convert createContextMenus to function

This commit is contained in:
narcolepticinsomniac 2020-02-12 02:45:12 -05:00
parent b506724b97
commit 341a03440d

View File

@ -162,6 +162,26 @@ navigatorUtil.onUrlChange(({tabId, frameId, transitionQualifiers}, type) => {
} }
}); });
// *************************************************************************
chrome.runtime.onInstalled.addListener(({reason}) => {
// save install type: "admin", "development", "normal", "sideload" or "other"
// "normal" = addon installed from webstore
chrome.management.getSelf(info => {
localStorage.installType = info.installType;
if (reason === 'install' && info.installType === 'development' && chrome.contextMenus) {
createContextMenus(['reload']);
}
});
if (reason !== 'update') return;
// translations may change
localStorage.L10N = JSON.stringify({
browserUIlanguage: chrome.i18n.getUILanguage(),
});
// themes may change
delete localStorage.codeMirrorThemes;
});
// ************************************************************************* // *************************************************************************
// browser commands // browser commands
browserCommands = { browserCommands = {
@ -209,7 +229,7 @@ contextMenus = {
} }
}; };
const createContextMenus = ids => { function createContextMenus(ids) {
for (const id of ids) { for (const id of ids) {
let item = contextMenus[id]; let item = contextMenus[id];
if (item.presentIf && !item.presentIf()) { if (item.presentIf && !item.presentIf()) {
@ -228,7 +248,7 @@ const createContextMenus = ids => {
delete item.click; delete item.click;
chrome.contextMenus.create(item, ignoreChromeError); chrome.contextMenus.create(item, ignoreChromeError);
} }
}; }
if (chrome.contextMenus) { if (chrome.contextMenus) {
// circumvent the bug with disabling check marks in Chrome 62-64 // circumvent the bug with disabling check marks in Chrome 62-64
@ -250,26 +270,6 @@ if (chrome.contextMenus) {
createContextMenus(keys); createContextMenus(keys);
} }
// *************************************************************************
chrome.runtime.onInstalled.addListener(({reason}) => {
// save install type: "admin", "development", "normal", "sideload" or "other"
// "normal" = addon installed from webstore
chrome.management.getSelf(info => {
localStorage.installType = info.installType;
if (reason === 'install' && info.installType === 'development' && chrome.contextMenus) {
createContextMenus(['reload']);
}
});
if (reason !== 'update') return;
// translations may change
localStorage.L10N = JSON.stringify({
browserUIlanguage: chrome.i18n.getUILanguage(),
});
// themes may change
delete localStorage.codeMirrorThemes;
});
// reinject content scripts when the extension is reloaded/updated. Firefox // reinject content scripts when the extension is reloaded/updated. Firefox
// would handle this automatically. // would handle this automatically.
if (!FIREFOX) { if (!FIREFOX) {
@ -308,7 +308,6 @@ function webNavUsercssInstallerFF(data) {
}); });
} }
function webNavIframeHelperFF({tabId, frameId}) { function webNavIframeHelperFF({tabId, frameId}) {
if (!frameId) return; if (!frameId) return;
msg.sendTab(tabId, {method: 'ping'}, {frameId}) msg.sendTab(tabId, {method: 'ping'}, {frameId})