Skip to content

Commit 10b7939

Browse files
committed
Condensed methods ↞ [auto-sync from KudoAI/chatgpt.js-chrome-starter]
1 parent 2d53893 commit 10b7939

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

starters/chrome/extension/lib/settings.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@ const config = {
33
ghRepoURL: 'https://github.kudoai.com/chatgpt.js-chrome-starter' }
44

55
const settings = {
6-
7-
load: function() {
6+
load() {
87
const keys = ( // original array if array, else new array from multiple args
98
Array.isArray(arguments[0]) ? arguments[0] : Array.from(arguments))
10-
return Promise.all(keys.map((key) => { // resolve promise when all keys load
11-
return new Promise((resolve) => { // resolve promise when single key value loads
12-
chrome.storage.local.get(key, (result) => { // load from Chrome
9+
return Promise.all(keys.map(key => // resolve promise when all keys load
10+
new Promise(resolve => // resolve promise when single key value loads
11+
chrome.storage.sync.get(key, result => { // load from Chrome
1312
config[key] = result[key] || false ; resolve()
14-
})})}))},
13+
}))))},
1514

16-
save: function(key, value) {
17-
const obj = {} ; obj[key] = value
18-
chrome.storage.local.set(obj) // save to Chrome
19-
config[key] = value // save to memory
15+
save(key, val) {
16+
chrome.storage.sync.set({ [key]: val }) // save to Chrome
17+
config[key] = val // save to memory
2018
}
21-
2219
}
2320

2421
export { config, settings }

0 commit comments

Comments
 (0)