Skip to content

Commit

Permalink
Added modal stack tracking ↞ [auto-sync from https://github.com/adaml…
Browse files Browse the repository at this point in the history
  • Loading branch information
kudo-sync-bot committed Dec 3, 2024
1 parent eb0b71d commit 5b75252
Showing 1 changed file with 150 additions and 132 deletions.
282 changes: 150 additions & 132 deletions chatgpt/chatgpt-auto-continue/chatgpt-auto-continue.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
// @description:zu ⚡ Terus menghasilkan imibuzo eminingi ye-ChatGPT ngokwesizulu
// @author Adam Lui
// @namespace https://github.com/adamlui
// @version 2024.12.2.1
// @version 2024.12.3
// @license MIT
// @match *://chatgpt.com/*
// @match *://chat.openai.com/*
Expand Down Expand Up @@ -360,8 +360,8 @@

// Show "Disabled (extension installed)"
if (env.extensionInstalled)
GM_registerMenuCommand(`${menu.state.symbols[0]} ${app.msgs.menuLabel_disabled}`, modals.about.show,
tooltipsSupported ? { title: ' ' } : undefined)
GM_registerMenuCommand(`${menu.state.symbols[0]} ${app.msgs.menuLabel_disabled}`,
() => modals.open('about'), tooltipsSupported ? { title: ' ' } : undefined )

// ...or add settings toggles
else Object.keys(settings.controls).forEach(key => {
Expand All @@ -378,14 +378,14 @@

// Add About entry
const aboutLabel = `💡 ${app.msgs.menuLabel_about} ${app.msgs.appName}`
menu.ids.push(GM_registerMenuCommand(aboutLabel, modals.about.show,
tooltipsSupported ? { title: ' ' } : undefined))
menu.ids.push(GM_registerMenuCommand(aboutLabel, () => modals.open('about'),
tooltipsSupported ? { title: ' ' } : undefined ))

// Add Donate entry
if (!env.extensionInstalled) {
const donateLabel = `💖 ${app.msgs.menuLabel_donate}`
menu.ids.push(GM_registerMenuCommand(donateLabel, modals.donate.show,
tooltipsSupported ? { title: ' ' } : undefined))
menu.ids.push(GM_registerMenuCommand(donateLabel, () => modals.open('donate'),
tooltipsSupported ? { title: ' ' } : undefined ))
}
},

Expand Down Expand Up @@ -440,7 +440,7 @@
`${app.msgs.appName} (v${currentVer}) ${app.msgs.alert_isUpToDate}!`, // msg
'', '', updateAlertWidth
)
modals.about.show()
modals.open('about')
}})}

// Define FEEDBACK functions
Expand All @@ -467,20 +467,39 @@
}

function siteAlert(title = '', msg = '', btns = '', checkbox = '', width = '') {
const alertID = chatgpt.alert(title, msg, btns, checkbox, width ),
alert = document.getElementById(alertID).firstChild
modals.setup(alert) // add class + starry BG + drag handlers
return alert
const alertID = chatgpt.alert(title, msg, btns, checkbox, width)
return document.getElementById(alertID).firstChild
}

// Define MODAL functions

