Skip to content

Commit

Permalink
Condensed settings.load()
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlui committed Jan 12, 2025
1 parent a115a9c commit 69ba309
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 44 deletions.
11 changes: 4 additions & 7 deletions chatgpt-auto-continue/chromium/extension/lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ window.settings = {
this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle')
})
else // 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]
?? this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle'
resolve()
}))))
return Promise.all(keys.map(async key => // resolve promise when all keys load
window.config[key] = (await chrome.storage.sync.get(key))[key]
?? this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle'
))
},

save(key, val) {
Expand Down
11 changes: 4 additions & 7 deletions chatgpt-auto-continue/firefox/extension/lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ window.settings = {
this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle')
})
else // 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]
?? this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle'
resolve()
}))))
return Promise.all(keys.map(async key => // resolve promise when all keys load
window.config[key] = (await chrome.storage.sync.get(key))[key]
?? this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle'
))
},

save(key, val) {
Expand Down
11 changes: 4 additions & 7 deletions chatgpt-infinity/chrome/extension/lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@ window.settings = {
this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle')
})
else // 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]
?? this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle'
resolve()
}))))
return Promise.all(keys.map(async key => // resolve promise when all keys load
window.config[key] = (await chrome.storage.sync.get(key))[key]
?? this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle'
))
},

save(key, val) {
Expand Down
11 changes: 4 additions & 7 deletions chatgpt-infinity/firefox/extension/lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@ window.settings = {
this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle')
})
else // 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]
?? this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle'
resolve()
}))))
return Promise.all(keys.map(async key => // resolve promise when all keys load
window.config[key] = (await chrome.storage.sync.get(key))[key]
?? this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle'
))
},

save(key, val) {
Expand Down
14 changes: 6 additions & 8 deletions chatgpt-widescreen/chrome/extension/lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ window.settings = {
this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle')
})
else // 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(
!this.browserwideKeys.includes(key) ? `${this.imports.env.site}_${key}` : key, result => {
window.config[key] = result[`${this.imports.env.site}_${key}`] ?? result[key]
?? this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle'
resolve()
}))))
return Promise.all(keys.map(async key => { // resolve promise when all keys load
const result = await chrome.storage.sync.get(
!this.browserwideKeys.includes(key) ? `${this.imports.env.site}_${key}` : key )
window.config[key] = result[`${this.imports.env.site}_${key}`] ?? result[key]
?? this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle'
}))
},

save(key, val) {
Expand Down
14 changes: 6 additions & 8 deletions chatgpt-widescreen/firefox/extension/lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ window.settings = {
this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle')
})
else // 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(
!this.browserwideKeys.includes(key) ? `${this.imports.env.site}_${key}` : key, result => {
window.config[key] = result[`${this.imports.env.site}_${key}`] ?? result[key]
?? this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle'
resolve()
}))))
return Promise.all(keys.map(async key => { // resolve promise when all keys load
const result = await chrome.storage.sync.get(
!this.browserwideKeys.includes(key) ? `${this.imports.env.site}_${key}` : key )
window.config[key] = result[`${this.imports.env.site}_${key}`] ?? result[key]
?? this.controls[key]?.defaultVal ?? this.controls[key]?.type == 'toggle'
}))
},

save(key, val) {
Expand Down

0 comments on commit 69ba309

Please sign in to comment.