Skip to content

Commit

Permalink
Added Streaming switch state update w/ Proxy toggle + on Settings open
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlui committed Aug 17, 2024
1 parent 248acd1 commit e998e53
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 56 deletions.
28 changes: 14 additions & 14 deletions amazongpt/greasemonkey/amazongpt.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @description Adds the magic of AI to Amazon shopping
// @author KudoAI
// @namespace https://kudoai.com
// @version 2024.8.16.7
// @version 2024.8.16.8
// @license MIT
// @icon https://amazongpt.kudoai.com/assets/images/icons/amazongpt/black-gold-teal/icon48.png?v=0fddfc7
// @icon64 https://amazongpt.kudoai.com/assets/images/icons/amazongpt/black-gold-teal/icon64.png?v=0fddfc7
Expand Down Expand Up @@ -716,7 +716,8 @@
const settingToggle = document.createElement('input'),
settingToggleAttrs = [['type', 'checkbox'], ['disabled', true]]
settingToggleAttrs.forEach(([attr, value]) => settingToggle.setAttribute(attr, value))
settingToggle.checked = config[key] ^ key.includes('Disabled')
settingToggle.checked = config[key] ^ key.includes('Disabled') // init based on config/name
&& !(key == 'streamingDisabled' && !config.proxyAPIenabled) // uncheck Streaming in OpenAI mode
settingToggle.style.display = 'none' // hide checkbox

// Create/stylize switch
Expand Down Expand Up @@ -748,7 +749,8 @@

