Skip to content

Commit 057c6f4

Browse files
committed
Moved env.scheme into env.ui for improved structure ↞ [auto-sync from https://github.com/KudoAI/chatgpt.js-chrome-starter]
1 parent 8c82c65 commit 057c6f4

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

starters/chrome/extension/components/modals.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +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.scheme == 'dark' ? 'white' : 'black' } !important ;`
42+
+ `color: ${ this.dependencies.env.ui.scheme == 'dark' ? 'white' : 'black' } !important ;`
4343
+ `background-image: linear-gradient(180deg, ${
44-
this.dependencies.env.scheme == 'dark' ? '#99a8a6 -200px, black 200px'
44+
this.dependencies.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.scheme == 'dark' ? 'stroke: white ; fill: white'
51+
+ `${ this.dependencies.env.ui.scheme == 'dark' ? 'stroke: white ; fill: white'
5252
: 'stroke: #9f9f9f ; fill: #9f9f9f' }}`
53-
+ ( this.dependencies.env.scheme == 'dark' ? // invert dark mode hover paths
53+
+ ( this.dependencies.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
57-
+ `.${this.class} a { color: #${ this.dependencies.env.scheme == 'dark' ? '00cfff' : '1e9ebb' } !important }`
57+
+ `.${this.class} a {`
58+
+ `color: #${ this.dependencies.env.ui.scheme == 'dark' ? '00cfff' : '1e9ebb' } !important }`
5859
+ `.${this.class} h2 { font-weight: bold }`
5960
+ `.${this.class} button {`
6061
+ 'font-size: 14px ; text-transform: uppercase ;' // shrink/uppercase labels
6162
+ 'border-radius: 0 !important ;' // square borders
6263
+ 'transition: transform 0.1s ease-in-out, box-shadow 0.1s ease-in-out ;' // smoothen hover fx
6364
+ 'cursor: pointer !important ;' // add finger cursor
64-
+ `border: 1px solid ${ this.dependencies.env.scheme == 'dark' ? 'white' : 'black' } !important ;`
65+
+ `border: 1px solid ${ this.dependencies.env.ui.scheme == 'dark' ? 'white' : 'black' } !important ;`
6566
+ 'padding: 8px !important ; min-width: 102px }' // resize
6667
+ `.${this.class} button:hover {` // add zoom, re-scheme
6768
+ 'transform: scale(1.055) ; color: black !important ;'
68-
+ `background-color: #${ this.dependencies.env.scheme == 'dark' ? '00cfff' : '9cdaff' } !important }`
69+
+ `background-color: #${ this.dependencies.env.ui.scheme == 'dark' ? '00cfff' : '9cdaff' } !important }`
6970
+ ( !this.dependencies.env.browser.isMobile ?
7071
`.${this.class} .modal-buttons { margin-left: -13px !important }` : '' )
71-
+ `.about-em { color: ${ this.dependencies.env.scheme == 'dark' ? 'white' : 'green' } !important }`
72+
+ `.about-em { color: ${ this.dependencies.env.ui.scheme == 'dark' ? 'white' : 'green' } !important }`
7273
)
7374
},
7475

starters/chrome/extension/content.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
await import(chrome.runtime.getURL(resource))
99

1010
// Init ENV context
11-
const env = { browser: { isMobile: chatgpt.browser.isMobile() }}
11+
const env = { browser: { isMobile: chatgpt.browser.isMobile() }, ui: { scheme: getScheme() }}
1212
env.browser.isPortrait = env.browser.isMobile && (window.innerWidth < window.innerHeight)
13-
env.scheme = getScheme()
1413

1514
// Import APP data
1615
const { app } = await chrome.storage.sync.get('app')
1716

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

2221
// Add CHROME MSG listener
2322
chrome.runtime.onMessage.addListener(req => { // from service-worker.js + popup/index.html
@@ -41,7 +40,7 @@
4140
if (foundState) msg = msg.replace(foundState, '')
4241

4342
// Show notification
44-
chatgpt.notify(`${app.symbol} ${msg}`, pos, notifDuration, shadow || env.scheme == 'dark' ? '' : 'shadow')
43+
chatgpt.notify(`${app.symbol} ${msg}`, pos, notifDuration, shadow || env.ui.scheme == 'dark' ? '' : 'shadow')
4544
const notif = document.querySelector('.chatgpt-notif:last-child')
4645

4746
// Append styled state word
@@ -98,14 +97,14 @@
9897
settings.save('skipAlert', !config.skipAlert) }
9998
)
10099

101-
// Monitor SCHEME PREF CHANGES to update modal colors + env.scheme for your use
100+
// Monitor SCHEME PREF CHANGES to update modal colors + env.ui.scheme for your use
102101
new MutationObserver(handleSchemePrefChange).observe( // for site scheme pref changes
103102
document.documentElement, { attributes: true, attributeFilter: ['class'] })
104103
window.matchMedia('(prefers-color-scheme: dark)').addEventListener( // for browser/system scheme pref changes
105104
'change', () => requestAnimationFrame(handleSchemePrefChange))
106105
function handleSchemePrefChange() {
107106
const displayedScheme = getScheme()
108-
if (env.scheme != displayedScheme) { env.scheme = displayedScheme ; modals.stylize() }
107+
if (env.ui.scheme != displayedScheme) { env.ui.scheme = displayedScheme ; modals.stylize() }
109108
}
110109

111110
// Your code here...

starters/chrome/extension/lib/dom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.scheme == 'dark' ? 'white' : 'black' }-stars-${starSize}`
30+
starsDiv.id = `${ this.dependencies.env.ui.scheme == 'dark' ? 'white' : 'black' }-stars-${starSize}`
3131
starsDivsContainer.append(starsDiv)
3232
})
3333
targetNode.prepend(starsDivsContainer)

0 commit comments

Comments
 (0)