extension-api-compilation
Version:
Cross browser extension api
72 lines (66 loc) • 1.97 kB
JavaScript
import Runtime from '../runtime/runtime';
import ChromeRuntime from '../runtime/chrome-runtime';
import MozillaRuntime from '../runtime/mozilla-runtime';
import Tabs from '../tabs/tabs';
import ChromeTabs from '../tabs/chrome-tabs';
import MozillaTabs from '../tabs/mozilla-tabs';
import SyncStorage from '../sync-storage/sync-storage';
import ChromeSyncStorage from '../sync-storage/chrome-sync-storage';
import MozillaSyncStorage from '../sync-storage/mozilla-sync-storage';
let browserApi = (function () {
let runtime = {
chrome: new ChromeRuntime(),
mozilla: new MozillaRuntime()
};
let tabs = {
chrome: new ChromeTabs(),
mozilla: new MozillaTabs()
};
let syncStorage = {
chrome: new ChromeSyncStorage(),
mozilla: new MozillaSyncStorage()
};
return {
runtime: (function () {
switch (Runtime.detectBrowser()){
case 'chrome':
return runtime.chrome; break;
case 'mozilla' :
return runtime.mozilla; break;
default:
return null;
}
})(),
tabs: (function () {
switch (Tabs.detectBrowser()){
case 'chrome':
return tabs.chrome; break;
case 'mozilla' :
return tabs.mozilla; break;
default:
return null;
}
})(),
syncStorage: (function () {
switch (SyncStorage.detectBrowser()){
case 'chrome':
return syncStorage.chrome; break;
case 'mozilla' :
return syncStorage.mozilla; break;
default:
return null;
}
})(),
alarms: (function () {
switch (SyncStorage.detectBrowser()){
case 'chrome':
return chrome.alarms; break;
case 'mozilla' :
return browser.alarms; break;
default:
return null;
}
})()
};
})();
export default browserApi;