// Add click listener
settingItem.onclick = () => {
modals.settings.toggle.switch(settingToggle) // visually switch toggle
if (!(key == 'streamingDisabled' && !config.proxyAPIenabled)) // visually switch toggle if not Streaminng in OpenAI mode
modals.settings.toggle.switch(settingToggle)

// Call specialized toggle funcs
if (key.includes('proxy')) toggle.proxyMode()
Expand Down Expand Up @@ -1686,16 +1688,20 @@
saveSetting('proxyAPIenabled', !config.proxyAPIenabled)
notify(( msgs.menuLabel_proxyAPImode || 'Proxy API Mode' ) + ' ' + menuState.word[+config.proxyAPIenabled])
refreshMenu()
if (modals.settings.get()) { // update visual state of Settings toggle
const proxyToggle = document.querySelector('[id*="proxy"][id*="menu-entry"] input')
if (proxyToggle.checked != config.proxyAPIenabled) modals.settings.toggle.switch(proxyToggle)
if (modals.settings.get()) { // update visual states of Settings toggles
const proxyToggle = document.querySelector('[id*="proxy"][id*="menu-entry"] input'),
streamingToggle = document.querySelector('[id*="streaming"][id*="menu-entry"] input')
if (proxyToggle.checked != config.proxyAPIenabled) // Proxy state out-of-sync (from using toolbar menu)
modals.settings.toggle.switch(proxyToggle)
if (streamingToggle.checked && !config.proxyAPIenabled // Streaming checked but OpenAI mode
|| !streamingToggle.checked && config.proxyAPIenabled && !config.streamingDisabled) // or Streaming unchecked but enabled in Proxy mode
modals.settings.toggle.switch(streamingToggle)
}
if (appDiv.querySelector('#amzgpt-alert')) location.reload() // re-send query if user alerted
},

streaming() {
const streamingToggle = document.querySelector('[id*="streaming"][id*="menu-entry"] input'),
scriptCatLink = isFirefox ? 'https://addons.mozilla.org/firefox/addon/scriptcat/'
const scriptCatLink = isFirefox ? 'https://addons.mozilla.org/firefox/addon/scriptcat/'
: isEdge ? 'https://microsoftedge.microsoft.com/addons/detail/scriptcat/liilgpjgabokdklappibcjfablkpcekh'
: 'https://chromewebstore.google.com/detail/scriptcat/ndcooeababalnlpkfedmmbbbgkljhpjf'
if (!/Tampermonkey|ScriptCat/.test(getUserscriptManager())) { // alert userscript manager unsupported, suggest TM/SC
Expand All @@ -1709,8 +1715,6 @@
)
const suggestAlert = document.getElementById(suggestAlertID).firstChild
modals.init(suggestAlert) // add classes/stars, disable wheel-scrolling, dim bg, glowup btns
if (streamingToggle && streamingToggle.checked == config.streamingDisabled) // revert Settings auto-toggle
modals.settings.toggle.switch(streamingToggle)
} else if (getUserscriptManager() == 'Tampermonkey' && (isChrome || isEdge || isBrave)) { // alert TM/browser unsupported, suggest SC
const suggestAlertID = siteAlert(`${settingsProps.streamingDisabled.label} ${ msgs.alert_unavailable || 'unavailable' }`,
`${settingsProps.streamingDisabled.label} ${ msgs.alert_isUnsupportedIn || 'is unsupported in' } `
Expand All @@ -1720,8 +1724,6 @@
)
const suggestAlert = document.getElementById(suggestAlertID).firstChild
modals.init(suggestAlert) // add classes/stars, disable wheel-scrolling, dim bg, glowup btns
if (streamingToggle && streamingToggle.checked == config.streamingDisabled) // revert Settings auto-toggle
modals.settings.toggle.switch(streamingToggle)
} else if (!config.proxyAPIenabled) { // alert OpenAI API unsupported, suggest Proxy Mode
let msg = `${settingsProps.streamingDisabled.label} `
+ `${ msgs.alert_isCurrentlyOnlyAvailBy || 'is currently only available by' } `
Expand All @@ -1733,8 +1735,6 @@
alert = document.getElementById(alertID).firstChild
modals.init(alert) // add classes/stars, disable wheel-scrolling, dim bg, glowup btns
alert.querySelector('[href="#"]').onclick = () => { alert.querySelector('.modal-close-btn').click() ; toggle.proxyMode() }
if (streamingToggle && streamingToggle.checked == config.streamingDisabled) // revert Settings auto-toggle
modals.settings.toggle.switch(streamingToggle)
} else { // functional toggle
saveSetting('streamingDisabled', !config.streamingDisabled)
notify(settingsProps.streamingDisabled.label + ' ' + menuState.word[+!config.streamingDisabled])
Expand Down
28 changes: 14 additions & 14 deletions bravegpt/greasemonkey/bravegpt.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
// @description:zu Yengeza izimpendulo ze-AI ku-Brave Search (inikwa amandla yi-GPT-4o!)
// @author KudoAI
// @namespace https://kudoai.com
// @version 2024.8.16.7
// @version 2024.8.16.8
// @license MIT
// @icon https://media.bravegpt.com/images/icons/bravegpt/icon48.png?0a9e287
// @icon64 https://media.bravegpt.com/images/icons/bravegpt/icon64.png?0a9e287
Expand Down Expand Up @@ -871,7 +871,8 @@ setTimeout(async () => {
const settingToggle = document.createElement('input'),
settingToggleAttrs = [['type', 'checkbox'], ['disabled', true]]
settingToggleAttrs.forEach(([attr, value]) => settingToggle.setAttribute(attr, value))
settingToggle.checked = config[key] ^ key.includes('Disabled')
settingToggle.checked = config[key] ^ key.includes('Disabled') // init based on config/name
&& !(key == 'streamingDisabled' && !config.proxyAPIenabled) // uncheck Streaming in OpenAI mode
settingToggle.style.display = 'none' // hide checkbox

// Create/stylize switch
Expand Down Expand Up @@ -903,7 +904,8 @@ setTimeout(async () => {

// Add click listener
settingItem.onclick = () => {
modals.settings.toggle.switch(settingToggle) // visually switch toggle
if (!(key == 'streamingDisabled' && !config.proxyAPIenabled)) // visually switch toggle if not Streaminng in OpenAI mode
modals.settings.toggle.switch(settingToggle)

// Call specialized toggle funcs
const manualGetMatch = /(?:suf|pre)fix/.exec(key)
Expand Down Expand Up @@ -2226,9 +2228,14 @@ setTimeout(async () => {
saveSetting('proxyAPIenabled', !config.proxyAPIenabled)
notify(( msgs.menuLabel_proxyAPImode || 'Proxy API Mode' ) + ' ' + menuState.word[+config.proxyAPIenabled])
refreshMenu()
if (modals.settings.get()) { // update visual state of Settings toggle
const proxyToggle = document.querySelector('[id*="proxy"][id*="menu-entry"] input')
if (proxyToggle.checked != config.proxyAPIenabled) modals.settings.toggle.switch(proxyToggle)
if (modals.settings.get()) { // update visual states of Settings toggles
const proxyToggle = document.querySelector('[id*="proxy"][id*="menu-entry"] input'),
streamingToggle = document.querySelector('[id*="streaming"][id*="menu-entry"] input')
if (proxyToggle.checked != config.proxyAPIenabled) // Proxy state out-of-sync (from using toolbar menu)
modals.settings.toggle.switch(proxyToggle)
if (streamingToggle.checked && !config.proxyAPIenabled // Streaming checked but OpenAI mode
|| !streamingToggle.checked && config.proxyAPIenabled && !config.streamingDisabled) // or Streaming unchecked but enabled in Proxy mode
modals.settings.toggle.switch(streamingToggle)
}
if (appDiv.querySelector('#bravegpt-alert')) location.reload() // re-send query if user alerted
},
Expand Down Expand Up @@ -2264,8 +2271,7 @@ setTimeout(async () => {
},

streaming() {
const streamingToggle = document.querySelector('[id*="streaming"][id*="menu-entry"] input'),
scriptCatLink = isFirefox ? 'https://addons.mozilla.org/firefox/addon/scriptcat/'
const scriptCatLink = isFirefox ? 'https://addons.mozilla.org/firefox/addon/scriptcat/'
: isEdge ? 'https://microsoftedge.microsoft.com/addons/detail/scriptcat/liilgpjgabokdklappibcjfablkpcekh'
: 'https://chromewebstore.google.com/detail/scriptcat/ndcooeababalnlpkfedmmbbbgkljhpjf'
if (!/Tampermonkey|ScriptCat/.test(getUserscriptManager())) { // alert userscript manager unsupported, suggest TM/SC
Expand All @@ -2279,8 +2285,6 @@ setTimeout(async () => {
)
const suggestAlert = document.getElementById(suggestAlertID).firstChild
modals.init(suggestAlert) // add classes/stars, disable wheel-scrolling, dim bg, glowup btns
if (streamingToggle && streamingToggle.checked == config.streamingDisabled) // revert Settings auto-toggle
modals.settings.toggle.switch(streamingToggle)
} else if (getUserscriptManager() == 'Tampermonkey' && (isChrome || isEdge || isBrave)) { // alert TM/browser unsupported, suggest SC
const suggestAlertID = siteAlert(`${settingsProps.streamingDisabled.label} ${ msgs.alert_unavailable || 'unavailable' }`,
`${settingsProps.streamingDisabled.label} ${ msgs.alert_isUnsupportedIn || 'is unsupported in' } `
Expand All @@ -2290,8 +2294,6 @@ setTimeout(async () => {
)
const suggestAlert = document.getElementById(suggestAlertID).firstChild
modals.init(suggestAlert) // add classes/stars, disable wheel-scrolling, dim bg, glowup btns
if (streamingToggle && streamingToggle.checked == config.streamingDisabled) // revert Settings auto-toggle
modals.settings.toggle.switch(streamingToggle)
} else if (!config.proxyAPIenabled) { // alert OpenAI API unsupported, suggest Proxy Mode
let msg = `${settingsProps.streamingDisabled.label} `
+ `${ msgs.alert_isCurrentlyOnlyAvailBy || 'is currently only available by' } `
Expand All @@ -2303,8 +2305,6 @@ setTimeout(async () => {
alert = document.getElementById(alertID).firstChild
modals.init(alert) // add classes/stars, disable wheel-scrolling, dim bg, glowup btns
alert.querySelector('[href="#"]').onclick = () => { alert.querySelector('.modal-close-btn').click() ; toggle.proxyMode() }
if (streamingToggle && streamingToggle.checked == config.streamingDisabled) // revert Settings auto-toggle
modals.settings.toggle.switch(streamingToggle)
} else { // functional toggle
saveSetting('streamingDisabled', !config.streamingDisabled)
notify(settingsProps.streamingDisabled.label + ' ' + menuState.word[+!config.streamingDisabled])
Expand Down
28 changes: 14 additions & 14 deletions duckduckgpt/greasemonkey/duckduckgpt.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
// @description:zu Yengeza izimpendulo ze-AI ku-DuckDuckGo (inikwa amandla yi-GPT-4o!)
// @author KudoAI
// @namespace https://kudoai.com
// @version 2024.8.16.6
// @version 2024.8.16.7
// @license MIT
// @icon https://media.ddgpt.com/images/icons/duckduckgpt/icon48.png?af89302
// @icon64 https://media.ddgpt.com/images/icons/duckduckgpt/icon64.png?af89302
Expand Down Expand Up @@ -877,7 +877,8 @@
const settingToggle = document.createElement('input'),
settingToggleAttrs = [['type', 'checkbox'], ['disabled', true]]
settingToggleAttrs.forEach(([attr, value]) => settingToggle.setAttribute(attr, value))
settingToggle.checked = config[key] ^ key.includes('Disabled')
settingToggle.checked = config[key] ^ key.includes('Disabled') // init based on config/name
&& !(key == 'streamingDisabled' && !config.proxyAPIenabled) // uncheck Streaming in OpenAI mode
settingToggle.style.display = 'none' // hide checkbox

// Create/stylize switch
Expand Down Expand Up @@ -909,7 +910,8 @@

// Add click listener
settingItem.onclick = () => {
modals.settings.toggle.switch(settingToggle) // visually switch toggle
if (!(key == 'streamingDisabled' && !config.proxyAPIenabled)) // visually switch toggle if not Streaminng in OpenAI mode
modals.settings.toggle.switch(settingToggle)

// Call specialized toggle funcs
const manualGetMatch = /(?:suf|pre)fix/.exec(key)
Expand Down Expand Up @@ -2128,9 +2130,14 @@
saveSetting('proxyAPIenabled', !config.proxyAPIenabled)
notify(( msgs.menuLabel_proxyAPImode || 'Proxy API Mode' ) + ' ' + menuState.word[+config.proxyAPIenabled])
refreshMenu()
if (modals.settings.get()) { // update visual state of Settings toggle
const proxyToggle = document.querySelector('[id*="proxy"][id*="menu-entry"] input')
if (proxyToggle.checked != config.proxyAPIenabled) modals.settings.toggle.switch(proxyToggle)
if (modals.settings.get()) { // update visual states of Settings toggles
const proxyToggle = document.querySelector('[id*="proxy"][id*="menu-entry"] input'),
streamingToggle = document.querySelector('[id*="streaming"][id*="menu-entry"] input')
if (proxyToggle.checked != config.proxyAPIenabled) // Proxy state out-of-sync (from using toolbar menu)
modals.settings.toggle.switch(proxyToggle)
if (streamingToggle.checked && !config.proxyAPIenabled // Streaming checked but OpenAI mode
|| !streamingToggle.checked && config.proxyAPIenabled && !config.streamingDisabled) // or Streaming unchecked but enabled in Proxy mode
modals.settings.toggle.switch(streamingToggle)
}
if (appDiv.querySelector('#ddgpt-alert')) location.reload() // re-send query if user alerted
},
Expand Down Expand Up @@ -2166,8 +2173,7 @@
},

streaming() {
const streamingToggle = document.querySelector('[id*="streaming"][id*="menu-entry"] input'),
scriptCatLink = isFirefox ? 'https://addons.mozilla.org/firefox/addon/scriptcat/'
const scriptCatLink = isFirefox ? 'https://addons.mozilla.org/firefox/addon/scriptcat/'
: isEdge ? 'https://microsoftedge.microsoft.com/addons/detail/scriptcat/liilgpjgabokdklappibcjfablkpcekh'
: 'https://chromewebstore.google.com/detail/scriptcat/ndcooeababalnlpkfedmmbbbgkljhpjf'
if (!/Tampermonkey|ScriptCat/.test(getUserscriptManager())) { // alert userscript manager unsupported, suggest TM/SC
Expand All @@ -2181,8 +2187,6 @@
)
const suggestAlert = document.getElementById(suggestAlertID).firstChild
modals.init(suggestAlert) // add classes/stars, disable wheel-scrolling, dim bg, glowup btns
if (streamingToggle && streamingToggle.checked == config.streamingDisabled) // revert Settings auto-toggle
modals.settings.toggle.switch(streamingToggle)
} else if (getUserscriptManager() == 'Tampermonkey' && (isChrome || isEdge || isBrave)) { // alert TM/browser unsupported, suggest SC
const suggestAlertID = siteAlert(`${settingsProps.streamingDisabled.label} ${ msgs.alert_unavailable || 'unavailable' }`,
`${settingsProps.streamingDisabled.label} ${ msgs.alert_isUnsupportedIn || 'is unsupported in' } `
Expand All @@ -2192,8 +2196,6 @@
)
const suggestAlert = document.getElementById(suggestAlertID).firstChild
modals.init(suggestAlert) // add classes/stars, disable wheel-scrolling, dim bg, glowup btns
if (streamingToggle && streamingToggle.checked == config.streamingDisabled) // revert Settings auto-toggle
modals.settings.toggle.switch(streamingToggle)
} else if (!config.proxyAPIenabled) { // alert OpenAI API unsupported, suggest Proxy Mode
let msg = `${settingsProps.streamingDisabled.label} `
+ `${ msgs.alert_isCurrentlyOnlyAvailBy || 'is currently only available by' } `
Expand All @@ -2205,8 +2207,6 @@
alert = document.getElementById(alertID).firstChild
modals.init(alert) // add classes/stars, disable wheel-scrolling, dim bg, glowup btns
alert.querySelector('[href="#"]').onclick = () => { alert.querySelector('.modal-close-btn').click() ; toggle.proxyMode() }
if (streamingToggle && streamingToggle.checked == config.streamingDisabled) // revert Settings auto-toggle
modals.settings.toggle.switch(streamingToggle)
} else { // functional toggle
saveSetting('streamingDisabled', !config.streamingDisabled)
notify(settingsProps.streamingDisabled.label + ' ' + menuState.word[+!config.streamingDisabled])
Expand Down
Loading

0 comments on commit e998e53

Please sign in to comment.