Skip to content

Commit 33df4ef

Browse files
committed
1 parent 43b1a17 commit 33df4ef

1 file changed

Lines changed: 57 additions & 52 deletions

File tree

chatgpt/chatgpt-auto-talk/chatgpt-auto-talk.user.js

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
// @description:zu Dlala izimpendulo ze-ChatGPT ngokuzenzakalela
226226
// @author Adam Lui
227227
// @namespace https://github.com/adamlui
228-
// @version 2025.10.5.6
228+
// @version 2025.10.5.7
229229
// @license MIT
230230
// @icon data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22180%22%20height=%22180%22%20fill=%22none%22%3E%3Cstyle%3E:root%7B--primary-fill:%23000;--secondary-fill:%23fff;%7D@media%20(prefers-color-scheme:dark)%7B:root%7B--primary-fill:%23fff;--secondary-fill:%23000;%7D%7D%3C/style%3E%3Cg%20clip-path=%22url(%23a)%22%3E%3Crect%20width=%22180%22%20height=%22180%22%20fill=%22var(--primary-fill)%22%20rx=%2290%22/%3E%3Cg%20clip-path=%22url(%23b)%22%3E%3Cpath%20fill=%22var(--secondary-fill)%22%20d=%22M75.91%2073.628V62.232c0-.96.36-1.68%201.199-2.16l22.912-13.194c3.119-1.8%206.838-2.639%2010.676-2.639%2014.394%200%2023.511%2011.157%2023.511%2023.032%200%20.839%200%201.799-.12%202.758l-23.752-13.914c-1.439-.84-2.879-.84-4.318%200L75.91%2073.627Zm53.499%2044.383v-27.23c0-1.68-.72-2.88-2.159-3.719L97.142%2069.55l9.836-5.638c.839-.48%201.559-.48%202.399%200l22.912%2013.195c6.598%203.839%2011.035%2011.995%2011.035%2019.912%200%209.116-5.397%2017.513-13.915%2020.992v.001Zm-60.577-23.99-9.836-5.758c-.84-.48-1.2-1.2-1.2-2.16v-26.39c0-12.834%209.837-22.55%2023.152-22.55%205.039%200%209.716%201.679%2013.676%204.678L70.993%2055.516c-1.44.84-2.16%202.039-2.16%203.719v34.787-.002Zm21.173%2012.234L75.91%2098.339V81.546l14.095-7.917%2014.094%207.917v16.793l-14.094%207.916Zm9.056%2036.467c-5.038%200-9.716-1.68-13.675-4.678l23.631-13.676c1.439-.839%202.159-2.038%202.159-3.718V85.863l9.956%205.757c.84.48%201.2%201.2%201.2%202.16v26.389c0%2012.835-9.957%2022.552-23.27%2022.552v.001Zm-28.43-26.75L47.72%20102.778c-6.599-3.84-11.036-11.996-11.036-19.913%200-9.236%205.518-17.513%2014.034-20.992v27.35c0%201.68.72%202.879%202.16%203.718l29.989%2017.393-9.837%205.638c-.84.48-1.56.48-2.399%200Zm-1.318%2019.673c-13.555%200-23.512-10.196-23.512-22.792%200-.959.12-1.919.24-2.879l23.63%2013.675c1.44.84%202.88.84%204.32%200l30.108-17.392v11.395c0%20.96-.361%201.68-1.2%202.16l-22.912%2013.194c-3.119%201.8-6.837%202.639-10.675%202.639Zm29.748%2014.274c14.515%200%2026.63-10.316%2029.39-23.991%2013.434-3.479%2022.071-16.074%2022.071-28.91%200-8.396-3.598-16.553-10.076-22.43.6-2.52.96-5.039.96-7.557%200-17.153-13.915-29.99-29.989-29.99-3.239%200-6.358.48-9.477%201.56-5.398-5.278-12.835-8.637-20.992-8.637-14.515%200-26.63%2010.316-29.39%2023.991-13.434%203.48-22.07%2016.074-22.07%2028.91%200%208.396%203.598%2016.553%2010.075%2022.431-.6%202.519-.96%205.038-.96%207.556%200%2017.154%2013.915%2029.989%2029.99%2029.989%203.238%200%206.357-.479%209.476-1.559%205.397%205.278%2012.835%208.637%2020.992%208.637Z%22/%3E%3C/g%3E%3C/g%3E%3Cdefs%3E%3CclipPath%20id=%22a%22%3E%3Cpath%20d=%22M0%200h180v180H0z%22/%3E%3C/clipPath%3E%3CclipPath%20id=%22b%22%3E%3Cpath%20d=%22M29.487%2029.964h121.035v119.954H29.487z%22/%3E%3C/clipPath%3E%3C/defs%3E%3C/svg%3E
231231
// @icon64 data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22180%22%20height=%22180%22%20fill=%22none%22%3E%3Cstyle%3E:root%7B--primary-fill:%23000;--secondary-fill:%23fff;%7D@media%20(prefers-color-scheme:dark)%7B:root%7B--primary-fill:%23fff;--secondary-fill:%23000;%7D%7D%3C/style%3E%3Cg%20clip-path=%22url(%23a)%22%3E%3Crect%20width=%22180%22%20height=%22180%22%20fill=%22var(--primary-fill)%22%20rx=%2290%22/%3E%3Cg%20clip-path=%22url(%23b)%22%3E%3Cpath%20fill=%22var(--secondary-fill)%22%20d=%22M75.91%2073.628V62.232c0-.96.36-1.68%201.199-2.16l22.912-13.194c3.119-1.8%206.838-2.639%2010.676-2.639%2014.394%200%2023.511%2011.157%2023.511%2023.032%200%20.839%200%201.799-.12%202.758l-23.752-13.914c-1.439-.84-2.879-.84-4.318%200L75.91%2073.627Zm53.499%2044.383v-27.23c0-1.68-.72-2.88-2.159-3.719L97.142%2069.55l9.836-5.638c.839-.48%201.559-.48%202.399%200l22.912%2013.195c6.598%203.839%2011.035%2011.995%2011.035%2019.912%200%209.116-5.397%2017.513-13.915%2020.992v.001Zm-60.577-23.99-9.836-5.758c-.84-.48-1.2-1.2-1.2-2.16v-26.39c0-12.834%209.837-22.55%2023.152-22.55%205.039%200%209.716%201.679%2013.676%204.678L70.993%2055.516c-1.44.84-2.16%202.039-2.16%203.719v34.787-.002Zm21.173%2012.234L75.91%2098.339V81.546l14.095-7.917%2014.094%207.917v16.793l-14.094%207.916Zm9.056%2036.467c-5.038%200-9.716-1.68-13.675-4.678l23.631-13.676c1.439-.839%202.159-2.038%202.159-3.718V85.863l9.956%205.757c.84.48%201.2%201.2%201.2%202.16v26.389c0%2012.835-9.957%2022.552-23.27%2022.552v.001Zm-28.43-26.75L47.72%20102.778c-6.599-3.84-11.036-11.996-11.036-19.913%200-9.236%205.518-17.513%2014.034-20.992v27.35c0%201.68.72%202.879%202.16%203.718l29.989%2017.393-9.837%205.638c-.84.48-1.56.48-2.399%200Zm-1.318%2019.673c-13.555%200-23.512-10.196-23.512-22.792%200-.959.12-1.919.24-2.879l23.63%2013.675c1.44.84%202.88.84%204.32%200l30.108-17.392v11.395c0%20.96-.361%201.68-1.2%202.16l-22.912%2013.194c-3.119%201.8-6.837%202.639-10.675%202.639Zm29.748%2014.274c14.515%200%2026.63-10.316%2029.39-23.991%2013.434-3.479%2022.071-16.074%2022.071-28.91%200-8.396-3.598-16.553-10.076-22.43.6-2.52.96-5.039.96-7.557%200-17.153-13.915-29.99-29.989-29.99-3.239%200-6.358.48-9.477%201.56-5.398-5.278-12.835-8.637-20.992-8.637-14.515%200-26.63%2010.316-29.39%2023.991-13.434%203.48-22.07%2016.074-22.07%2028.91%200%208.396%203.598%2016.553%2010.075%2022.431-.6%202.519-.96%205.038-.96%207.556%200%2017.154%2013.915%2029.989%2029.99%2029.989%203.238%200%206.357-.479%209.476-1.559%205.397%205.278%2012.835%208.637%2020.992%208.637Z%22/%3E%3C/g%3E%3C/g%3E%3Cdefs%3E%3CclipPath%20id=%22a%22%3E%3Cpath%20d=%22M0%200h180v180H0z%22/%3E%3C/clipPath%3E%3CclipPath%20id=%22b%22%3E%3Cpath%20d=%22M29.487%2029.964h121.035v119.954H29.487z%22/%3E%3C/clipPath%3E%3C/defs%3E%3C/svg%3E
@@ -634,60 +634,65 @@
634634
}
635635
}
636636

