Skip to content

Commit

Permalink
Renamed menu obj to toolbarMenu ↞ [auto-sync from https://github.…
Browse files Browse the repository at this point in the history
  • Loading branch information
kudo-sync-bot committed Feb 12, 2025
1 parent 7ac7441 commit bf4a389
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions chatgpt/chatgpt-infinity/chatgpt-infinity.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
// @description:zh-TW 從無所不知的 ChatGPT 生成無窮無盡的答案 (用任何語言!)
// @author Adam Lui
// @namespace https://github.com/adamlui
// @version 2025.2.12.1
// @version 2025.2.12.2
// @license MIT
// @icon https://assets.chatgptinfinity.com/images/icons/infinity-symbol/circled/with-robot/icon48.png?v=69e434b
// @icon64 https://assets.chatgptinfinity.com/images/icons/infinity-symbol/circled/with-robot/icon64.png?v=69e434b
Expand Down Expand Up @@ -385,22 +385,22 @@

// Define MENU functions

const menu = {
const toolbarMenu = {
ids: [], state: {
symbols: ['❌', '✔️'], separator: env.scriptManager.name == 'Tampermonkey' ? ' — ' : ': ',
words: [app.msgs.state_off.toUpperCase(), app.msgs.state_on.toUpperCase()]
},

refresh() {
if (typeof GM_unregisterMenuCommand == 'undefined') return
for (const id of menu.ids) { GM_unregisterMenuCommand(id) } menu.register()
for (const id of this.ids) { GM_unregisterMenuCommand(id) } this.register()
},

register() {

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

// ...or add settings entries
Expand All @@ -410,16 +410,16 @@
// Add setting entries
Object.keys(settings.controls).forEach(key => {
const settingIsEnabled = config[key] ^ /disabled|hidden/i.test(key)
const menuLabel = `${ settings.controls[key].symbol || menu.state.symbols[+settingIsEnabled] } `
const menuLabel = `${ settings.controls[key].symbol || this.state.symbols[+settingIsEnabled] } `
+ settings.controls[key].label
+ ( settings.controls[key].type == 'toggle' ? menu.state.separator
+ menu.state.words[+settingIsEnabled]
+ ( settings.controls[key].type == 'toggle' ? this.state.separator
+ this.state.words[+settingIsEnabled]
: `— ${settings.controls[key].status}` )
menu.ids.push(GM_registerMenuCommand(menuLabel, () => {
this.ids.push(GM_registerMenuCommand(menuLabel, () => {
if (settings.controls[key].type == 'toggle') {
settings.save(key, !config[key])
notify(`${settings.controls[key].label}: ${
menu.state.words[+(/disabled|hidden/i.test(key) ^ config[key])]}`)
this.state.words[+(/disabled|hidden/i.test(key) ^ config[key])]}`)
} else if (key == 'replyLanguage') {
while (true) {
let replyLang = prompt(
Expand Down Expand Up @@ -476,7 +476,7 @@
// Add About/Donate entries
['about', 'donate'].forEach(entryType => {
if (entryType === 'donate' && env.extensionInstalled) return
menu.ids.push(GM_registerMenuCommand(
this.ids.push(GM_registerMenuCommand(
`${ entryType == 'about' ? '💡' : '💖' }`
+ ` ${app.msgs[`menuLabel_${entryType}`]} ${ entryType == 'about' ? app.msgs.appName : '' }`,
() => modals.open(entryType), env.scriptManager.supportsTooltips ? { title: ' ' } : undefined
Expand Down Expand Up @@ -519,7 +519,7 @@
function notify(msg, pos = '', notifDuration = '', shadow = '') {

// Strip state word to append colored one later
const foundState = menu.state.words.find(word => msg.includes(word))
const foundState = toolbarMenu.state.words.find(word => msg.includes(word))
if (foundState) msg = msg.replace(foundState, '')

// Show notification
Expand All @@ -539,7 +539,8 @@
}
}
const styledStateSpan = dom.create.elem('span')
styledStateSpan.style.cssText = stateStyles[foundState == menu.state.words[0] ? 'off' : 'on'][env.ui.scheme]
styledStateSpan.style.cssText = stateStyles[
foundState == toolbarMenu.state.words[0] ? 'off' : 'on'][env.ui.scheme]
styledStateSpan.append(foundState) ; notif.append(styledStateSpan)
}
}
Expand All @@ -564,7 +565,7 @@
else if (settings.controls[options?.updatedKey].type == 'prompt' && config.infinityMode)
infinity.restart({ target: options?.updatedKey == 'replyInterval' ? 'self' : 'new' })
if (/infinityMode|toggleHidden/.test(options?.updatedKey)) toggles.sidebar.update.state()
menu.refresh() // prefixes/suffixes
toolbarMenu.refresh() // prefixes/suffixes
}

// Define INFINITY MODE functions
Expand Down Expand Up @@ -629,7 +630,7 @@
})()
}), new Promise(resolve => setTimeout(() => resolve(false), 1500))])

menu.register() ; if (env.extensionInstalled) return
toolbarMenu.register() ; if (env.extensionInstalled) return

// Init BROWSER/UI props
await Promise.race([chatgpt.isLoaded(), new Promise(resolve => setTimeout(resolve, 5000))]) // initial UI loaded
Expand Down

0 comments on commit bf4a389

Please sign in to comment.