Skip to content

Commit

Permalink
Moved modal functions into obj for improved structure ↞ [auto-sync fr…
Browse files Browse the repository at this point in the history
…om `adamlui/userscripts`]
  • Loading branch information
adamlui authored and kudo-sync-bot committed Sep 19, 2024
1 parent cb3ecdb commit 411dede
Showing 1 changed file with 54 additions and 48 deletions.
102 changes: 54 additions & 48 deletions greasemonkey/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.9.18.1
// @version 2024.9.19
// @license MIT
// @match *://chatgpt.com/*
// @match *://chat.openai.com/*
Expand Down Expand Up @@ -396,7 +396,7 @@

// Add About entry
const amLabel = `💡 ${ msgs.menuLabel_about || 'About' } ${ msgs.appName || app.name }`
menu.ids.push(GM_registerMenuCommand(amLabel, launchAboutModal))
menu.ids.push(GM_registerMenuCommand(amLabel, modals.about.show))
},

refresh() {
Expand All @@ -405,48 +405,6 @@
}
}

function launchAboutModal() {

// Init data/styles
const chatgptJSver = (/chatgpt-([\d.]+)\.min/.exec(GM_info.script.header) || [null, ''])[1],
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 aboutModalID = siteAlert(
msgs.appName || app.name, // title
`<span style="${headingStyle}"><b>🏷️ <i>${ msgs.about_version || 'Version' }</i></b>: </span>`
+ `<span style="${pStyle}">${ GM_info.script.version }</span>\n`
+ `<span style="${headingStyle}"><b>⚡ <i>${ msgs.about_poweredBy || 'Powered by' }</i></b>: </span>`
+ `<span style="${pStyle}"><a style="${aStyle}" href="${app.urls.chatgptJS}" target="_blank" rel="noopener">`
+ 'chatgpt.js</a>' + ( chatgptJSver ? ( ' v' + chatgptJSver ) : '' ) + '</span>\n'
+ `<span style="${headingStyle}"><b>📜 <i>${ msgs.about_sourceCode || 'Source code' }</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() { safeWinOpen(app.urls.support) },
function leaveAReview() { safeWinOpen(app.urls.greasyFork + '/feedback#post-discussion') },
function moreChatGPTapps() { safeWinOpen(app.urls.relatedApps) }
], '', 478 // set width
)

// Re-format buttons to include emoji + localized label + hide Dismiss button
for (const button of document.getElementById(aboutModalID).querySelectorAll('button')) {
if (/updates/i.test(button.textContent)) button.textContent = (
'🚀 ' + ( msgs.btnLabel_updateCheck || 'Check for Updates' ))
else if (/support/i.test(button.textContent)) button.textContent = (
'🧠 ' + ( msgs.btnLabel_getSupport || 'Get Support' ))
else if (/review/i.test(button.textContent)) button.textContent = (
'⭐ ' + ( msgs.btnLabel_leaveReview || 'Leave Review' ))
else if (/apps/i.test(button.textContent)) button.textContent = (
'🤖 ' + ( msgs.btnLabel_moreApps || 'More ChatGPT Apps' ))
else button.style.display = 'none' // hide Dismiss button
}
}

function updateCheck() {

// Fetch latest meta
Expand Down Expand Up @@ -474,7 +432,7 @@
+ app.urls.update.replace(/.*\/(.*)meta\.js/, '$1user.js') + '"'
+ `> ${ msgs.link_viewChanges || 'View changes' }</a>`,
function update() { // button
safeWinOpen(app.urls.update.replace('meta.js', 'user.js') + '?t=' + Date.now())
modals.safeWinOpen(app.urls.update.replace('meta.js', 'user.js') + '?t=' + Date.now())
}, '', updateAlertWidth
)

Expand All @@ -495,11 +453,9 @@
+ ( msgs.alert_isUpToDate || 'is up-to-date' ) + '!',
'', '', updateAlertWidth
)
launchAboutModal()
modals.about.show()
}})}

function safeWinOpen(url) { window.open(url, '_blank', 'noopener') } // to prevent backdoor vulnerabilities

// Define FEEDBACK functions

function notify(msg, position = '', notifDuration = '', shadow = '') {
Expand All @@ -525,6 +481,56 @@
function siteAlert(title = '', msg = '', btns = '', checkbox = '', width = '') {
return chatgpt.alert(title, msg, btns, checkbox, width )}

// Define MODAL functions

const modals = {
about: {
show() {

// Init data/styles
const chatgptJSver = (/chatgpt-([\d.]+)\.min/.exec(GM_info.script.header) || [null, ''])[1],
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 aboutModalID = siteAlert(
msgs.appName || app.name, // title
`<span style="${headingStyle}"><b>🏷️ <i>${ msgs.about_version || 'Version' }</i></b>: </span>`
+ `<span style="${pStyle}">${ GM_info.script.version }</span>\n`
+ `<span style="${headingStyle}"><b>⚡ <i>${ msgs.about_poweredBy || 'Powered by' }</i></b>: </span>`
+ `<span style="${pStyle}"><a style="${aStyle}" href="${app.urls.chatgptJS}" target="_blank" rel="noopener">`
+ 'chatgpt.js</a>' + ( chatgptJSver ? ( ' v' + chatgptJSver ) : '' ) + '</span>\n'
+ `<span style="${headingStyle}"><b>📜 <i>${ msgs.about_sourceCode || 'Source code' }</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() { modals.safeWinOpen(app.urls.support) },
function leaveAReview() { modals.safeWinOpen(app.urls.greasyFork + '/feedback#post-discussion') },
function moreChatGPTapps() { modals.safeWinOpen(app.urls.relatedApps) }
], '', 478 // set width
)

// Re-format buttons to include emoji + localized label + hide Dismiss button
for (const button of document.getElementById(aboutModalID).querySelectorAll('button')) {
if (/updates/i.test(button.textContent)) button.textContent = (
'🚀 ' + ( msgs.btnLabel_updateCheck || 'Check for Updates' ))
else if (/support/i.test(button.textContent)) button.textContent = (
'🧠 ' + ( msgs.btnLabel_getSupport || 'Get Support' ))
else if (/review/i.test(button.textContent)) button.textContent = (
'⭐ ' + ( msgs.btnLabel_leaveReview || 'Leave Review' ))
else if (/apps/i.test(button.textContent)) button.textContent = (
'🤖 ' + ( msgs.btnLabel_moreApps || 'More ChatGPT Apps' ))
else button.style.display = 'none' // hide Dismiss button
}
}
},

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

// Define UI functions

async function insertToggle() {
Expand Down

0 comments on commit 411dede

Please sign in to comment.