637-
// Define PLAY functions
637+
// Define MESSAGE functions
638638

639-
function getLastMoreOptionsBtn() {
640-
const moreOptionsBtns = document.querySelectorAll(chatgpt.selectors.btns.moreOptions),
641-
lastMoreOptionsBtns = moreOptionsBtns[moreOptionsBtns.length -1]
642-
return !lastMoreOptionsBtns?.closest('article') ? null : lastMoreOptionsBtns
643-
}
639+
const message = {
644640

645-
function getTalkingMsgDiv() {
646-
return getLastMoreOptionsBtn()?.closest('article')?.querySelector(chatgpt.selectors.replyDiv)
647-
}
641+
get: {
642+
lastMoreOptionsBtn() {
643+
const moreOptionsBtns = document.querySelectorAll(chatgpt.selectors.btns.moreOptions),
644+
lastMoreOptionsBtns = moreOptionsBtns[moreOptionsBtns.length -1]
645+
return !lastMoreOptionsBtns?.closest('article') ? null : lastMoreOptionsBtns
646+
},
648647

649-
function openLastMoreOptionsMenu() {
650-
const lastMoreOptionsBtn = getLastMoreOptionsBtn() ; if (!lastMoreOptionsBtn) return
651-
lastMoreOptionsBtn.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }))
652-
}
648+
talkingDiv() {
649+
return this.lastMoreOptionsBtn()?.closest('article')?.querySelector(chatgpt.selectors.replyDiv)
650+
}
651+
},
653652

