From 69ba3091a3b2a715a857f6f4f03f06f0b186242c Mon Sep 17 00:00:00 2001 From: "adamlui@protonmail.com" Date: Sat, 11 Jan 2025 21:14:24 -0800 Subject: [PATCH] Condensed `settings.load()` --- .../chromium/extension/lib/settings.js | 11 ++++------- .../firefox/extension/lib/settings.js | 11 ++++------- chatgpt-infinity/chrome/extension/lib/settings.js | 11 ++++------- chatgpt-infinity/firefox/extension/lib/settings.js | 11 ++++------- .../chrome/extension/lib/settings.js | 14 ++++++-------- .../firefox/extension/lib/settings.js | 14 ++++++-------- 6 files changed, 28 insertions(+), 44 deletions(-) diff --git a/chatgpt-auto-continue/chromium/extension/lib/settings.js b/chatgpt-auto-continue/chromium/extension/lib/settings.js index 09b7acd08..ea996e528 100644 --- a/chatgpt-auto-continue/chromium/extension/lib/settings.js +++ b/chatgpt-auto-continue/chromium/extension/lib/settings.js @@ -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) { diff --git a/chatgpt-auto-continue/firefox/extension/lib/settings.js b/chatgpt-auto-continue/firefox/extension/lib/settings.js index 09b7acd08..ea996e528 100644 --- a/chatgpt-auto-continue/firefox/extension/lib/settings.js +++ b/chatgpt-auto-continue/firefox/extension/lib/settings.js @@ -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) { diff --git a/chatgpt-infinity/chrome/extension/lib/settings.js b/chatgpt-infinity/chrome/extension/lib/settings.js index 6c0097d7c..e2ff86995 100644 --- a/chatgpt-infinity/chrome/extension/lib/settings.js +++ b/chatgpt-infinity/chrome/extension/lib/settings.js @@ -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) { diff --git a/chatgpt-infinity/firefox/extension/lib/settings.js b/chatgpt-infinity/firefox/extension/lib/settings.js index 6c0097d7c..e2ff86995 100644 --- a/chatgpt-infinity/firefox/extension/lib/settings.js +++ b/chatgpt-infinity/firefox/extension/lib/settings.js @@ -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) { diff --git a/chatgpt-widescreen/chrome/extension/lib/settings.js b/chatgpt-widescreen/chrome/extension/lib/settings.js index 829987d0a..9c8b64ac1 100644 --- a/chatgpt-widescreen/chrome/extension/lib/settings.js +++ b/chatgpt-widescreen/chrome/extension/lib/settings.js @@ -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) { diff --git a/chatgpt-widescreen/firefox/extension/lib/settings.js b/chatgpt-widescreen/firefox/extension/lib/settings.js index 829987d0a..9c8b64ac1 100644 --- a/chatgpt-widescreen/firefox/extension/lib/settings.js +++ b/chatgpt-widescreen/firefox/extension/lib/settings.js @@ -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) {