|
38 | 38 | if (!config.replyInterval) settings.save('replyInterval', 7) // init refresh interval to 7 secs if unset
|
39 | 39 | })
|
40 | 40 |
|
41 |
| - // Init UI flags |
42 |
| - await Promise.race([chatgpt.isLoaded(), new Promise(resolve => setTimeout(resolve, 5000))]) // initial UI loaded |
43 |
| - await chatgpt.sidebar.isLoaded() |
44 |
| - const isGPT4oUI = document.documentElement.className.includes(' '), |
45 |
| - firstLink = chatgpt.getNewChatLink() |
46 |
| - |
47 |
| - // Add LISTENER to auto-disable Infinity Mode |
48 |
| - if (document.hidden !== undefined) // ...if Page Visibility API supported |
49 |
| - document.onvisibilitychange = () => { |
50 |
| - if (config.infinityMode) { |
51 |
| - if (document.getElementById('infToggleLabel')) // ensure toggle state is accurate |
52 |
| - document.getElementById('infToggleLabel').click() |
53 |
| - else infinityMode.deactivate() |
54 |
| - }} |
55 |
| - |
56 |
| - // Add/update TWEAKS style |
57 |
| - const tweaksStyleUpdated = 202405171 // datestamp of last edit for this file's `tweaksStyle` |
58 |
| - let tweaksStyle = document.getElementById('tweaks-style') // try to select existing style |
59 |
| - if (!tweaksStyle || parseInt(tweaksStyle.getAttribute('last-updated'), 10) < tweaksStyleUpdated) { // if missing or outdated |
60 |
| - if (!tweaksStyle) { // outright missing, create/id/attr/append it first |
61 |
| - tweaksStyle = document.createElement('style') ; tweaksStyle.id = 'tweaks-style' |
62 |
| - tweaksStyle.setAttribute('last-updated', tweaksStyleUpdated.toString()) |
63 |
| - document.head.append(tweaksStyle) |
64 |
| - } |
65 |
| - tweaksStyle.innerText = ( |
66 |
| - '.chatgpt-modal button {' |
67 |
| - + 'font-size: 0.77rem ; text-transform: uppercase ;' |
68 |
| - + 'border-radius: 0 !important ; padding: 5px !important ; min-width: 102px }' |
69 |
| - + '.modal-buttons { margin-left: -13px !important }' |
70 |
| - + '.sticky div:active, .sticky div:focus {' // post-GPT-4o UI sidebar button container |
71 |
| - + 'transform: none !important }' // disable distracting click zoom effect |
72 |
| - ) |
73 |
| - } |
74 |
| - |
75 |
| - // Create NAV TOGGLE div, add styles |
76 |
| - const navToggleDiv = document.createElement('div') |
77 |
| - navToggleDiv.style.height = '37px' |
78 |
| - navToggleDiv.style.margin = '2px 0' // add v-margins |
79 |
| - navToggleDiv.style.userSelect = 'none' // prevent highlighting |
80 |
| - navToggleDiv.style.cursor = 'pointer' // add finger cursor |
81 |
| - updateToggleHTML() // create children |
82 |
| - |
83 |
| - if (firstLink) { // borrow/assign classes from sidebar div |
84 |
| - const firstIcon = firstLink.querySelector('div:first-child'), |
85 |
| - firstLabel = firstLink.querySelector('div:nth-child(2)') |
86 |
| - navToggleDiv.classList.add(...firstLink.classList, ...firstLabel.classList) |
87 |
| - navToggleDiv.querySelector('img')?.classList.add(...firstIcon.classList) |
88 |
| - } |
89 |
| - |
90 |
| - settings.load(['extensionDisabled']).then(() => { if (!config.extensionDisabled) insertToggle() }) |
91 |
| - |
92 |
| - // Add LISTENER to toggle switch/label/config/menu |
93 |
| - navToggleDiv.onclick = () => { |
94 |
| - const toggleInput = document.getElementById('infToggleInput') |
95 |
| - toggleInput.checked = !toggleInput.checked |
96 |
| - settings.save('infinityMode', toggleInput.checked) |
97 |
| - updateToggleHTML() |
98 |
| - infinityMode.toggle() |
99 |
| - } |
100 |
| - |
101 |
| - // Monitor <html> to maintain SIDEBAR TOGGLE VISIBILITY on node changes |
102 |
| - const nodeObserver = new MutationObserver(mutations => { mutations.forEach(mutation => { |
103 |
| - if (mutation.type == 'childList' && mutation.addedNodes.length) |
104 |
| - settings.load(['extensionDisabled']).then(() => { if (!config.extensionDisabled) insertToggle() |
105 |
| - })})}) ; nodeObserver.observe(document.documentElement, { childList: true, subtree: true }) |
106 |
| - |
107 | 41 | // Define FEEDBACK functions
|
108 | 42 |
|
109 | 43 | function notify(msg, position = '', notifDuration = '', shadow = '') {
|
|
261 | 195 | // Define SYNC function
|
262 | 196 |
|
263 | 197 | syncExtension = () => { // settings + sidebar toggle visibility
|
264 |
| - settings.load(['extensionDisabled', 'toggleHidden', 'autoScrollDisabled', |
265 |
| - 'replyTopic', 'replyInterval', 'replyLanguage']) |
| 198 | + settings.load(['autoScrollDisabled', 'autoStart', 'extensionDisabled', |
| 199 | + 'replyInterval', 'replyLanguage', 'replyTopic', 'toggleHidden']) |
266 | 200 | .then(() => { insertToggle() ; updateToggleHTML() // hide/show sidebar toggle based on latest setting
|
267 | 201 | })}
|
268 | 202 |
|
| 203 | + // Init UI flags |
| 204 | + await Promise.race([chatgpt.isLoaded(), new Promise(resolve => setTimeout(resolve, 5000))]) // initial UI loaded |
| 205 | + await chatgpt.sidebar.isLoaded() |
| 206 | + const isGPT4oUI = document.documentElement.className.includes(' '), |
| 207 | + firstLink = chatgpt.getNewChatLink() |
| 208 | + |
| 209 | + // Add LISTENER to auto-disable Infinity Mode |
| 210 | + if (document.hidden !== undefined) // ...if Page Visibility API supported |
| 211 | + document.onvisibilitychange = () => { |
| 212 | + if (config.infinityMode) { |
| 213 | + if (document.getElementById('infToggleLabel')) // ensure toggle state is accurate |
| 214 | + document.getElementById('infToggleLabel').click() |
| 215 | + else infinityMode.deactivate() |
| 216 | + }} |
| 217 | + |
| 218 | + // Add/update TWEAKS style |
| 219 | + const tweaksStyleUpdated = 202405171 // datestamp of last edit for this file's `tweaksStyle` |
| 220 | + let tweaksStyle = document.getElementById('tweaks-style') // try to select existing style |
| 221 | + if (!tweaksStyle || parseInt(tweaksStyle.getAttribute('last-updated'), 10) < tweaksStyleUpdated) { // if missing or outdated |
| 222 | + if (!tweaksStyle) { // outright missing, create/id/attr/append it first |
| 223 | + tweaksStyle = document.createElement('style') ; tweaksStyle.id = 'tweaks-style' |
| 224 | + tweaksStyle.setAttribute('last-updated', tweaksStyleUpdated.toString()) |
| 225 | + document.head.append(tweaksStyle) |
| 226 | + } |
| 227 | + tweaksStyle.innerText = ( |
| 228 | + '.chatgpt-modal button {' |
| 229 | + + 'font-size: 0.77rem ; text-transform: uppercase ;' |
| 230 | + + 'border-radius: 0 !important ; padding: 5px !important ; min-width: 102px }' |
| 231 | + + '.modal-buttons { margin-left: -13px !important }' |
| 232 | + + '.sticky div:active, .sticky div:focus {' // post-GPT-4o UI sidebar button container |
| 233 | + + 'transform: none !important }' // disable distracting click zoom effect |
| 234 | + ) |
| 235 | + } |
| 236 | + |
| 237 | + // Create NAV TOGGLE div, add styles |
| 238 | + const navToggleDiv = document.createElement('div') |
| 239 | + navToggleDiv.style.height = '37px' |
| 240 | + navToggleDiv.style.margin = '2px 0' // add v-margins |
| 241 | + navToggleDiv.style.userSelect = 'none' // prevent highlighting |
| 242 | + navToggleDiv.style.cursor = 'pointer' // add finger cursor |
| 243 | + updateToggleHTML() // create children |
| 244 | + |
| 245 | + if (firstLink) { // borrow/assign classes from sidebar div |
| 246 | + const firstIcon = firstLink.querySelector('div:first-child'), |
| 247 | + firstLabel = firstLink.querySelector('div:nth-child(2)') |
| 248 | + navToggleDiv.classList.add(...firstLink.classList, ...firstLabel.classList) |
| 249 | + navToggleDiv.querySelector('img')?.classList.add(...firstIcon.classList) |
| 250 | + } |
| 251 | + |
| 252 | + settings.load(['extensionDisabled']).then(() => { if (!config.extensionDisabled) insertToggle() }) |
| 253 | + |
| 254 | + // Add LISTENER to toggle switch/label/config/menu |
| 255 | + navToggleDiv.onclick = () => { |
| 256 | + const toggleInput = document.getElementById('infToggleInput') |
| 257 | + toggleInput.checked = !toggleInput.checked |
| 258 | + settings.save('infinityMode', toggleInput.checked) |
| 259 | + updateToggleHTML() |
| 260 | + infinityMode.toggle() |
| 261 | + } |
| 262 | + |
| 263 | + // Auto-start if enabled |
| 264 | + settings.load('autoStart').then(() => { if (config.autoStart) { |
| 265 | + const navToggle = document.getElementById('infToggleInput') |
| 266 | + if (navToggle) navToggle.parentNode.click() |
| 267 | + else { // activate via infinityMode funcs obj |
| 268 | + infinityMode.activate() |
| 269 | + settings.save('infinityMode', true) // so popup.js updates toggle |
| 270 | + }}}) |
| 271 | + |
| 272 | + // Monitor <html> to maintain SIDEBAR TOGGLE VISIBILITY on node changes |
| 273 | + const nodeObserver = new MutationObserver(mutations => { mutations.forEach(mutation => { |
| 274 | + if (mutation.type == 'childList' && mutation.addedNodes.length) |
| 275 | + settings.load(['extensionDisabled']).then(() => { if (!config.extensionDisabled) insertToggle() |
| 276 | + })})}) ; nodeObserver.observe(document.documentElement, { childList: true, subtree: true }) |
| 277 | + |
269 | 278 | })()
|
0 commit comments