654-
function outlineText() {
655-
if (!config.outlineText) return
656-
const talkingMsgDiv = getTalkingMsgDiv() ; if (!talkingMsgDiv) return
657-
const durations = { iniDelay: 500 /* ms */, pulse: 5 /* s */ }
658-
const outlineColor = chatgpt.isDarkMode() ? 'rgba(223, 225, 227, 0.7)' : 'rgba(0, 157, 255, 0.7)'
659-
setTimeout(() => talkingMsgDiv.style.cssText = `
660-
box-shadow: 0 0 0 0 ${outlineColor} ;
661-
animation: pulse-glow ${durations.pulse}s ease-in-out ; border-radius: 8px`,
662-
durations.iniDelay)
663-
;(window.pulseGlowKeyframes ||= dom.create.style()).textContent = `
664-
@keyframes pulse-glow {
665-
0% { box-shadow: 0 0 0 0 ${outlineColor} }
666-
50% { box-shadow: 0 0 0 8px rgba(59, 130, 246, 0) }
667-
100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0) }
668-
}`
669-
if (!window.pulseGlowKeyframes.isConnected) document.head.append(window.pulseGlowKeyframes)
670-
}
653+
openLastMoreOptionsMenu() {
654+
this.get.lastMoreOptionsBtn()
655+
?.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }))
656+
},
671657

