Skip to content

Commit

Permalink
Moved app props from config to new app obj for readability, ↞ [au…
Browse files Browse the repository at this point in the history
…to-sync from `KudoAI/chatgpt.js-chrome-starter`]
  • Loading branch information
kudo-sync-bot committed Nov 17, 2024
1 parent 116024d commit 0c357ba
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
9 changes: 6 additions & 3 deletions starters/chrome/extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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')

Expand All @@ -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

Expand All @@ -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) }
)
Expand Down
6 changes: 1 addition & 5 deletions starters/chrome/extension/lib/settings.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
5 changes: 4 additions & 1 deletion starters/chrome/extension/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions starters/chrome/extension/service-worker.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down

0 comments on commit 0c357ba

Please sign in to comment.