Skip to content

Commit

Permalink
Added sync Settings toggle to toggle.proxy() + .streaming()
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlui committed Jun 27, 2024
1 parent 5487017 commit 8a1f926
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
16 changes: 11 additions & 5 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.6.27.10
// @version 2024.6.27.12
// @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 @@ -1448,7 +1448,10 @@ setTimeout(async () => {
saveSetting('proxyAPIenabled', !config.proxyAPIenabled)
notify(( msgs.menuLabel_proxyAPImode || 'Proxy API Mode' ) + ' ' + menuState.word[+config.proxyAPIenabled])
refreshMenu()
if (appDiv.querySelector('#bravegpt-alert')) location.reload() // re-send query if user alerted
const proxyToggle = document.querySelector('[id*="proxy"][id*="menu-entry"] input')
if (proxyToggle && proxyToggle.checked != config.proxyAPIenabled) // update visual state of Settings modal
modals.settings.toggle.switch(proxyToggle)
if (appDiv.querySelector('#ddgpt-alert')) location.reload() // re-send query if user alerted
},

relatedQueries() {
Expand Down Expand Up @@ -1490,15 +1493,17 @@ setTimeout(async () => {
+ ` <a target="_blank" rel="noopener" href="${scriptCatLink}">ScriptCat</a>.` // suggest SC
+ ` (${ msgs.alert_userscriptMgrNoStream || 'Your userscript manager does not support returning stream responses' }.)`
)
if (streamingToggle) modals.settings.toggle.switch(streamingToggle) // reverse toggle visually
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
siteAlert(`${settingsProps.streamingDisabled.label} ${ msgs.alert_unavailable || 'unavailable' }`,
`${settingsProps.streamingDisabled.label} ${ msgs.alert_isUnsupportedIn || 'is unsupported in' } `
+ `${ isChrome ? 'Chrome' : isEdge ? 'Edge' : 'Brave' } ${ msgs.alert_whenUsing || 'when using' } Tampermonkey. `
+ `${ msgs.alert_pleaseUse || 'Please use' } <a target="_blank" rel="noopener" href="${scriptCatLink}">ScriptCat</a> `
+ `${ msgs.alert_instead || 'instead' }.`
)
if (streamingToggle) modals.settings.toggle.switch(streamingToggle) // reverse toggle visually
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 @@ -1509,7 +1514,8 @@ setTimeout(async () => {
const alertID = siteAlert(`${ msgs.mode_streaming || 'Streaming Mode' } ${ msgs.alert_unavailable || 'unavailable' }`, msg),
alert = document.getElementById(alertID)
alert.querySelector('[href="#"]').onclick = () => { alert.querySelector('.modal-close-btn').click() ; toggle.proxyMode() }
if (streamingToggle) modals.settings.toggle.switch(streamingToggle) // reverse toggle visually
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
14 changes: 10 additions & 4 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.6.27.8
// @version 2024.6.27.9
// @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 @@ -1378,6 +1378,9 @@
saveSetting('proxyAPIenabled', !config.proxyAPIenabled)
notify(( msgs.menuLabel_proxyAPImode || 'Proxy API Mode' ) + ' ' + menuState.word[+config.proxyAPIenabled])
refreshMenu()
const proxyToggle = document.querySelector('[id*="proxy"][id*="menu-entry"] input')
if (proxyToggle && proxyToggle.checked != config.proxyAPIenabled) // update visual state of Settings toggle
modals.settings.toggle.switch(proxyToggle)
if (appDiv.querySelector('#ddgpt-alert')) location.reload() // re-send query if user alerted
},

Expand Down Expand Up @@ -1423,15 +1426,17 @@
+ ` <a target="_blank" rel="noopener" href="${scriptCatLink}">ScriptCat</a>.` // suggest SC
+ ` (${ msgs.alert_userscriptMgrNoStream || 'Your userscript manager does not support returning stream responses' }.)`
)
if (streamingToggle) modals.settings.toggle.switch(streamingToggle) // reverse toggle visually
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
siteAlert(`${settingsProps.streamingDisabled.label} ${ msgs.alert_unavailable || 'unavailable' }`,
`${settingsProps.streamingDisabled.label} ${ msgs.alert_isUnsupportedIn || 'is unsupported in' } `
+ `${ isChrome ? 'Chrome' : isEdge ? 'Edge' : 'Brave' } ${ msgs.alert_whenUsing || 'when using' } Tampermonkey. `
+ `${ msgs.alert_pleaseUse || 'Please use' } <a target="_blank" rel="noopener" href="${scriptCatLink}">ScriptCat</a> `
+ `${ msgs.alert_instead || 'instead' }.`
)
if (streamingToggle) modals.settings.toggle.switch(streamingToggle) // reverse toggle visually
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 @@ -1442,7 +1447,8 @@
const alertID = siteAlert(`${ msgs.mode_streaming || 'Streaming Mode' } ${ msgs.alert_unavailable || 'unavailable' }`, msg),
alert = document.getElementById(alertID)
alert.querySelector('[href="#"]').onclick = () => { alert.querySelector('.modal-close-btn').click() ; toggle.proxyMode() }
if (streamingToggle) modals.settings.toggle.switch(streamingToggle) // reverse toggle visually
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
16 changes: 11 additions & 5 deletions googlegpt/greasemonkey/googlegpt.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
// @description:zu Yengeza izimpendulo ze-AI ku-Google Search (inikwa amandla yi-Google Gemma + GPT-4o!)
// @author KudoAI
// @namespace https://kudoai.com
// @version 2024.6.27.9
// @version 2024.6.27.10
// @license MIT
// @icon https://media.googlegpt.io/images/icons/googlegpt/black/icon48.png?8652a6e
// @icon64 https://media.googlegpt.io/images/icons/googlegpt/black/icon64.png?8652a6e
Expand Down Expand Up @@ -1693,7 +1693,10 @@
saveSetting('proxyAPIenabled', !config.proxyAPIenabled)
notify(( msgs.menuLabel_proxyAPImode || 'Proxy API Mode' ) + ' ' + menuState.word[+config.proxyAPIenabled])
refreshMenu()
if (appDiv.querySelector('#googlegpt-alert')) location.reload() // re-send query if user alerted
const proxyToggle = document.querySelector('[id*="proxy"][id*="menu-entry"] input')
if (proxyToggle && proxyToggle.checked != config.proxyAPIenabled) // update visual state of Settings modal
modals.settings.toggle.switch(proxyToggle)
if (appDiv.querySelector('#ddgpt-alert')) location.reload() // re-send query if user alerted
},

relatedQueries() {
Expand Down Expand Up @@ -1738,15 +1741,17 @@
+ ` <a target="_blank" rel="noopener" href="${scriptCatLink}">ScriptCat</a>.` // suggest SC
+ ` (${ msgs.alert_userscriptMgrNoStream || 'Your userscript manager does not support returning stream responses' }.)`
)
if (streamingToggle) modals.settings.toggle.switch(streamingToggle) // reverse toggle visually
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
siteAlert(`${settingsProps.streamingDisabled.label} ${ msgs.alert_unavailable || 'unavailable' }`,
`${settingsProps.streamingDisabled.label} ${ msgs.alert_isUnsupportedIn || 'is unsupported in' } `
+ `${ isChrome ? 'Chrome' : isEdge ? 'Edge' : 'Brave' } ${ msgs.alert_whenUsing || 'when using' } Tampermonkey. `
+ `${ msgs.alert_pleaseUse || 'Please use' } <a target="_blank" rel="noopener" href="${scriptCatLink}">ScriptCat</a> `
+ `${ msgs.alert_instead || 'instead' }.`
)
if (streamingToggle) modals.settings.toggle.switch(streamingToggle) // reverse toggle visually
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 @@ -1757,7 +1762,8 @@
const alertID = siteAlert(`${ msgs.mode_streaming || 'Streaming Mode' } ${ msgs.alert_unavailable || 'unavailable' }`, msg),
alert = document.getElementById(alertID)
alert.querySelector('[href="#"]').onclick = () => { alert.querySelector('.modal-close-btn').click() ; toggle.proxyMode() }
if (streamingToggle) modals.settings.toggle.switch(streamingToggle) // reverse toggle visually
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

0 comments on commit 8a1f926

Please sign in to comment.