Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import browser from 'webextension-polyfill';
// Store preferences in synced storage if available, use local as a fallback:
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage/sync
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage/local
export default browser.storage.sync || browser.storage.local;
const url = new URL(message.url);
const siteName = url.hostname.replace('www.', '');
const { onboardingShown } = await browser.storage.local.get('onboardingShown');
dispatch({ type: 'init', siteName, showOnboarding: !onboardingShown });
} else if (message.type === 'detectFeatures') {
detectFeatures(message.url, dispatch);
} else if (message.type === 'detectConsent') {
detectConsent(message.consent, tab, localStorage, dispatch);
} else if (message.type === 'changeConsent') {
changeConsent(message.consent, tab, localStorage, dispatch);
} else if (message.type === 'setBrowserExtensionIcon') {
setBrowserExtensionIcon(message.applicationState, tab.id);
} else if (message.type === 'telemetry') {
telemetry(message.actionKey, message.actionData);
} else if (message.type === 'hideOnboarding') {
browser.storage.local.set({
onboardingShown: +new Date(),
});
dispatch({ type: 'hideOnboarding' });
} else if (message.type === 'showPageAction') {
browser.pageAction.show(tab.id);
telemetry(TELEMETRY_ACTION.PAGE_ACTION_DISPLAYED, {
site: new URL(tab.url).hostname,
type: getConsentType(message.state),
});
}
});
import browser from 'webextension-polyfill';
const message = 'Add installTime, searchCount and contribPageLastOpen';
const revision = 'SkhmnNhMG';
const downRevision = 'SJltHx2rW';
const storage = browser.storage.local;
async function upgrade() {
const changes = {};
changes.installTime = new Date().getTime();
changes.searchCount = 0;
changes.contribPageLastOpen = 0;
changes.storageVersion = revision;
return storage.set(changes);
}
async function downgrade() {
const changes = {};
await storage.remove(['installTime', 'searchCount', 'contribPageLastOpen']);
changes.storageVersion = downRevision;
const fixDirtyData = async () => {
const unlock = await listManager.RWLock.lock()
const {lists} = await browser.storage.local.get('lists')
if (lists) {
const cleanLists = lists.filter(_.isPlainObject).map(normalizeList)
await browser.storage.local.set({lists: cleanLists})
}
await unlock()
}
import browser from 'webextension-polyfill';
const message = 'Add stock photo engines';
const revision = 'r1H3rgx1X';
const downRevision = 'r1Pvd36nz';
const storage = browser.storage.local;
async function upgrade() {
const changes = {};
const {engines, disabledEngines} = await storage.get([
'engines',
'disabledEngines'
]);
const newEngines = [
'getty',
'istock',
'shutterstock',
'adobestock',
'depositphotos'
];
utils.resetLocalStorageTheme = async () => {
await browser.storage.sync.set({themeConfig: utils.defaultThemeConfig})
}
}).then(newList => {
return browser.storage.local.set({
[NOTES_KEY]: newList
});
});
}
fetchSakaSettings = async function fetchSakaSettings() {
const { sakaSettings } = await browser.storage.sync.get(['sakaSettings']);
let { searchHistory } = await browser.storage.sync.get(['searchHistory']);
searchHistory =
searchHistory !== undefined && searchHistory.length > 0
? new Set(searchHistory)
: new Set(['']);
if (sakaSettings !== undefined) {
const { mode, showEmptySearchSuggestions } = sakaSettings;
return {
isLoading: false,
mode,
showEmptySearchSuggestions,
searchHistory
};
}
case constants.INSERT_PASSWORD_MESSAGE:
performAction(constants.INSERT_PREVIOUS_PASSWORD_MENU);
break;
case constants.GET_STATE_MESSAGE:
response = Promise.resolve({
password: password,
settings: settings
});
break;
case constants.SET_STATE_MESSAGE:
settings = message.settings;
password = message.password;
break;
case constants.SAVE_SETTINGS_MESSAGE:
settings = message.settings;
response = browser.storage.local.set({ [constants.SETTINGS_KEY]: settings });
break;
}
return response;
});
function setUser(user) {
return browser.storage.local.set({ user }).then(() => user);
}