Skip to content

Commit

Permalink
Replaced nav in toggle obj/elem names w/ more semantic sidebar ↞ …
Browse files Browse the repository at this point in the history
  • Loading branch information
kudo-sync-bot committed Nov 19, 2024
1 parent 9241172 commit c56e306
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions chatgpt/chatgpt-auto-talk/chatgpt-auto-talk.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
// @description:zu Dlala izimpendulo ze-ChatGPT ngokuzenzakalela
// @author Adam Lui
// @namespace https://github.com/adamlui
// @version 2024.11.19
// @version 2024.11.19.1
// @license MIT
// @icon https://assets.chatgptautotalk.com/images/icons/openai/black/icon48.png?v=9f1ed3c
// @icon64 https://assets.chatgptautotalk.com/images/icons/openai/black/icon64.png?v=9f1ed3c
Expand Down Expand Up @@ -380,7 +380,7 @@
+ menu.state.separator + menu.state.words[+!config.toggleHidden]
menu.ids.push(GM_registerMenuCommand(tvLabel, () => {
settings.save('toggleHidden', !config.toggleHidden)
navToggleDiv.style.display = config.toggleHidden ? 'none' : 'flex' // toggle visibility
sidebarToggleDiv.style.display = config.toggleHidden ? 'none' : 'flex' // toggle visibility
notify(`${app.msgs.menuLabel_toggleVis}: ${menu.state.words[+!config.toggleHidden]}`)
menu.refresh()
}))
Expand Down Expand Up @@ -570,20 +570,20 @@

// Define UI functions

const navToggle = {
const sidebarToggle = {
insert() {
if (document.getElementById('auto-talk-toggle-navicon')) return

// Insert toggle
const sidebar = document.querySelectorAll('nav')[env.browser.isMobile ? 1 : 0]
if (!sidebar) return
sidebar.insertBefore(navToggleDiv, sidebar.children[1])
sidebar.insertBefore(sidebarToggleDiv, sidebar.children[1])

// Tweak styles
const knobSpan = document.getElementById('auto-talk-toggle-knob-span'),
navicon = document.getElementById('auto-talk-toggle-navicon')
navToggleDiv.style.flexGrow = 'unset' // overcome OpenAI .grow
navToggleDiv.style.paddingLeft = '8px'
sidebarToggleDiv.style.flexGrow = 'unset' // overcome OpenAI .grow
sidebarToggleDiv.style.paddingLeft = '8px'
if (knobSpan) knobSpan.style.boxShadow = (
'rgba(0, 0, 0, .3) 0 1px 2px 0' + ( chatgpt.isDarkMode() ? ', rgba(0, 0, 0, .15) 0 3px 6px 2px' : '' ))
if (navicon) navicon.src = `${ // update navicon color in case scheme changed
Expand All @@ -592,7 +592,7 @@
},

update() {
if (config.toggleHidden) navToggleDiv.style.display = 'none'
if (config.toggleHidden) sidebarToggleDiv.style.display = 'none'
else {

// Create/size/position navicon
Expand Down Expand Up @@ -643,10 +643,10 @@
+ ( toggleInput.checked ? ( app.msgs.state_enabled || 'enabled' )
: ( app.msgs.state_disabled ))
// Append elements
for (const elem of [navicon, toggleInput, switchSpan, toggleLabel]) navToggleDiv.append(elem)
for (const elem of [navicon, toggleInput, switchSpan, toggleLabel]) sidebarToggleDiv.append(elem)

// Update visual state
navToggleDiv.style.display = 'flex'
sidebarToggleDiv.style.display = 'flex'
setTimeout(() => {
switchSpan.style.backgroundColor = toggleInput.checked ? '#ad68ff' : '#ccc'
switchSpan.style.boxShadow = toggleInput.checked ? '2px 1px 9px #d8a9ff' : 'none'
Expand Down Expand Up @@ -706,26 +706,26 @@
}

// Create NAV TOGGLE div, add styles
const navToggleDiv = document.createElement('div')
navToggleDiv.style.height = '37px'
navToggleDiv.style.margin = '2px 0' // add v-margins
navToggleDiv.style.userSelect = 'none' // prevent highlighting
navToggleDiv.style.cursor = 'pointer' // add finger cursor
navToggle.update() // create children
const sidebarToggleDiv = document.createElement('div')
sidebarToggleDiv.style.height = '37px'
sidebarToggleDiv.style.margin = '2px 0' // add v-margins
sidebarToggleDiv.style.userSelect = 'none' // prevent highlighting
sidebarToggleDiv.style.cursor = 'pointer' // add finger cursor
sidebarToggle.update() // create children
if (ui.firstLink) { // borrow/assign CLASSES from sidebar div
const firstIcon = ui.firstLink.querySelector('div:first-child'),
firstLabel = ui.firstLink.querySelector('div:nth-child(2)')
navToggleDiv.classList.add(...ui.firstLink.classList, ...(firstLabel?.classList || []))
navToggleDiv.querySelector('img')?.classList.add(...(firstIcon?.classList || []))
sidebarToggleDiv.classList.add(...ui.firstLink.classList, ...(firstLabel?.classList || []))
sidebarToggleDiv.querySelector('img')?.classList.add(...(firstIcon?.classList || []))
}

navToggle.insert()
sidebarToggle.insert()

// Add LISTENER to toggle switch/label/config/menu
navToggleDiv.onclick = () => {
sidebarToggleDiv.onclick = () => {
const toggleInput = document.getElementById('auto-talk-toggle-input')
toggleInput.checked = !toggleInput.checked ; config.autoTalkDisabled = !toggleInput.checked
navToggle.update() ; menu.refresh()
sidebarToggle.update() ; menu.refresh()
notify(`${app.msgs.mode_autoTalk}: ${menu.state.words[+!config.autoTalkDisabled]}`)
settings.save('autoTalkDisabled', config.autoTalkDisabled)
}
Expand All @@ -747,14 +747,14 @@
// Monitor <html> to maintain NAV TOGGLE VISIBILITY on node changes
new MutationObserver(mutations => mutations.forEach(mutation => {
if (mutation.type == 'childList' && mutation.addedNodes.length && !config.toggleHidden)
navToggle.insert()
sidebarToggle.insert()
})).observe(document.documentElement, { childList: true, subtree: true })

// Disable distracting SIDEBAR CLICK-ZOOM effect
if (!document.querySelector('[sidebar-click-zoom-observed]')) {
new MutationObserver(mutations => mutations.forEach(({ target }) => {
if (target.closest('[class*="sidebar"]') // include sidebar divs
&& !target.id.endsWith('-knob-span') // exclude our navToggle
&& !target.id.endsWith('-knob-span') // exclude our sidebarToggle
&& target.style.transform != 'none' // click-zoom occurred
) target.style.transform = 'none'
})).observe(document.body, { attributes: true, subtree: true, attributeFilter: [ 'style' ]})
Expand Down

0 comments on commit c56e306

Please sign in to comment.