Skip to content

Commit b6ee03c

Browse files
committed
Moved siteAlert() from content.js to components/modal.js for centralization ↞ [auto-sync from https://github.com/KudoAI/chatgpt.js-chrome-starter]
1 parent fac6b09 commit b6ee03c

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

starters/chrome/extension/components/modals.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ window.modals = {
44
stack: [], // of types of undismissed modals
55

66
dependencies: {
7-
import(dependencies) { // { app, siteAlert }
7+
import(dependencies) { // { app }
88
for (const name in dependencies) this[name] = dependencies[name] }
99
},
1010

11+
alert(title = '', msg = '', btns = '', checkbox = '', width = '') {
12+
const alertID = chatgpt.alert(title, msg, btns, checkbox, width),
13+
alert = document.getElementById(alertID).firstChild
14+
return alert
15+
},
16+
1117
open(modalType) {
1218
this.stack.unshift(modalType) // add to stack
1319
const modal = this[modalType]() // show modal
@@ -79,7 +85,7 @@ window.modals = {
7985
]
8086

8187
// Show modal
82-
const aboutModal = this.dependencies.siteAlert(
88+
const aboutModal = this.alert(
8389
`${this.dependencies.app.symbol} ${chrome.runtime.getManifest().name}`, // title
8490
`<span style="${headingStyle}"><b>🏷️ <i>Version</i></b>: </span>`
8591
+ `<span style="${pStyle}">${this.dependencies.app.version}</span>\n`

starters/chrome/extension/content.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
// Import APP data
1111
const { app } = await chrome.storage.sync.get('app')
12-
modals.dependencies.import({ app, siteAlert })
12+
modals.dependencies.import({ app })
1313

1414
// Add CHROME MSG listener
1515
chrome.runtime.onMessage.addListener(req => { // from service-worker.js + popup/index.html
1616
if (req.action == 'notify')
1717
notify(...['msg', 'pos', 'notifDuration', 'shadow'].map(arg => req.options[arg]))
1818
else if (req.action == 'alert')
19-
siteAlert(...['title', 'msg', 'btns', 'checkbox', 'width'].map(arg => req.options[arg]))
19+
modals.alert(...['title', 'msg', 'btns', 'checkbox', 'width'].map(arg => req.options[arg]))
2020
else if (req.action == 'showAbout') chatgpt.isLoaded().then(() => { modals.open('about') })
2121
else if (req.action == 'syncConfigToUI') syncConfigToUI(req.options)
2222
})
@@ -47,11 +47,6 @@
4747
}
4848
}
4949

50-
function siteAlert(title = '', msg = '', btns = '', checkbox = '', width = '') {
51-
const alertID = chatgpt.alert(title, msg, btns, checkbox, width)
52-
return document.getElementById(alertID).firstChild
53-
}
54-
5550
// Define SYNC function
5651

5752
async function syncConfigToUI(options) { // eslint-disable-line
@@ -84,7 +79,7 @@
8479
if (config.extensionDisabled) return
8580

8681
if (!config.skipAlert) // alert to extension load
87-
chatgpt.alert('≫ ChatGPT extension loaded! 🚀', // title
82+
modals.alert('≫ ChatGPT extension loaded! 🚀', // title
8883
'Success! Press Ctrl+Shift+J to view all chatgpt.js methods.', // msg
8984
function getHelp() { // button
9085
chrome.tabs.create({ url: `${app.urls.gitHub}/issues` }) },

0 commit comments

Comments
 (0)