Skip to content

Commit

Permalink
Refactored show.reply() to use forEach loop for dynamic button cr…
Browse files Browse the repository at this point in the history
…eation
  • Loading branch information
adamlui committed Aug 17, 2024
1 parent 6a6ca38 commit c2403c7
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 103 deletions.
30 changes: 20 additions & 10 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.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
Expand Down Expand Up @@ -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) {
Expand Down
62 changes: 31 additions & 31 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.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
Expand Down Expand Up @@ -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')
Expand All @@ -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) {
Expand Down
62 changes: 31 additions & 31 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.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
Expand Down Expand Up @@ -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) {
Expand Down
62 changes: 31 additions & 31 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.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
Expand Down Expand Up @@ -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')
Expand All @@ -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) {
Expand Down

0 comments on commit c2403c7

Please sign in to comment.