From 4d0dadd1a5a5883ca7de079f63c9cec249a9405f Mon Sep 17 00:00:00 2001 From: "adamlui@protonmail.com" Date: Sun, 17 Nov 2024 00:04:36 -0800 Subject: [PATCH] Moved app props from `config` to new `app` obj for readability, --- extension/content.js | 9 ++++++--- extension/lib/settings.js | 6 +----- extension/popup/popup.js | 5 ++++- extension/service-worker.js | 4 ++++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/extension/content.js b/extension/content.js index cbafb56..763861d 100644 --- a/extension/content.js +++ b/extension/content.js @@ -7,6 +7,9 @@ const { config, settings } = await import(chrome.runtime.getURL('lib/settings.js')) await import(chrome.runtime.getURL('lib/chatgpt.js')) + // Import APP data + const { app } = await chrome.storage.sync.get('app') + // Add CHROME MSG listener chrome.runtime.onMessage.addListener(req => { if (req.action === 'notify') notify(req.msg, req.position) @@ -26,7 +29,7 @@ if (foundState) msg = msg.replace(foundState, '') // Show notification - chatgpt.notify(`${config.appSymbol} ${msg}`, pos, notifDuration, + chatgpt.notify(`${app.symbol} ${msg}`, pos, notifDuration, shadow || chatgpt.isDarkMode() ? '' : 'shadow' ) const notif = document.querySelector('.chatgpt-notif:last-child') @@ -41,7 +44,7 @@ } function siteAlert(title = '', msg = '', btns = '', checkbox = '', width = '') { - return chatgpt.alert(`${config.appSymbol} ${title}`, msg, btns, checkbox, width )} + return chatgpt.alert(`${app.symbol} ${title}`, msg, btns, checkbox, width )} // Define SYNC function @@ -66,7 +69,7 @@ chatgpt.alert('≫ ChatGPT extension loaded! 🚀', // title 'Success! Press Ctrl+Shift+J to view all chatgpt.js methods.', // msg function getHelp() { // button - chrome.tabs.create({ url: `${config.ghRepoURL}/issues` }) }, + chrome.tabs.create({ url: `${app.urls.gitHub}/issues` }) }, function dontShowAgain() { // checkbox settings.save('skipAlert', !config.skipAlert) } ) diff --git a/extension/lib/settings.js b/extension/lib/settings.js index 0bcb424..dcb2609 100644 --- a/extension/lib/settings.js +++ b/extension/lib/settings.js @@ -1,8 +1,4 @@ -const config = { - appSymbol: '🤖', appName: 'ChatGPT Extension', - ghRepoURL: 'https://github.kudoai.com/chatgpt.js-chrome-starter' } - -const settings = { +const config = {}, settings = { availKeys: [ 'extensionDisabled', 'skipAlert' ], load() { diff --git a/extension/popup/popup.js b/extension/popup/popup.js index cfd63b0..45607a7 100644 --- a/extension/popup/popup.js +++ b/extension/popup/popup.js @@ -3,6 +3,9 @@ // Import settings.js const { config, settings } = await import(chrome.runtime.getURL('lib/settings.js')) + // Import APP data + const { app } = await chrome.storage.sync.get('app') + // Initialize popup toggles settings.load('extensionDisabled') .then(function() { // restore extension/toggle states @@ -16,7 +19,7 @@ masterToggle.addEventListener('change', function() { settings.save('extensionDisabled', !this.checked) syncStorageToUI() ; updateGreyness() - notify(config.appName + ( this.checked ? ' ON' : ' OFF' )) + notify(`${app.name} ${ this.checked ? 'ON' : 'OFF' }`) }) // Add update-check span click-listener diff --git a/extension/service-worker.js b/extension/service-worker.js index fe44af2..390429c 100644 --- a/extension/service-worker.js +++ b/extension/service-worker.js @@ -1,3 +1,7 @@ +// Init APP data +const app = { name: 'ChatGPT Extension', symbol: '🤖', urls: { gitHub: 'https://github.com/KudoAI/chatgpt.js-chrome-starter' }} +chrome.storage.sync.set({ app }) + // Launch ChatGPT on install chrome.runtime.onInstalled.addListener(details => { if (details.reason == 'install')