Skip to content

Commit

Permalink
Unabbr'd + hyphen-cased ID names for readability ↞ [auto-sync from `a…
Browse files Browse the repository at this point in the history
…damlui/chatgpt-apps/chatgpt-infinity/greasemonkey`]
  • Loading branch information
adamlui authored and kudo-sync-bot committed Jun 26, 2024
1 parent 6482426 commit 6772406
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 79 deletions.
38 changes: 19 additions & 19 deletions chrome/extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if (request.action == 'notify') notify(request.msg, request.position)
else if (request.action == 'alert') siteAlert(request.title, request.msg, request.btns)
else if (request.action == 'updateToggleHTML') updateToggleHTML()
else if (request.action == 'clickToggle') document.getElementById('infToggleLabel').click()
else if (request.action == 'clickToggle') document.getElementById('infinity-toggle-label').click()
else if (typeof window[request.action] == 'function') {
const args = Array.isArray(request.args) ? request.args // preserve array if supplied
: request.args !== undefined ? [request.args] : [] // convert to array if single or no arg
Expand Down Expand Up @@ -63,7 +63,7 @@
if (isGPT4oUI) navToggleDiv.style.flexGrow = 'unset' // overcome OpenAI .grow
if (!firstLink) parentToInsertInto.children[0].style.marginBottom = '5px'
navToggleDiv.style.paddingLeft = '8px'
const navicon = document.getElementById('infToggleNavicon')
const navicon = document.getElementById('infinity-toggle-navicon')
if (navicon) navicon.src = `${ // update navicon color in case scheme changed
config.assetHostURL }media/images/icons/infinity-symbol/${
chatgpt.isDarkMode() ? 'white' : 'black' }/icon32.png`
Expand All @@ -77,19 +77,19 @@
else {

// Create/size/position navicon
const navicon = document.getElementById('infToggleNavicon') || document.createElement('img')
navicon.id = 'infToggleNavicon'
const navicon = document.getElementById('infinity-toggle-navicon') || document.createElement('img')
navicon.id = 'infinity-toggle-navicon'
navicon.style.width = navicon.style.height = '1.25rem'
navicon.style.marginLeft = isGPT4oUI ? '2px' : '4px' ; navicon.style.marginRight = '4px'

// Create/ID/disable/hide/update checkbox
const toggleInput = document.getElementById('infToggleInput') || document.createElement('input')
toggleInput.id = 'infToggleInput' ; toggleInput.type = 'checkbox' ; toggleInput.disabled = true
const toggleInput = document.getElementById('infinity-toggle-input') || document.createElement('input')
toggleInput.id = 'infinity-toggle-input' ; toggleInput.type = 'checkbox' ; toggleInput.disabled = true
toggleInput.style.display = 'none' ; toggleInput.checked = config.infinityMode

// Create/ID/stylize switch
const switchSpan = document.getElementById('infSwitchSpan') || document.createElement('span')
switchSpan.id = 'infSwitchSpan'
const switchSpan = document.getElementById('infinity-switch-span') || document.createElement('span')
switchSpan.id = 'infinity-switch-span'
const switchStyles = {
position: 'relative', left: `${ chatgpt.browser.isMobile() ? 211 : !firstLink ? 160 : isGPT4oUI ? 147 : 152 }px`,
backgroundColor: toggleInput.checked ? '#ccc' : '#AD68FF', // init opposite final color
Expand All @@ -99,8 +99,8 @@
Object.assign(switchSpan.style, switchStyles)

// Create/stylize knob, append to switch
const knobSpan = document.getElementById('infToggleKnobSpan') || document.createElement('span')
knobSpan.id = 'infToggleKnobSpan'
const knobSpan = document.getElementById('infinity-toggle-knob-span') || document.createElement('span')
knobSpan.id = 'infinity-toggle-knob-span'
const knobWidth = 13
const knobStyles = {
position: 'absolute', left: '3px', bottom: '0.055em',
Expand All @@ -112,8 +112,8 @@
Object.assign(knobSpan.style, knobStyles) ; switchSpan.append(knobSpan)

// Create/stylize/fill label
const toggleLabel = document.getElementById('infToggleLabel') || document.createElement('label')
toggleLabel.id = 'infToggleLabel'
const toggleLabel = document.getElementById('infinity-toggle-label') || document.createElement('label')
toggleLabel.id = 'infinity-toggle-label'
if (!firstLink) { // add font size/weight since no firstLink to borrow from
toggleLabel.style.fontSize = '0.875rem' ; toggleLabel.style.fontWeight = 600 }
toggleLabel.style.marginLeft = `-${ !firstLink ? 23 : 41 }px` // left-shift to navicon
Expand Down Expand Up @@ -172,7 +172,7 @@
if (!fromMsg) notify(chrome.i18n.getMessage('menuLabel_infinityMode') + ': OFF')
fromMsg = false
chatgpt.stop() ; clearTimeout(infinityMode.isActive) ; infinityMode.isActive = null
document.getElementById('infToggleInput').checked = false // for window listener
document.getElementById('infinity-toggle-input').checked = false // for window listener
settings.save('infinityMode', false) // in case toggled by PV listener
},

Expand All @@ -182,8 +182,8 @@
// Define LIVE RESTART functions

restartInNewChat = () => { // eslint-disable-line no-undef
chatgpt.stop() ; document.getElementById('infToggleLabel').click() // toggle off
setTimeout(() => { document.getElementById('infToggleLabel').click() }, 750) // toggle on
chatgpt.stop() ; document.getElementById('infinity-toggle-label').click() // toggle off
setTimeout(() => { document.getElementById('infinity-toggle-label').click() }, 750) // toggle on
}

resetInSameChat = async () => { // eslint-disable-line no-undef
Expand Down Expand Up @@ -211,8 +211,8 @@
if (document.hidden !== undefined) // ...if Page Visibility API supported
document.onvisibilitychange = () => {
if (config.infinityMode) {
if (document.getElementById('infToggleLabel')) // ensure toggle state is accurate
document.getElementById('infToggleLabel').click()
if (document.getElementById('infinity-toggle-label')) // ensure toggle state is accurate
document.getElementById('infinity-toggle-label').click()
else infinityMode.deactivate()
}}

Expand Down Expand Up @@ -254,7 +254,7 @@

// Add LISTENER to toggle switch/label/config/menu
navToggleDiv.onclick = () => {
const toggleInput = document.getElementById('infToggleInput')
const toggleInput = document.getElementById('infinity-toggle-input')
toggleInput.checked = !toggleInput.checked
settings.save('infinityMode', toggleInput.checked)
updateToggleHTML()
Expand All @@ -263,7 +263,7 @@

// Auto-start if enabled
settings.load('autoStart').then(() => { if (config.autoStart) {
const navToggle = document.getElementById('infToggleInput')
const navToggle = document.getElementById('infinity-toggle-input')
if (navToggle) navToggle.parentNode.click()
else { // activate via infinityMode funcs obj
infinityMode.activate()
Expand Down
38 changes: 19 additions & 19 deletions edge/extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if (request.action == 'notify') notify(request.msg, request.position)
else if (request.action == 'alert') siteAlert(request.title, request.msg, request.btns)
else if (request.action == 'updateToggleHTML') updateToggleHTML()
else if (request.action == 'clickToggle') document.getElementById('infToggleLabel').click()
else if (request.action == 'clickToggle') document.getElementById('infinity-toggle-label').click()
else if (typeof window[request.action] == 'function') {
const args = Array.isArray(request.args) ? request.args // preserve array if supplied
: request.args !== undefined ? [request.args] : [] // convert to array if single or no arg
Expand Down Expand Up @@ -63,7 +63,7 @@
if (isGPT4oUI) navToggleDiv.style.flexGrow = 'unset' // overcome OpenAI .grow
if (!firstLink) parentToInsertInto.children[0].style.marginBottom = '5px'
navToggleDiv.style.paddingLeft = '8px'
const navicon = document.getElementById('infToggleNavicon')
const navicon = document.getElementById('infinity-toggle-navicon')
if (navicon) navicon.src = `${ // update navicon color in case scheme changed
config.assetHostURL }media/images/icons/infinity-symbol/${
chatgpt.isDarkMode() ? 'white' : 'black' }/icon32.png`
Expand All @@ -77,19 +77,19 @@
else {

// Create/size/position navicon
const navicon = document.getElementById('infToggleNavicon') || document.createElement('img')
navicon.id = 'infToggleNavicon'
const navicon = document.getElementById('infinity-toggle-navicon') || document.createElement('img')
navicon.id = 'infinity-toggle-navicon'
navicon.style.width = navicon.style.height = '1.25rem'
navicon.style.marginLeft = isGPT4oUI ? '2px' : '4px' ; navicon.style.marginRight = '4px'

// Create/ID/disable/hide/update checkbox
const toggleInput = document.getElementById('infToggleInput') || document.createElement('input')
toggleInput.id = 'infToggleInput' ; toggleInput.type = 'checkbox' ; toggleInput.disabled = true
const toggleInput = document.getElementById('infinity-toggle-input') || document.createElement('input')
toggleInput.id = 'infinity-toggle-input' ; toggleInput.type = 'checkbox' ; toggleInput.disabled = true
toggleInput.style.display = 'none' ; toggleInput.checked = config.infinityMode

// Create/ID/stylize switch
const switchSpan = document.getElementById('infSwitchSpan') || document.createElement('span')
switchSpan.id = 'infSwitchSpan'
const switchSpan = document.getElementById('infinity-switch-span') || document.createElement('span')
switchSpan.id = 'infinity-switch-span'
const switchStyles = {
position: 'relative', left: `${ chatgpt.browser.isMobile() ? 211 : !firstLink ? 160 : isGPT4oUI ? 147 : 152 }px`,
backgroundColor: toggleInput.checked ? '#ccc' : '#AD68FF', // init opposite final color
Expand All @@ -99,8 +99,8 @@
Object.assign(switchSpan.style, switchStyles)

// Create/stylize knob, append to switch
const knobSpan = document.getElementById('infToggleKnobSpan') || document.createElement('span')
knobSpan.id = 'infToggleKnobSpan'
const knobSpan = document.getElementById('infinity-toggle-knob-span') || document.createElement('span')
knobSpan.id = 'infinity-toggle-knob-span'
const knobWidth = 13
const knobStyles = {
position: 'absolute', left: '3px', bottom: '0.055em',
Expand All @@ -112,8 +112,8 @@
Object.assign(knobSpan.style, knobStyles) ; switchSpan.append(knobSpan)

// Create/stylize/fill label
const toggleLabel = document.getElementById('infToggleLabel') || document.createElement('label')
toggleLabel.id = 'infToggleLabel'
const toggleLabel = document.getElementById('infinity-toggle-label') || document.createElement('label')
toggleLabel.id = 'infinity-toggle-label'
if (!firstLink) { // add font size/weight since no firstLink to borrow from
toggleLabel.style.fontSize = '0.875rem' ; toggleLabel.style.fontWeight = 600 }
toggleLabel.style.marginLeft = `-${ !firstLink ? 23 : 41 }px` // left-shift to navicon
Expand Down Expand Up @@ -172,7 +172,7 @@
if (!fromMsg) notify(chrome.i18n.getMessage('menuLabel_infinityMode') + ': OFF')
fromMsg = false
chatgpt.stop() ; clearTimeout(infinityMode.isActive) ; infinityMode.isActive = null
document.getElementById('infToggleInput').checked = false // for window listener
document.getElementById('infinity-toggle-input').checked = false // for window listener
settings.save('infinityMode', false) // in case toggled by PV listener
},

Expand All @@ -182,8 +182,8 @@
// Define LIVE RESTART functions

restartInNewChat = () => { // eslint-disable-line no-undef
chatgpt.stop() ; document.getElementById('infToggleLabel').click() // toggle off
setTimeout(() => { document.getElementById('infToggleLabel').click() }, 750) // toggle on
chatgpt.stop() ; document.getElementById('infinity-toggle-label').click() // toggle off
setTimeout(() => { document.getElementById('infinity-toggle-label').click() }, 750) // toggle on
}

resetInSameChat = async () => { // eslint-disable-line no-undef
Expand Down Expand Up @@ -211,8 +211,8 @@
if (document.hidden !== undefined) // ...if Page Visibility API supported
document.onvisibilitychange = () => {
if (config.infinityMode) {
if (document.getElementById('infToggleLabel')) // ensure toggle state is accurate
document.getElementById('infToggleLabel').click()
if (document.getElementById('infinity-toggle-label')) // ensure toggle state is accurate
document.getElementById('infinity-toggle-label').click()
else infinityMode.deactivate()
}}

Expand Down Expand Up @@ -254,7 +254,7 @@

// Add LISTENER to toggle switch/label/config/menu
navToggleDiv.onclick = () => {
const toggleInput = document.getElementById('infToggleInput')
const toggleInput = document.getElementById('infinity-toggle-input')
toggleInput.checked = !toggleInput.checked
settings.save('infinityMode', toggleInput.checked)
updateToggleHTML()
Expand All @@ -263,7 +263,7 @@

// Auto-start if enabled
settings.load('autoStart').then(() => { if (config.autoStart) {
const navToggle = document.getElementById('infToggleInput')
const navToggle = document.getElementById('infinity-toggle-input')
if (navToggle) navToggle.parentNode.click()
else { // activate via infinityMode funcs obj
infinityMode.activate()
Expand Down
Loading

0 comments on commit 6772406

Please sign in to comment.