-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored FF code to align more w/ Chromium code for easier maintena…
…nce ↞ [auto-sync from https://github.com/adamlui/ai-web-extensions]
- Loading branch information
1 parent
b84a1a8
commit 9ced016
Showing
1 changed file
with
21 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,34 @@ | ||
window.config = {} | ||
window.settings = { | ||
|
||
controls: { | ||
notifDisabled: { type: 'toggle', | ||
label: chrome.i18n.getMessage('menuLabel_modeNotifs'), | ||
helptip: chrome.i18n.getMessage('helptip_modeNotifs') } | ||
controls: { // displays top-to-bottom in toolbar menu | ||
get notifDisabled() { return { type: 'toggle', | ||
label: window.settings.getMsg('menuLabel_modeNotifs'), | ||
helptip: window.settings.getMsg('helptip_modeNotifs') }} | ||
}, | ||
|
||
getMsg(key) { | ||
return typeof chrome != 'undefined' && chrome.runtime ? chrome.i18n.getMessage(key) | ||
: this.appProps.msgs[key] // assigned from app.msgs in userscript | ||
}, | ||
|
||
load() { | ||
const keys = ( // original array if array, else new array from multiple args | ||
Array.isArray(arguments[0]) ? arguments[0] : Array.from(arguments)) | ||
return Promise.all(keys.map(key => // resolve promise when all keys load | ||
new Promise(resolve => // resolve promise when single key value loads | ||
chrome.storage.sync.get(key, result => { // load from browser extension storage | ||
window.config[key] = result[key] || false ; resolve() | ||
}))))}, | ||
if (typeof chrome != 'undefined' && chrome.runtime) // asynchronously load from browser extension storage | ||
return Promise.all(keys.map(key => // resolve promise when all keys load | ||
new Promise(resolve => // resolve promise when single key value loads | ||
chrome.storage.sync.get(key, result => { | ||
window.config[key] = result[key] || false ; resolve() | ||
})))) ; else // synchronously load from userscript manager storage | ||
keys.forEach(key => window.config[key] = GM_getValue(this.appProps.configKeyPrefix + '_' + key, false)) | ||
}, | ||
|
||
save(key, val) { | ||
chrome.storage.sync.set({ [key]: val }) // save to browser extension storage | ||
if (typeof chrome != 'undefined' && chrome.runtime) // save to browser extension storage | ||
chrome.storage.sync.set({ [key]: val }) | ||
else // save to userscript manager storage | ||
GM_setValue(this.appProps.configKeyPrefix + '_' + key, val) | ||
window.config[key] = val // save to memory | ||
} | ||
}; |