Skip to content

Commit 74ebc7c

Browse files
committed
Shorted import func arg to deps + parent obj to imports ↞ [auto-sync from https://github.com/KudoAI/chatgpt.js-chrome-starter]
1 parent 1cf590c commit 74ebc7c

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

starters/chrome/extension/components/icons.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Requires lib/dom.js
22

33
window.icons = {
4-
dependencies: {
5-
import(dependencies) { // { app }
6-
for (const depName in dependencies) this[depName] = dependencies[depName] }
4+
imports: {
5+
import(deps) { // { app }
6+
for (const depName in deps) this[depName] = deps[depName] }
77
},
88

99
create({ name, size = 16, width, height, ...additionalAttrs }) {
@@ -26,6 +26,6 @@ window.icons = {
2626

2727
questionMark: {
2828
type: 'png',
29-
get src() { return `${icons.dependencies.app.urls.assetHost}@b5551ac/images/icons/question-mark/icon16.png` }
29+
get src() { return `${icons.imports.app.urls.assetHost}@b5551ac/images/icons/question-mark/icon16.png` }
3030
}
3131
};

starters/chrome/extension/components/modals.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
window.modals = {
44
stack: [], // of types of undismissed modals
5-
get class() { return `${this.dependencies.app.cssPrefix}-modal` },
5+
get class() { return `${this.imports.app.cssPrefix}-modal` },
66

7-
dependencies: {
8-
import(dependencies) { // { app, env }
9-
for (const depName in dependencies) this[depName] = dependencies[depName] }
7+
imports: {
8+
import(deps) { // { app, env }
9+
for (const depName in deps) this[depName] = deps[depName] }
1010
},
1111

1212
alert(title = '', msg = '', btns = '', checkbox = '', width = '') { // generic one from chatgpt.alert()
@@ -39,37 +39,37 @@ window.modals = {
3939
+ 'font-family: -apple-system, system-ui, BlinkMacSystemFont, Segoe UI, Roboto,'
4040
+ 'Oxygen-Sans, Ubuntu, Cantarell, Helvetica Neue, sans-serif ;'
4141
+ 'padding: 20px 25px 24px 25px !important ; font-size: 20px ;'
42-
+ `color: ${ this.dependencies.env.ui.scheme == 'dark' ? 'white' : 'black' } !important ;`
42+
+ `color: ${ this.imports.env.ui.scheme == 'dark' ? 'white' : 'black' } !important ;`
4343
+ `background-image: linear-gradient(180deg, ${
44-
this.dependencies.env.ui.scheme == 'dark' ? '#99a8a6 -200px, black 200px'
44+
this.imports.env.ui.scheme == 'dark' ? '#99a8a6 -200px, black 200px'
4545
: '#b6ebff -296px, white 171px' }) }`
4646
+ `.${this.class} [class*=modal-close-btn] {`
4747
+ 'position: absolute !important ; float: right ; top: 14px !important ; right: 16px !important ;'
4848
+ 'cursor: pointer ; width: 33px ; height: 33px ; border-radius: 20px }'
4949
+ `.${this.class} [class*=modal-close-btn] svg { height: 10px }`
5050
+ `.${this.class} [class*=modal-close-btn] path {`
51-
+ `${ this.dependencies.env.ui.scheme == 'dark' ? 'stroke: white ; fill: white'
51+
+ `${ this.imports.env.ui.scheme == 'dark' ? 'stroke: white ; fill: white'
5252
: 'stroke: #9f9f9f ; fill: #9f9f9f' }}`
53-
+ ( this.dependencies.env.ui.scheme == 'dark' ? // invert dark mode hover paths
53+
+ ( this.imports.env.ui.scheme == 'dark' ? // invert dark mode hover paths
5454
`.${this.class} [class*=modal-close-btn]:hover path { stroke: black ; fill: black }` : '' )
5555
+ `.${this.class} [class*=modal-close-btn]:hover { background-color: #f2f2f2 }` // hover underlay
5656
+ `.${this.class} [class*=modal-close-btn] svg { margin: 11.5px }` // center SVG for hover underlay
5757
+ `.${this.class} a {`
58-
+ `color: #${ this.dependencies.env.ui.scheme == 'dark' ? '00cfff' : '1e9ebb' } !important }`
58+
+ `color: #${ this.imports.env.ui.scheme == 'dark' ? '00cfff' : '1e9ebb' } !important }`
5959
+ `.${this.class} h2 { font-weight: bold }`
6060
+ `.${this.class} button {`
6161
+ 'font-size: 14px ; text-transform: uppercase ;' // shrink/uppercase labels
6262
+ 'border-radius: 0 !important ;' // square borders
6363
+ 'transition: transform 0.1s ease-in-out, box-shadow 0.1s ease-in-out ;' // smoothen hover fx
6464
+ 'cursor: pointer !important ;' // add finger cursor
65-
+ `border: 1px solid ${ this.dependencies.env.ui.scheme == 'dark' ? 'white' : 'black' } !important ;`
65+
+ `border: 1px solid ${ this.imports.env.ui.scheme == 'dark' ? 'white' : 'black' } !important ;`
6666
+ 'padding: 8px !important ; min-width: 102px }' // resize
6767
+ `.${this.class} button:hover {` // add zoom, re-scheme
6868
+ 'transform: scale(1.055) ; color: black !important ;'
69-
+ `background-color: #${ this.dependencies.env.ui.scheme == 'dark' ? '00cfff' : '9cdaff' } !important }`
70-
+ ( !this.dependencies.env.browser.isMobile ?
69+
+ `background-color: #${ this.imports.env.ui.scheme == 'dark' ? '00cfff' : '9cdaff' } !important }`
70+
+ ( !this.imports.env.browser.isMobile ?
7171
`.${this.class} .modal-buttons { margin-left: -13px !important }` : '' )
72-
+ `.about-em { color: ${ this.dependencies.env.ui.scheme == 'dark' ? 'white' : 'green' } !important }`
72+
+ `.about-em { color: ${ this.imports.env.ui.scheme == 'dark' ? 'white' : 'green' } !important }`
7373
)
7474
},
7575

@@ -94,13 +94,13 @@ window.modals = {
9494

9595
// Show modal
9696
const aboutModal = this.alert(
97-
`${this.dependencies.app.symbol} ${chrome.runtime.getManifest().name}`, // title
98-
`🏷️ Version: <span class="about-em">${this.dependencies.app.version}</span>\n` // msg
97+
`${this.imports.app.symbol} ${chrome.runtime.getManifest().name}`, // title
98+
`🏷️ Version: <span class="about-em">${this.imports.app.version}</span>\n` // msg
9999
+ '⚡ Powered by: '
100-
+ `<a href="${this.dependencies.app.urls.chatgptJS}" target="_blank" rel="noopener">chatgpt.js</a>\n`
100+
+ `<a href="${this.imports.app.urls.chatgptJS}" target="_blank" rel="noopener">chatgpt.js</a>\n`
101101
+ '📜 Open source code: '
102-
+ `<a href="${this.dependencies.app.urls.gitHub}" target="_blank" rel="nopener">`
103-
+ this.dependencies.app.urls.gitHub + '</a>',
102+
+ `<a href="${this.imports.app.urls.gitHub}" target="_blank" rel="nopener">`
103+
+ this.imports.app.urls.gitHub + '</a>',
104104
[ function getSupport(){}, function rateUs(){}, function moreAiExtensions(){} ], // button labels
105105
'', 656 // modal width
106106
)
@@ -110,7 +110,7 @@ window.modals = {
110110
'text-align: center ; font-size: 51px ; line-height: 46px ; padding: 15px 0' )
111111
aboutModal.querySelector('p').style.cssText = (
112112
'text-align: center ; overflow-wrap: anywhere ;'
113-
+ `margin: ${ this.dependencies.env.browser.isPortrait ? '6px 0 -16px' : '3px 0 0' }` )
113+
+ `margin: ${ this.imports.env.browser.isPortrait ? '6px 0 -16px' : '3px 0 0' }` )
114114

115115
// Hack buttons
116116
aboutModal.querySelector('.modal-buttons').style.justifyContent = 'center'
@@ -121,9 +121,9 @@ window.modals = {
121121
const btnClone = btn.cloneNode(true)
122122
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
123123
btn.onclick = () => this.safeWinOpen(
124-
btn.textContent == 'Get Support' ? `${modals.dependencies.app.urls.gitHub}/issues`
125-
: btn.textContent == 'Rate Us' ? `${modals.dependencies.app.urls.gitHub}/discussions`
126-
: modals.dependencies.app.urls.relatedExtensions
124+
btn.textContent == 'Get Support' ? `${modals.imports.app.urls.gitHub}/issues`
125+
: btn.textContent == 'Rate Us' ? `${modals.imports.app.urls.gitHub}/discussions`
126+
: modals.imports.app.urls.relatedExtensions
127127
)
128128

129129
// Prepend emoji

starters/chrome/extension/content.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
const { app } = await chrome.storage.sync.get('app')
1616

1717
// Export DEPENDENCIES to imported resources
18-
dom.dependencies.import({ env }) // for env.ui.scheme
19-
modals.dependencies.import({ app, env }) // for app data + env.ui.scheme
18+
dom.imports.import({ env }) // for env.ui.scheme
19+
modals.imports.import({ app, env }) // for app data + env.ui.scheme
2020

2121
// Add CHROME MSG listener
2222
chrome.runtime.onMessage.addListener(req => { // from service-worker.js + popup/index.html

starters/chrome/extension/lib/dom.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
window.dom = {
22

3-
dependencies: {
4-
import(dependencies) { // { env) }
5-
for (const depName in dependencies) this[depName] = dependencies[depName] }
3+
imports: {
4+
import(deps) { // { env) }
5+
for (const depName in deps) this[depName] = deps[depName] }
66
},
77

88
create: {
@@ -27,7 +27,7 @@ window.dom = {
2727
+ 'z-index: -1'; // allow interactive elems to be clicked
2828
['sm', 'med', 'lg'].forEach(starSize => {
2929
const starsDiv = document.createElement('div')
30-
starsDiv.id = `${ this.dependencies.env.ui.scheme == 'dark' ? 'white' : 'black' }-stars-${starSize}`
30+
starsDiv.id = `${ this.imports.env.ui.scheme == 'dark' ? 'white' : 'black' }-stars-${starSize}`
3131
starsDivsContainer.append(starsDiv)
3232
})
3333
targetNode.prepend(starsDivsContainer)

starters/chrome/extension/popup/controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// Import APP data
1212
const { app } = await chrome.storage.sync.get('app')
13-
icons.dependencies.import({ app }) // for src's using app.urls.assetHost
13+
icons.imports.import({ app }) // for src's using app.urls.assetHost
1414

1515
// Define FUNCTIONS
1616

0 commit comments

Comments
 (0)