webextensions/src/scripts/utils/ext.js

67 lines
1.0 KiB
JavaScript
Raw Normal View History

2018-04-08 22:33:36 +02:00
const apis = [
2019-05-06 17:01:54 +02:00
"alarms",
"bookmarks",
"browserAction",
"commands",
"contextMenus",
"cookies",
"downloads",
"events",
"extension",
"extensionTypes",
"history",
"i18n",
"idle",
"notifications",
"pageAction",
"runtime",
"storage",
"tabs",
"webNavigation",
"webRequest",
"windows"
];
2018-04-08 22:33:36 +02:00
2019-05-06 17:01:54 +02:00
function Extension() {
const _this = this;
2018-04-08 22:33:36 +02:00
2019-05-06 17:01:54 +02:00
apis.forEach(function(api) {
_this[api] = null;
2018-04-08 22:33:36 +02:00
try {
if (chrome[api]) {
2019-05-06 17:01:54 +02:00
_this[api] = chrome[api];
2018-04-08 22:33:36 +02:00
}
} catch (e) {}
try {
if (window[api]) {
2019-05-06 17:01:54 +02:00
_this[api] = window[api];
2018-04-08 22:33:36 +02:00
}
} catch (e) {}
try {
if (browser[api]) {
2019-05-06 17:01:54 +02:00
_this[api] = browser[api];
2018-04-08 22:33:36 +02:00
}
} catch (e) {}
try {
2019-05-06 17:01:54 +02:00
_this.api = browser.extension[api];
2018-04-08 22:33:36 +02:00
} catch (e) {}
2019-05-06 17:01:54 +02:00
});
2018-04-08 22:33:36 +02:00
try {
if (browser && browser.runtime) {
2019-05-06 17:01:54 +02:00
this.runtime = browser.runtime;
2018-04-08 22:33:36 +02:00
}
} catch (e) {}
try {
if (browser && browser.browserAction) {
2019-05-06 17:01:54 +02:00
this.browserAction = browser.browserAction;
2018-04-08 22:33:36 +02:00
}
} catch (e) {}
}
2019-05-06 17:01:54 +02:00
module.exports = new Extension();