const modals = {
stack: [], // of types of undismissed modals

setup(modal) {
open(modalType) {
this.stack.unshift(modalType) // add to stack
const modal = modals[modalType]() // show modal
modal.classList.add('chatgpt-auto-continue-modal')
modal.onmousedown = modals.dragHandlers.mousedown
fillStarryBG(modal) // add stars
fillStarryBG(modal) // fill BG w/ rising stars
this.observeRemoval(modal, modalType) // to maintain stack for proper nav
},

observeRemoval(modal, modalType) { // to maintain stack for proper nav
const modalBG = modal.parentNode
new MutationObserver(([mutation], obs) => {
mutation.removedNodes.forEach(removedNode => { if (removedNode == modalBG) {
if (modals.stack[0] == modalType) { // new modal not launched, implement nav back logic
modals.stack.shift() // remove this modal type from stack
const prevModalType = modals.stack[0]
if (prevModalType) { // open it
modals.stack.shift() // remove type from stack since re-added on open
modals.open(prevModalType)
}
}
obs.disconnect()
}})
}).observe(modalBG.parentNode, { childList: true, subtree: true })
},

dragHandlers: {
Expand Down Expand Up @@ -512,130 +531,129 @@
}
},

about: {
show() {

// Init styles
const headingStyle = 'font-size: 1.15rem',
pStyle = 'position: relative ; left: 3px',
pBrStyle = 'position: relative ; left: 4px ',
aStyle = 'color: ' + ( chatgpt.isDarkMode() ? '#c67afb' : '#8325c4' ) // purple

// Show modal
const aboutModal = siteAlert(
`${app.symbol} ${app.msgs.appName}`, // title
`<span style="${headingStyle}"><b>🏷️ <i>${app.msgs.about_version}</i></b>: </span>`
+ `<span style="${pStyle}">${app.version}</span>\n`
+ `<span style="${headingStyle}"><b>⚡ <i>${app.msgs.about_poweredBy}</i></b>: </span>`
+ `<span style="${pStyle}">`
+ `<a style="${aStyle}" href="${app.urls.chatgptJS}" target="_blank" rel="noopener">`
+ `chatgpt.js</a> v${app.chatgptJSver}</span>\n`
+ `<span style="${headingStyle}"><b>📜 <i>${app.msgs.about_sourceCode}</i></b>:</span>\n`
+ `<span style="${pBrStyle}"><a href="${app.urls.gitHub}" target="_blank" rel="nopener">`
+ app.urls.gitHub + '</a></span>',
[ // buttons
function checkForUpdates() { updateCheck() },
function getSupport(){},
function rateUs(){},
function moreAIextensions(){}
], '', 546 // set width
)
about() {

// Init styles
const headingStyle = 'font-size: 1.15rem',
pStyle = 'position: relative ; left: 3px',
pBrStyle = 'position: relative ; left: 4px ',
aStyle = 'color: ' + ( chatgpt.isDarkMode() ? '#c67afb' : '#8325c4' ) // purple

// Show modal
const aboutModal = siteAlert(
`${app.symbol} ${app.msgs.appName}`, // title
`<span style="${headingStyle}"><b>🏷️ <i>${app.msgs.about_version}</i></b>: </span>`
+ `<span style="${pStyle}">${app.version}</span>\n`
+ `<span style="${headingStyle}"><b>⚡ <i>${app.msgs.about_poweredBy}</i></b>: </span>`
+ `<span style="${pStyle}">`
+ `<a style="${aStyle}" href="${app.urls.chatgptJS}" target="_blank" rel="noopener">`
+ `chatgpt.js</a> v${app.chatgptJSver}</span>\n`
+ `<span style="${headingStyle}"><b>📜 <i>${app.msgs.about_sourceCode}</i></b>:</span>\n`
+ `<span style="${pBrStyle}"><a href="${app.urls.gitHub}" target="_blank" rel="nopener">`
+ app.urls.gitHub + '</a></span>',
[ // buttons
function checkForUpdates() { updateCheck() },
function getSupport(){},
function rateUs(){},
function moreAIextensions(){}
], '', 546 // set width
)

// Format text
aboutModal.querySelector('h2').style.cssText = 'text-align: center ; font-size: 37px ; padding: 9px'
aboutModal.querySelector('p').style.cssText = 'text-align: center'

// Hack buttons
aboutModal.querySelectorAll('button').forEach(btn => {
btn.style.cssText = 'cursor: pointer !important' // since tweaks won't load on script auto-disable

// Replace link buttons w/ clones that don't dismissAlert()
if (/support|rate|extensions/i.test(btn.textContent)) {
const btnClone = btn.cloneNode(true)
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
btn.onclick = () => modals.safeWinOpen(
btn.textContent.includes(app.msgs.btnLabel_getSupport) ? app.urls.support
: btn.textContent.includes(app.msgs.btnLabel_rateUs) ? app.urls.review.greasyFork
: app.urls.relatedExtensions
)
}

// Format text
aboutModal.querySelector('h2').style.cssText = 'text-align: center ; font-size: 37px ; padding: 9px'
aboutModal.querySelector('p').style.cssText = 'text-align: center'

// Hack buttons
aboutModal.querySelectorAll('button').forEach(btn => {
btn.style.cssText = 'cursor: pointer !important' // since tweaks won't load on script auto-disable

// Replace link buttons w/ clones that don't dismissAlert()
if (/support|rate|extensions/i.test(btn.textContent)) {
const btnClone = btn.cloneNode(true)
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
btn.onclick = () => modals.safeWinOpen(
btn.textContent.includes(app.msgs.btnLabel_getSupport) ? app.urls.support
: btn.textContent.includes(app.msgs.btnLabel_rateUs) ? app.urls.review.greasyFork
: app.urls.relatedExtensions
)
}
// Prepend emoji + localize labels
if (/updates/i.test(btn.textContent))
btn.textContent = `🚀 ${app.msgs.btnLabel_updateCheck}`
else if (/support/i.test(btn.textContent))
btn.textContent = `🧠 ${app.msgs.btnLabel_getSupport}`
else if (/rate/i.test(btn.textContent))
btn.textContent = `⭐ ${app.msgs.btnLabel_rateUs}`
else if (/extensions/i.test(btn.textContent))
btn.textContent = `🤖 ${app.msgs.btnLabel_moreAIextensions}`

// Hide Dismiss button
else btn.style.display = 'none' // hide Dismiss button
})

// Prepend emoji + localize labels
if (/updates/i.test(btn.textContent))
btn.textContent = `🚀 ${app.msgs.btnLabel_updateCheck}`
else if (/support/i.test(btn.textContent))
btn.textContent = `🧠 ${app.msgs.btnLabel_getSupport}`
else if (/rate/i.test(btn.textContent))
btn.textContent = `⭐ ${app.msgs.btnLabel_rateUs}`
else if (/extensions/i.test(btn.textContent))
btn.textContent = `🤖 ${app.msgs.btnLabel_moreAIextensions}`

// Hide Dismiss button
else btn.style.display = 'none' // hide Dismiss button
})
}
return aboutModal
},

donate: {
longCOVIDwikiLink: 'https://en.wikipedia.org/wiki/Long_COVID',

show() {

// Show alert
const donateModal = siteAlert(
`💖 ${app.msgs.alert_showYourSupport}`, // title
`<p>${app.msgs.appName} ${app.msgs.alert_isOSS}.</p>`
+ `<p>${app.msgs.alert_despiteAffliction} `
+ `<a target="_blank" rel="noopener" href="${modals.donate.longCOVIDwikiLink}">`
+ `${app.msgs.alert_longCOVID}</a> `
+ `${app.msgs.alert_since2020}, ${app.msgs.alert_byDonatingResults}.</p>`
+ `<p>${app.msgs.alert_yourContrib}, <b>${app.msgs.alert_noMatterSize}</b>, `
+ `${app.msgs.alert_directlySupports}.</p>`
+ `<p>${app.msgs.alert_tyForSupport}!</p>`
+ '<img src="https://cdn.jsdelivr.net/gh/adamlui/adamlui/images/siggie/'
+ `${ chatgpt.isDarkMode() ? 'white' : 'black' }.png" `
+ 'style="height: 54px ; margin: 5px 0 -2px 5px"></img>'
+ `<p>—<b><a target="_blank" rel="noopener" href="${app.author.url}">`
+ `${app.msgs.appAuthor}</a></b>, ${app.msgs.alert_author}</p>`,
[ // buttons
function paypal(){},
function githubSponsors(){},
function cashApp(){},
function rateUs() { modals.safeWinOpen(app.urls.review.greasyFork) }
], '', 478 // set width
)
donate() {

// Show modal
const donateModal = siteAlert(
`💖 ${app.msgs.alert_showYourSupport}`, // title
`<p>${app.msgs.appName} ${app.msgs.alert_isOSS}.</p>`
+ `<p>${app.msgs.alert_despiteAffliction} `
+ '<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Long_COVID">'
+ `${app.msgs.alert_longCOVID}</a> `
+ `${app.msgs.alert_since2020}, ${app.msgs.alert_byDonatingResults}.</p>`
+ `<p>${app.msgs.alert_yourContrib}, <b>${app.msgs.alert_noMatterSize}</b>, `
+ `${app.msgs.alert_directlySupports}.</p>`
+ `<p>${app.msgs.alert_tyForSupport}!</p>`
+ '<img src="https://cdn.jsdelivr.net/gh/adamlui/adamlui/images/siggie/'
+ `${ chatgpt.isDarkMode() ? 'white' : 'black' }.png" `
+ 'style="height: 54px ; margin: 5px 0 -2px 5px"></img>'
+ `<p>—<b><a target="_blank" rel="noopener" href="${app.author.url}">`
+ `${app.msgs.appAuthor}</a></b>, ${app.msgs.alert_author}</p>`,
[ // buttons
function paypal(){},
function githubSponsors(){},
function cashApp(){},
function rateUs() { modals.safeWinOpen(app.urls.review.greasyFork) }
], '', 478 // set width
)

// Format text
donateModal.querySelectorAll('p').forEach(p => // v-pad text, shrink line height
p.style.cssText = 'padding: 8px 0 ; line-height: 20px')

// Hack buttons
const btns = donateModal.querySelectorAll('button')
btns.forEach((btn, idx) => {

// Replace link buttons w/ clones that don't dismissAlert()
if (!/dismiss|rate/i.test(btn.textContent)) {
const btnClone = btn.cloneNode(true)
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
btn.onclick = () => modals.safeWinOpen(
btn.textContent == 'Cash App' ? app.urls.donate.cashApp
: btn.textContent == 'Github Sponsors' ? app.urls.donate.gitHub
: btn.textContent == 'Paypal' ? app.urls.donate.payPal
: app.urls.review.greasyFork
)
}

// Format text
donateModal.querySelectorAll('p').forEach(p => // v-pad text, shrink line height
p.style.cssText = 'padding: 8px 0 ; line-height: 20px')

// Hack buttons
const btns = donateModal.querySelectorAll('button')
btns.forEach((btn, idx) => {

// Replace link buttons w/ clones that don't dismissAlert()
if (!/dismiss|rate/i.test(btn.textContent)) {
const btnClone = btn.cloneNode(true)
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
btn.onclick = () => modals.safeWinOpen(app.urls.donate[
btn.textContent == 'Cash App' ? 'cashApp'
: btn.textContent == 'GitHub' ? 'gitHub'
: 'payPal'
])
}
// Format buttons
if (idx == 0) btn.style.display = 'none' // hide Dismiss button
else {
btn.style.cssText = 'padding: 8px 6px !important ; margin-top: -14px ;'
+ ' width: 107px ; line-height: 14px'
if (idx == btns.length -1) // de-emphasize right-most button
btn.classList.remove('primary-modal-btn')
else if (/rate/i.test(btn.textContent)) // localize 'Rate Us' label
btn.textContent = app.msgs.btnLabel_rateUs
}
})

// Format buttons
if (idx == 0) btn.style.display = 'none' // hide Dismiss button
else {
btn.style.cssText = 'padding: 8px 6px !important ; margin-top: -14px ;'
+ ' width: 107px ; line-height: 14px'
if (idx == btns.length -1) // de-emphasize right-most button
btn.classList.remove('primary-modal-btn')
else if (/rate/i.test(btn.textContent)) // localize 'Rate Us' label
btn.textContent = app.msgs.btnLabel_rateUs
}
})
}
return donateModal
},

safeWinOpen(url) { open(url, '_blank', 'noopener') } // to prevent backdoor vulnerabilities
Expand Down

0 comments on commit 5b75252

Please sign in to comment.