From c2403c7af927ae7fea46e8710e77f3486242f381 Mon Sep 17 00:00:00 2001 From: "adamlui@protonmail.com" Date: Sat, 17 Aug 2024 04:50:52 -0700 Subject: [PATCH] Refactored `show.reply()` to use `forEach` loop for dynamic button creation --- amazongpt/greasemonkey/amazongpt.user.js | 30 ++++++---- bravegpt/greasemonkey/bravegpt.user.js | 62 ++++++++++---------- duckduckgpt/greasemonkey/duckduckgpt.user.js | 62 ++++++++++---------- googlegpt/greasemonkey/googlegpt.user.js | 62 ++++++++++---------- 4 files changed, 113 insertions(+), 103 deletions(-) diff --git a/amazongpt/greasemonkey/amazongpt.user.js b/amazongpt/greasemonkey/amazongpt.user.js index 27a9b819a0..957b1e6fca 100644 --- a/amazongpt/greasemonkey/amazongpt.user.js +++ b/amazongpt/greasemonkey/amazongpt.user.js @@ -3,7 +3,7 @@ // @description Adds the magic of AI to Amazon shopping // @author KudoAI // @namespace https://kudoai.com -// @version 2024.8.17 +// @version 2024.8.17.1 // @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 @@ -2301,20 +2301,30 @@ chatTextarea.placeholder = `${ msgs.tooltip_sendReply || 'Send reply' }...` continueChatDiv.append(chatTextarea) replyForm.append(continueChatDiv) ; replySection.append(replyForm) - appDiv.append(replySection) + appDiv.append(replySection); - // Create/append send button - const sendBtn = document.createElement('button'), - sendSVG = icons.arrowUp.create() - sendBtn.id = 'send-btn' ; sendBtn.className = 'chatbar-btn' - sendBtn.style.right = `${ isFirefox ? 8 : 7 }px` - sendBtn.append(sendSVG) ; continueChatDiv.append(sendBtn) + // Create/append chatbar buttons + ['send'].forEach(btnType => { + + // Create/ID/classify/pos button + const btnElem = document.createElement('button') + btnElem.id = `${btnType}-btn` ; btnElem.className = 'chatbar-btn' + btnElem.style.right = `${ isFirefox ? 8 : 7 }px` + + // Append icon + btnElem.append(icons.arrowUp.create()) + + // Add listeners + if (!isMobile) // add hover listener for tooltips + btnElem.onmouseover = btnElem.onmouseout = toggle.tooltip + + // Append button + continueChatDiv.append(btnElem) + }) // Add reply section listeners replyForm.onkeydown = handleEnter ; replyForm.onsubmit = handleSubmit chatTextarea.oninput = autosizeChatbar - if (!isMobile) // add hover listeners for tooltips - sendBtn.onmouseover = sendBtn.onmouseout = toggle.tooltip // Scroll to top on mobile if user interacted if (isMobile && show.reply.userInteracted) { diff --git a/bravegpt/greasemonkey/bravegpt.user.js b/bravegpt/greasemonkey/bravegpt.user.js index 181081b079..16b3e18507 100644 --- a/bravegpt/greasemonkey/bravegpt.user.js +++ b/bravegpt/greasemonkey/bravegpt.user.js @@ -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.17 +// @version 2024.8.17.1 // @license MIT // @icon https://media.bravegpt.com/images/icons/bravegpt/icon48.png?0a9e287 // @icon64 https://media.bravegpt.com/images/icons/bravegpt/icon64.png?0a9e287 @@ -2970,21 +2970,36 @@ setTimeout(async () => { : msgs.tooltip_sendReply || 'Send reply' ) + '...' continueChatDiv.append(chatTextarea) replyForm.append(continueChatDiv) ; replySection.append(replyForm) - appDiv.insertBefore(replySection, appDiv.querySelector('footer')) - - // Create/append send button - const sendBtn = document.createElement('button'), - sendSVG = icons.arrowUp.create() - sendBtn.id = 'send-btn' ; sendBtn.className = 'chatbar-btn' - sendBtn.style.right = '12px' - sendBtn.append(sendSVG) ; continueChatDiv.append(sendBtn) - - // Create/append shuffle button - const shuffleBtn = document.createElement('div') - shuffleBtn.id = 'shuffle-btn' ; shuffleBtn.className = 'chatbar-btn' - shuffleBtn.style.right = '20px' - const shuffleSVG = icons.arrowsTwistedRight.create() - shuffleBtn.append(shuffleSVG) ; continueChatDiv.append(shuffleBtn) + appDiv.insertBefore(replySection, appDiv.querySelector('footer')); + + // Create/append chatbar buttons + ['send', 'shuffle'].forEach(btnType => { + + // Create/ID/classify/pos button + const btnElem = document.createElement(btnType === 'send' ? 'button' : 'div') + btnElem.id = `${btnType}-btn` ; btnElem.className = 'chatbar-btn' + btnElem.style.right = `${ btnType == 'send' ? 12 : 20 }px` + + // Append icon + btnElem.append(icons[btnType == 'send' ? 'arrowUp' : 'arrowsTwistedRight'].create()) + + // Add listeners + if (!isMobile) // add hover listener for tooltips + btnElem.onmouseover = btnElem.onmouseout = toggle.tooltip + if (btnType == 'shuffle') btnElem.onclick = () => { + const randQAprompt = 'Generate a single random question on any topic then answer it.' + + `${ !config.proxyAPIenabled ? 'Don\'t talk about Canberra, Tokyo, blue whales, photosynthesis,' + + ' deserts, mindfulness meditation, the Fibonacci sequence,' + + ' Jupiter, the Great Wall of China, Sheakespeare or da Vinci.' : '' }` + + 'Try to give an answer that is 25-50 words.' + + 'Do not type anything but the question and answer. Reply in markdown.' + chatTextarea.value = augmentQuery(randQAprompt) + chatTextarea.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true })) + } + + // Append button + continueChatDiv.append(btnElem) + }) // Init/fill/append footer const appFooter = appDiv.querySelector('footer') || document.createElement('footer') @@ -2994,21 +3009,6 @@ setTimeout(async () => { // Add reply section listeners replyForm.onkeydown = handleEnter ; replyForm.onsubmit = handleSubmit chatTextarea.oninput = autosizeChatbar - shuffleBtn.onclick = () => { - const randQAprompt = 'Generate a single random question on any topic then answer it.' - + `${ !config.proxyAPIenabled ? 'Don\'t talk about Canberra, Tokyo, blue whales, photosynthesis,' - + ' deserts, mindfulness meditation, the Fibonacci sequence,' - + ' Jupiter, the Great Wall of China, Sheakespeare or da Vinci.' : '' }` - + 'Try to give an answer that is 25-50 words.' - + 'Do not type anything but the question and answer. Reply in markdown.' - chatTextarea.value = augmentQuery(randQAprompt) - chatTextarea.dispatchEvent(new KeyboardEvent('keydown', { - key: 'Enter', bubbles: true, cancelable: true })) - } - if (!isMobile) { // add hover listeners for tooltips - sendBtn.onmouseover = sendBtn.onmouseout = toggle.tooltip - shuffleBtn.onmouseover = shuffleBtn.onmouseout = toggle.tooltip - } // Scroll to top on mobile if user interacted if (isMobile && show.reply.userInteracted) { diff --git a/duckduckgpt/greasemonkey/duckduckgpt.user.js b/duckduckgpt/greasemonkey/duckduckgpt.user.js index 07e0380c20..7e61f948b3 100644 --- a/duckduckgpt/greasemonkey/duckduckgpt.user.js +++ b/duckduckgpt/greasemonkey/duckduckgpt.user.js @@ -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.17 +// @version 2024.8.17.1 // @license MIT // @icon https://media.ddgpt.com/images/icons/duckduckgpt/icon48.png?af89302 // @icon64 https://media.ddgpt.com/images/icons/duckduckgpt/icon64.png?af89302 @@ -2876,40 +2876,40 @@ continueChatDiv.append(chatTextarea) replyForm.append(continueChatDiv) ; replySection.append(replyForm) appFooter.style.right = '-72px' // counteract right-offset bug from chatbar padding - appDiv.append(replySection) - - // Create/append send button - const sendBtn = document.createElement('button'), - sendSVG = icons.arrowUp.create() - sendBtn.id = 'send-btn' ; sendBtn.className = 'chatbar-btn' - sendBtn.style.right = `${ isFirefox ? 8 : 7 }px` - sendBtn.append(sendSVG) ; continueChatDiv.append(sendBtn) - - // Create/append shuffle button - const shuffleBtn = document.createElement('div') - shuffleBtn.id = 'shuffle-btn' ; shuffleBtn.className = 'chatbar-btn' - shuffleBtn.style.right = `${ isFirefox ? 11.5 : 9.5 }px` - const shuffleSVG = icons.arrowsTwistedRight.create() - shuffleBtn.append(shuffleSVG) ; continueChatDiv.append(shuffleBtn) + appDiv.append(replySection); + + // Create/append chatbar buttons + ['send', 'shuffle'].forEach(btnType => { + + // Create/ID/classify/pos button + const btnElem = document.createElement(btnType === 'send' ? 'button' : 'div') + btnElem.id = `${btnType}-btn` ; btnElem.className = 'chatbar-btn' + btnElem.style.right = `${ btnType == 'send' ? ( isFirefox ? 8 : 7 ) : ( isFirefox ? 11.5 : 9.5 )}px` + + // Append icon + btnElem.append(icons[btnType == 'send' ? 'arrowUp' : 'arrowsTwistedRight'].create()) + + // Add listeners + if (!isMobile) // add hover listener for tooltips + btnElem.onmouseover = btnElem.onmouseout = toggle.tooltip + if (btnType == 'shuffle') btnElem.onclick = () => { + const randQAprompt = 'Generate a single random question on any topic then answer it.' + + `${ !config.proxyAPIenabled ? 'Don\'t talk about Canberra, Tokyo, blue whales, photosynthesis,' + + ' deserts, mindfulness meditation, the Fibonacci sequence,' + + ' Jupiter, the Great Wall of China, Sheakespeare or da Vinci.' : '' }` + + 'Try to give an answer that is 25-50 words.' + + 'Do not type anything but the question and answer. Reply in markdown.' + chatTextarea.value = augmentQuery(randQAprompt) + chatTextarea.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true })) + } + + // Append button + continueChatDiv.append(btnElem) + }) // Add reply section listeners replyForm.onkeydown = handleEnter ; replyForm.onsubmit = handleSubmit chatTextarea.oninput = autosizeChatbar - shuffleBtn.onclick = () => { - const randQAprompt = 'Generate a single random question on any topic then answer it.' - + `${ !config.proxyAPIenabled ? 'Don\'t talk about Canberra, Tokyo, blue whales, photosynthesis,' - + ' deserts, mindfulness meditation, the Fibonacci sequence,' - + ' Jupiter, the Great Wall of China, Sheakespeare or da Vinci.' : '' }` - + 'Try to give an answer that is 25-50 words.' - + 'Do not type anything but the question and answer. Reply in markdown.' - chatTextarea.value = augmentQuery(randQAprompt) - chatTextarea.dispatchEvent(new KeyboardEvent('keydown', { - key: 'Enter', bubbles: true, cancelable: true })) - } - if (!isMobile) { // add hover listeners for tooltips - sendBtn.onmouseover = sendBtn.onmouseout = toggle.tooltip - shuffleBtn.onmouseover = shuffleBtn.onmouseout = toggle.tooltip - } // Scroll to top on mobile if user interacted if (isMobile && show.reply.userInteracted) { diff --git a/googlegpt/greasemonkey/googlegpt.user.js b/googlegpt/greasemonkey/googlegpt.user.js index 66f1323539..40ab47da54 100644 --- a/googlegpt/greasemonkey/googlegpt.user.js +++ b/googlegpt/greasemonkey/googlegpt.user.js @@ -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.8.17 +// @version 2024.8.17.1 // @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 @@ -3202,21 +3202,36 @@ : msgs.tooltip_sendReply || 'Send reply' ) + '...' continueChatDiv.append(chatTextarea) replyForm.append(continueChatDiv) ; replySection.append(replyForm) - appDiv.insertBefore(replySection, appDiv.querySelector('footer')) - - // Create/append send button - const sendBtn = document.createElement('button'), - sendSVG = icons.arrowUp.create() - sendBtn.id = 'send-btn' ; sendBtn.className = 'chatbar-btn' - sendBtn.style.right = `${ isFirefox ? 7 : 5 }px` - sendBtn.append(sendSVG) ; continueChatDiv.append(sendBtn) - - // Create/append shuffle button - const shuffleBtn = document.createElement('div') - shuffleBtn.id = 'shuffle-btn' ; shuffleBtn.className = 'chatbar-btn' - shuffleBtn.style.right = `${ isFirefox ? 9 : 7 }px` - const shuffleSVG = icons.arrowsTwistedRight.create() - shuffleBtn.append(shuffleSVG) ; continueChatDiv.append(shuffleBtn) + appDiv.insertBefore(replySection, appDiv.querySelector('footer')); + + // Create/append chatbar buttons + ['send', 'shuffle'].forEach(btnType => { + + // Create/ID/classify/pos button + const btnElem = document.createElement(btnType === 'send' ? 'button' : 'div') + btnElem.id = `${btnType}-btn` ; btnElem.className = 'chatbar-btn' + btnElem.style.right = `${ btnType == 'send' ? ( isFirefox ? 7 : 5 ) : ( isFirefox ? 9 : 7 )}px` + + // Append icon + btnElem.append(icons[btnType == 'send' ? 'arrowUp' : 'arrowsTwistedRight'].create()) + + // Add listeners + if (!isMobile) // add hover listener for tooltips + btnElem.onmouseover = btnElem.onmouseout = toggle.tooltip + if (btnType == 'shuffle') btnElem.onclick = () => { + const randQAprompt = 'Generate a single random question on any topic then answer it.' + + `${ !config.proxyAPIenabled ? 'Don\'t talk about Canberra, Tokyo, blue whales, photosynthesis,' + + ' deserts, mindfulness meditation, the Fibonacci sequence,' + + ' Jupiter, the Great Wall of China, Sheakespeare or da Vinci.' : '' }` + + 'Try to give an answer that is 25-50 words.' + + 'Do not type anything but the question and answer. Reply in markdown.' + chatTextarea.value = augmentQuery(randQAprompt) + chatTextarea.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true })) + } + + // Append button + continueChatDiv.append(btnElem) + }) // Init/fill/append footer const appFooter = appDiv.querySelector('footer') || document.createElement('footer') @@ -3226,21 +3241,6 @@ // Add reply section listeners replyForm.onkeydown = handleEnter ; replyForm.onsubmit = handleSubmit chatTextarea.oninput = autosizeChatbar - shuffleBtn.onclick = () => { - const randQAprompt = 'Generate a single random question on any topic then answer it.' - + `${ !config.proxyAPIenabled ? 'Don\'t talk about Canberra, Tokyo, blue whales, photosynthesis,' - + ' deserts, mindfulness meditation, the Fibonacci sequence,' - + ' Jupiter, the Great Wall of China, Sheakespeare or da Vinci.' : '' }` - + 'Try to give an answer that is 25-50 words.' - + 'Do not type anything but the question and answer. Reply in markdown.' - chatTextarea.value = augmentQuery(randQAprompt) - chatTextarea.dispatchEvent(new KeyboardEvent('keydown', { - key: 'Enter', bubbles: true, cancelable: true })) - } - if (!isMobile) { // add hover listeners for tooltips - sendBtn.onmouseover = sendBtn.onmouseout = toggle.tooltip - shuffleBtn.onmouseover = shuffleBtn.onmouseout = toggle.tooltip - } // Scroll to top on mobile if user interacted if (isMobile && show.reply.userInteracted) {