Skip to content

Commit

Permalink
Changed all document.querySelector()s of IDs to use `.getElementByI…
Browse files Browse the repository at this point in the history
…d` for improved efficiency ↞ [auto-sync from `adamlui/chatgpt-apps/chatgpt-auto-refresh`]
  • Loading branch information
adamlui authored and kudo-sync-bot committed Jun 17, 2024
1 parent 8d9b0b4 commit ac4d60f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions chatgpt/chatgpt-auto-refresh/chatgpt-auto-refresh.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
// @description:zu *NGOKUPHEPHA* susa ukusetha kabusha ingxoxo yemizuzu eyi-10 + amaphutha enethiwekhi ahlala njalo + Ukuhlolwa kwe-Cloudflare ku-ChatGPT.
// @author Adam Lui
// @namespace https://github.com/adamlui
// @version 2024.6.16
// @version 2024.6.17
// @license MIT
// @match *://chatgpt.com/*
// @match *://chat.openai.com/*
Expand Down Expand Up @@ -366,7 +366,7 @@

// Add LISTENER to toggle switch/label/config/menu/auto-refresh
navToggleDiv.addEventListener('click', () => {
const toggleInput = document.querySelector('#arToggleInput')
const toggleInput = document.getElementById('arToggleInput')
toggleInput.checked = !toggleInput.checked ; config.arDisabled = !toggleInput.checked
updateToggleHTML() ; refreshMenu()
if (!config.arDisabled && !chatgpt.autoRefresh.isActive) {
Expand Down Expand Up @@ -405,7 +405,7 @@
+ ( msgs.menuLabel_autoRefresh || 'Auto-Refresh' ) + ' ↻ '
+ state.separator + state.word[+!config.arDisabled]
menuIDs.push(GM_registerMenuCommand(arLabel, () => {
document.querySelector('#arSwitchSpan').click()
document.getElementById('arSwitchSpan').click()
}))

// Add command to toggle visibility of toggle
Expand Down Expand Up @@ -584,26 +584,26 @@
if (isGPT4oUI) navToggleDiv.style.flexGrow = 'unset' // overcome OpenAI .grow
if (!firstLink) parentToInsertInto.children[0].style.marginBottom = '5px'
navToggleDiv.style.paddingLeft = '8px'
document.querySelector('#arToggleFavicon').src = `${ // update navicon color in case scheme changed
document.getElementById('arToggleFavicon').src = `${ // update navicon color in case scheme changed
config.assetHostURL }media/images/icons/auto-refresh/${
chatgpt.isDarkMode() ? 'white' : 'black' }/icon32.png`
}

function updateToggleHTML() {

// Create/size/position navicon
const navicon = document.querySelector('#arToggleFavicon') || document.createElement('img')
const navicon = document.getElementById('arToggleFavicon') || document.createElement('img')
navicon.id = 'arToggleFavicon'
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.querySelector('#arToggleInput') || document.createElement('input')
const toggleInput = document.getElementById('arToggleInput') || document.createElement('input')
toggleInput.id = 'arToggleInput' ; toggleInput.type = 'checkbox' ; toggleInput.disabled = true
toggleInput.style.display = 'none' ; toggleInput.checked = !config.arDisabled

// Create/ID/stylize switch
const switchSpan = document.querySelector('#arSwitchSpan') || document.createElement('span')
const switchSpan = document.getElementById('arSwitchSpan') || document.createElement('span')
switchSpan.id = 'arSwitchSpan'
const switchStyles = {
position: 'relative', left: `${ chatgpt.browser.isMobile() ? 211 : !firstLink ? 160 : isGPT4oUI ? 147 : 152 }px`,
Expand All @@ -614,7 +614,7 @@
Object.assign(switchSpan.style, switchStyles)

// Create/stylize knob, append to switch
const knobSpan = document.querySelector('#arToggleKnobSpan') || document.createElement('span')
const knobSpan = document.getElementById('arToggleKnobSpan') || document.createElement('span')
knobSpan.id = 'arToggleKnobSpan'
const knobWidth = 13
const knobStyles = {
Expand All @@ -627,7 +627,7 @@
Object.assign(knobSpan.style, knobStyles) ; switchSpan.append(knobSpan)

// Create/stylize/fill label
const toggleLabel = document.querySelector('#arToggleLabel') || document.createElement('label')
const toggleLabel = document.getElementById('arToggleLabel') || document.createElement('label')
toggleLabel.id = 'arToggleLabel'
if (!firstLink) { // add font size/weight since no firstLink to borrow from
toggleLabel.style.fontSize = '0.875rem' ; toggleLabel.style.fontWeight = 600 }
Expand Down

0 comments on commit ac4d60f

Please sign in to comment.