672-
function playLastMsg() {
673-
openLastMoreOptionsMenu()
674-
dom.get.loadedElem(chatgpt.selectors.btns.play, { timeout: 1000 }).then(playBtn => {
675-
playBtn.click() ; document.querySelector('textarea')?.click() ; outlineText() })
676-
}
658+
outline() {
659+
if (!config.outlineText) return
660+
const talkingMsgDiv = this.get.talkingDiv() ; if (!talkingMsgDiv) return
661+
const durations = { iniDelay: 500 /* ms */, pulse: 5 /* s */ }
662+
const outlineColor = chatgpt.isDarkMode() ? 'rgba(223, 225, 227, 0.7)' : 'rgba(0, 157, 255, 0.7)'
663+
setTimeout(() => talkingMsgDiv.style.cssText = `
664+
box-shadow: 0 0 0 0 ${outlineColor} ;
665+
animation: pulse-glow ${durations.pulse}s ease-in-out ; border-radius: 8px`,
666+
durations.iniDelay)
667+
;(this.pulseGlowKeyframes ||= dom.create.style()).textContent = `
668+
@keyframes pulse-glow {
669+
0% { box-shadow: 0 0 0 0 ${outlineColor} }
670+
50% { box-shadow: 0 0 0 8px rgba(59, 130, 246, 0) }
671+
100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0) }
672+
}`
673+
if (!this.pulseGlowKeyframes.isConnected) document.head.append(this.pulseGlowKeyframes)
674+
},
677675

678-
async function stopPlayingMsg() {
679-
openLastMoreOptionsMenu()
680-
const actionBtn = await Promise.race([
681-
dom.get.loadedElem(chatgpt.selectors.btns.stop),
682-
dom.get.loadedElem(chatgpt.selectors.btns.play),
683-
new Promise(resolve => setTimeout(resolve, 1000))
684-
])
685-
if (actionBtn?.matches?.(chatgpt.selectors.btns.stop)) {
686-
actionBtn.click() // stop playing
687-
if (config.outlineText) { // rid outline
688-
const talkingMsgDiv = getTalkingMsgDiv() ; if (talkingMsgDiv) talkingMsgDiv.style.cssText = '' }
676+
playLast() {
677+
this.openLastMoreOptionsMenu()
678+
dom.get.loadedElem(chatgpt.selectors.btns.play, { timeout: 1000 }).then(playBtn => {
679+
playBtn.click() ; document.querySelector('textarea')?.click() ; this.outline() })
680+
},
681+
682+
async stopPlaying() {
683+
this.openLastMoreOptionsMenu()
684+
const actionBtn = await Promise.race([
685+
dom.get.loadedElem(chatgpt.selectors.btns.stop),
686+
dom.get.loadedElem(chatgpt.selectors.btns.play),
687+
new Promise(resolve => setTimeout(resolve, 1000))
688+
])
689+
if (actionBtn?.matches?.(chatgpt.selectors.btns.stop)) {
690+
actionBtn.click() // stop playing
691+
if (config.outlineText) { // rid outline
692+
const talkingMsgDiv = this.get.talkingDiv() ; if (talkingMsgDiv) talkingMsgDiv.style.cssText = '' }
693+
}
694+
document.querySelector('textarea')?.click()
689695
}
690-
document.querySelector('textarea')?.click()
691696
}
692697

693698
// Define UI functions
@@ -700,8 +705,8 @@
700705
function syncConfigToUI(options) {
701706
if (/autoTalkDisabled|toggleHidden/.test(options.updatedKey)) {
702707
toggles.sidebar.update.state()
703-
if (options.updatedKey == 'autoTalkDisabled') {
704-
if (config.autoTalkDisabled) stopPlayingMsg() ; else playLastMsg() }
708+
if (options.updatedKey == 'autoTalkDisabled')
709+
message[config.autoTalkDisabled ? 'stopPlaying' : 'playLast']()
705710
}
706711
toolbarMenu.refresh() // prefixes/suffixes
707712
}
@@ -885,12 +890,12 @@
885890
|| document.querySelector(chatgpt.selectors.btns.login) // no Play btn
886891
) return
887892
if (locationPath != location.pathname) { // nav'd to diff page, play last msg if convo page
888-
locationPath = location.pathname ; if (/\/c\/[\w-]+$/.test(locationPath)) playLastMsg()
893+
locationPath = location.pathname ; if (/\/c\/[\w-]+$/.test(locationPath)) message.playLast()
889894
} else for (const { addedNodes } of mutations) for (const node of addedNodes) { // look for options btns created
890895
if (node.tagName != 'DIV'
891896
|| !node.querySelector(chatgpt.selectors.btns.moreOptions)?.closest('article') // ignore convo options
892897
) continue
893-
playLastMsg()
898+
message.playLast()
894899
}
895900
}).observe(document.body, { childList: true, subtree: true })
896901

0 commit comments

Comments
 (0)