-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Directly assigned libs to
window
for simplicity ↞ [auto-sync from h…
- Loading branch information
1 parent
9eece84
commit 9ea9b5f
Showing
4 changed files
with
34 additions
and
42 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
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,53 +1,51 @@ | ||
const config = {} | ||
const settings = { | ||
window.config = {} | ||
window.settings = { | ||
|
||
controls: { // displays top-to-bottom in toolbar menu | ||
get infinityMode() { return { type: 'toggle', | ||
label: settings.getMsg('menuLabel_infinityMode') }}, | ||
label: window.settings.getMsg('menuLabel_infinityMode') }}, | ||
get autoStart() { return { type: 'toggle', | ||
label: settings.getMsg('menuLabel_autoStart'), | ||
helptip: settings.getMsg('helptip_autoStart') }}, | ||
label: window.settings.getMsg('menuLabel_autoStart'), | ||
helptip: window.settings.getMsg('helptip_autoStart') }}, | ||
get toggleHidden() { return { type: 'toggle', | ||
label: settings.getMsg('menuLabel_toggleVis'), | ||
helptip: settings.getMsg('helptip_toggleVis') }}, | ||
label: window.settings.getMsg('menuLabel_toggleVis'), | ||
helptip: window.settings.getMsg('helptip_toggleVis') }}, | ||
get autoScrollDisabled() { return { type: 'toggle', | ||
label: settings.getMsg('menuLabel_autoScroll'), | ||
helptip: settings.getMsg('helptip_autoScroll') }}, | ||
label: window.settings.getMsg('menuLabel_autoScroll'), | ||
helptip: window.settings.getMsg('helptip_autoScroll') }}, | ||
get replyLanguage() { return { type: 'prompt', symbol: '🌐', | ||
label: settings.getMsg('menuLabel_replyLang'), | ||
helptip: settings.getMsg('prompt_updateReplyLang') }}, | ||
label: window.settings.getMsg('menuLabel_replyLang'), | ||
helptip: window.settings.getMsg('prompt_updateReplyLang') }}, | ||
get replyTopic() { return { type: 'prompt', symbol: '🧠', | ||
label: settings.getMsg('menuLabel_replyTopic'), | ||
helptip: settings.getMsg('prompt_updateReplyTopic') }}, | ||
label: window.settings.getMsg('menuLabel_replyTopic'), | ||
helptip: window.settings.getMsg('prompt_updateReplyTopic') }}, | ||
get replyInterval() { return { type: 'prompt', symbol: '⌚', | ||
label: settings.getMsg('menuLabel_replyInt'), | ||
helptip: settings.getMsg('prompt_updateReplyInt') }} | ||
label: window.settings.getMsg('menuLabel_replyInt'), | ||
helptip: window.settings.getMsg('prompt_updateReplyInt') }} | ||
}, | ||
|
||
getMsg(key) { | ||
return typeof chrome != 'undefined' && chrome.runtime ? chrome.i18n.getMessage(key) | ||
: settings.appProps.msgs[key] // assigned from app.msgs in userscript | ||
: 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)) | ||
if (typeof chrome != 'undefined' && chrome.runtime) // asynchronously load from Chrome storage | ||
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 => { | ||
config[key] = result[key] || false ; resolve() | ||
window.config[key] = result[key] || false ; resolve() | ||
})))) ; else // synchronously load from userscript manager storage | ||
keys.forEach(key => config[key] = GM_getValue(settings.appProps.configKeyPrefix + '_' + key, false)) | ||
keys.forEach(key => window.config[key] = GM_getValue(this.appProps.configKeyPrefix + '_' + key, false)) | ||
}, | ||
|
||
save(key, val) { | ||
if (typeof chrome != 'undefined' && chrome.runtime) // save to Chrome 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(settings.appProps.configKeyPrefix + '_' + key, val) | ||
config[key] = val // save to memory | ||
GM_setValue(this.appProps.configKeyPrefix + '_' + key, val) | ||
window.config[key] = val // save to memory | ||
} | ||
} | ||
|
||
window.config = config ; window.settings = settings; | ||
}; |
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
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