Skip to content

Commit

Permalink
Refactored exposed timing vals of show.copyBtns() to local consts f…
Browse files Browse the repository at this point in the history
…or clarity ↞ [auto-sync from `adamlui/chatgpt-apps`]
  • Loading branch information
adamlui authored and kudo-sync-bot committed Sep 11, 2024
1 parent 4e0f3e8 commit fc72dad
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions greasemonkey/googlegpt.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
// @description:zu Yengeza izimpendulo ze-AI ku-Google Search (inikwa amandla yi-Google Gemma + GPT-4o!)
// @author KudoAI
// @namespace https://kudoai.com
// @version 2024.9.11.2
// @version 2024.9.11.3
// @license MIT
// @icon https://media.googlegpt.io/images/icons/googlegpt/black/icon48.png?8652a6e
// @icon64 https://media.googlegpt.io/images/icons/googlegpt/black/icon64.png?8652a6e
Expand Down Expand Up @@ -3397,9 +3397,9 @@
copyBtns() {
if (document.getElementById('copy-btn')) return

show.copyBtns.fadeDuration = 220 // ms
show.copyBtns.reappearDelay = 200 // ms
show.copyBtns.fadeDurationOffset = 150 // ms — for early hide to not trigger overflow scrollbar
const fadeDuration = 220, // ms
reappearDelay = 200, // ms
fadeDurationOffset = 150 // ms — for early hide to not trigger overflow scrollbar

appDiv.querySelectorAll('#googlegpt > pre, code').forEach(parentElem => {
const copySpan = document.createElement('span'),
Expand All @@ -3425,20 +3425,20 @@
textToCopy = textContainer.textContent.replace(/^>> /, '').trim(),
checkmarksSVG = icons.checkmarkDouble.create() ; checkmarksSVG.id = 'copied-icon'
setTimeout(() => copySpan.replaceChild(checkmarksSVG, copySVG), // change to copied icon
show.copyBtns.fadeDuration + show.copyBtns.reappearDelay - show.copyBtns.fadeDurationOffset) // ...after copySpan reappears
fadeDuration + reappearDelay - fadeDurationOffset) // ...after copySpan reappears
setTimeout(() => copySpan.replaceChild(copySVG, checkmarksSVG), 1355) // change back to copy icon
navigator.clipboard.writeText(textToCopy) // copy text to clipboard
if (!browser.isMobile) toggle.tooltip(event) // show copied status in tooltip
}
copySpan.onmouseup = () => { // zoom/fade-out
const copySVG = copySpan.querySelector('#copy-icon')
if (!copySVG) return // since clicking on copied icon
copySpan.style.animation = `btn-zoom-fade-out .${show.copyBtns.fadeDuration}s ease-out`
copySpan.style.animation = `btn-zoom-fade-out .${fadeDuration}s ease-out`
setTimeout(() => { // hide copySpan after animation nears completion
Object.assign(copySpan.style, { opacity: '0', visibility: 'hidden', animation: '' })
setTimeout(() => // show copySpan after show.copyBtns.reappearDelay
Object.assign(copySpan.style, { visibility: 'visible', opacity: '1' }), show.copyBtns.reappearDelay)
}, show.copyBtns.fadeDuration - show.copyBtns.fadeDurationOffset)
setTimeout(() => // show copySpan after reappearDelay
Object.assign(copySpan.style, { visibility: 'visible', opacity: '1' }), reappearDelay)
}, fadeDuration - fadeDurationOffset)
}

// Prepend button
Expand Down

0 comments on commit fc72dad

Please sign in to comment.