Skip to content

Commit cec7bf0

Browse files
committed
Condensed elem replacement routines
1 parent a10d15d commit cec7bf0

File tree

13 files changed

+79
-111
lines changed

13 files changed

+79
-111
lines changed

amazongpt/greasemonkey/amazongpt.user.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @description Adds the magic of AI to Amazon shopping
44
// @author KudoAI
55
// @namespace https://kudoai.com
6-
// @version 2025.3.3
6+
// @version 2025.3.3.1
77
// @license MIT
88
// @icon https://amazongpt.kudoai.com/assets/images/icons/amazongpt/black-gold-teal/icon48.png?v=0fddfc7
99
// @icon64 https://amazongpt.kudoai.com/assets/images/icons/amazongpt/black-gold-teal/icon64.png?v=0fddfc7
@@ -613,8 +613,7 @@
613613

614614
// Replace link buttons w/ clones that don't dismiss modal
615615
if (/support|discuss|extensions/i.test(btn.textContent)) {
616-
const btnClone = btn.cloneNode(true)
617-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
616+
btn.replaceWith(btn = btn.cloneNode(true))
618617
btn.onclick = () => modals.safeWinOpen(app.urls[
619618
btn.textContent.includes(app.msgs.btnLabel_getSupport) ? 'support'
620619
: btn.textContent.includes(app.msgs.btnLabel_discuss) ? 'discuss' : 'relatedExtensions' ])
@@ -805,10 +804,9 @@
805804
schemeModal.querySelector('.modal-buttons')
806805
.style.cssText = 'justify-content: center ; margin-top: -2px !important'
807806

808-
// Re-format each button
809-
const buttons = schemeModal.querySelectorAll('button'),
810-
schemeEmojis = { 'light': '☀️', 'dark': '🌘', 'auto': '🌗'}
811-
for (const btn of buttons) {
807+
// Hack buttons
808+
const schemeEmojis = { 'light': '☀️', 'dark': '🌘', 'auto': '🌗'}
809+
schemeModal.querySelectorAll('button').forEach(btn => {
812810
const btnScheme = btn.textContent.toLowerCase()
813811

814812
// Emphasize active scheme
@@ -824,19 +822,19 @@
824822
else btn.style.display = 'none' // hide Dismiss button
825823

826824
// Clone button to replace listener to not dismiss modal on click
827-
const newBtn = btn.cloneNode(true) ; btn.parentNode.replaceChild(newBtn, btn)
828-
newBtn.onclick = () => {
825+
btn.replaceWith(btn = btn.cloneNode(true))
826+
btn.onclick = () => {
829827
const newScheme = btnScheme == 'auto' ? getScheme() : btnScheme
830828
settings.save('scheme', btnScheme == 'auto' ? false : newScheme)
831829
schemeModal.querySelectorAll('button').forEach(btn =>
832830
btn.classList = '') // clear prev emphasized active scheme
833-
newBtn.classList = 'primary-modal-btn' // emphasize newly active scheme
834-
newBtn.style.cssText = 'pointer-events: none' // disable hover fx to show emphasis
835-
setTimeout(() => { newBtn.style.pointerEvents = 'auto' }, // re-enable hover fx
831+
btn.classList = 'primary-modal-btn' // emphasize newly active scheme
832+
btn.style.cssText = 'pointer-events: none' // disable hover fx to show emphasis
833+
setTimeout(() => { btn.style.pointerEvents = 'auto' }, // re-enable hover fx
836834
100) // ...after 100ms to flicker emphasis
837835
update.scheme(newScheme) ; schemeNotify(btnScheme)
838836
}
839-
}
837+
})
840838

841839
log.debug('Success! Scheme modal shown')
842840

@@ -2992,10 +2990,10 @@
29922990
: copyBtn.parentNode.parentNode ) // code container
29932991
const textToCopy = textContainer.textContent.replace(/^>> /, '').trim()
29942992
copyBtn.style.cursor = 'default' // remove finger
2995-
copyBtn.replaceChild(copySVGs.copied, copySVGs.copy) // change to Copied icon
2993+
copySVGs.copy.replaceWith(copySVGs.copied) // change to Copied icon
29962994
toggle.tooltip(event) // update tooltip
29972995
setTimeout(() => { // restore icon/cursor/tooltip after a bit
2998-
copyBtn.replaceChild(copySVGs.copy, copySVGs.copied)
2996+
copySVGs.copied.replaceWith(copySVGs.copy)
29992997
copyBtn.style.cursor = 'pointer' ; copyBtn.dispatchEvent(new Event('mouseenter'))
30002998
}, 1355)
30012999
navigator.clipboard.writeText(textToCopy) // copy text to clipboard

autoclear-chatgpt-history/greasemonkey/autoclear-chatgpt-history.user.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
// @description:zu Ziba itshala lokucabanga okuzoshintshwa ngokuzenzakalelayo uma ukubuka chatgpt.com
226226
// @author Adam Lui
227227
// @namespace https://github.com/adamlui
228-
// @version 2025.3.3.1
228+
// @version 2025.3.3.2
229229
// @license MIT
230230
// @icon https://assets.autoclearchatgpt.com/images/icons/openai/black/icon48.png?v=f461c06
231231
// @icon64 https://assets.autoclearchatgpt.com/images/icons/openai/black/icon64.png?v=f461c06
@@ -548,8 +548,7 @@
548548

549549
// Replace link buttons w/ clones that don't dismiss modal
550550
if (/support|discuss|extensions/i.test(btn.textContent)) {
551-
const btnClone = btn.cloneNode(true)
552-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
551+
btn.replaceWith(btn = btn.cloneNode(true))
553552
btn.onclick = () => modals.safeWinOpen(app.urls[
554553
btn.textContent.includes(app.msgs.btnLabel_getSupport) ? 'support'
555554
: btn.textContent.includes(app.msgs.btnLabel_discuss) ? 'discuss' : 'relatedExtensions'
@@ -615,8 +614,7 @@
615614

616615
// Replace link buttons w/ clones that don't dismiss modal
617616
if (!/dismiss/i.test(btn.textContent)) {
618-
const btnClone = btn.cloneNode(true)
619-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
617+
btn.replaceWith(btn = btn.cloneNode(true))
620618
btn.onclick = () => modals.safeWinOpen(app.urls.donate[
621619
btn.textContent == 'Cash App' ? 'cashApp'
622620
: btn.textContent == 'Github Sponsors' ? 'gitHub' : 'payPal'

bravegpt/greasemonkey/bravegpt.user.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
// @description:zu Yengeza izimpendulo ze-AI ku-Brave Search (inikwa amandla yi-GPT-4o!)
149149
// @author KudoAI
150150
// @namespace https://kudoai.com
151-
// @version 2025.3.3
151+
// @version 2025.3.3.1
152152
// @license MIT
153153
// @icon https://assets.bravegpt.com/images/icons/bravegpt/icon48.png?v=df624b0
154154
// @icon64 https://assets.bravegpt.com/images/icons/bravegpt/icon64.png?v=df624b0
@@ -796,8 +796,7 @@
796796

797797
// Replace link buttons w/ clones that don't dismiss modal
798798
if (/support|extensions/i.test(btn.textContent)) {
799-
const btnClone = btn.cloneNode(true)
800-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
799+
btn.replaceWith(btn = btn.cloneNode(true))
801800
btn.onclick = () => modals.safeWinOpen(app.urls[
802801
btn.textContent.includes(app.msgs.btnLabel_getSupport) ? 'support' : 'relatedExtensions' ])
803802
}
@@ -854,8 +853,7 @@
854853
btn.style.marginTop = btn.style.marginBottom = '5px' // v-pad btns
855854

856855
// Replace buttons w/ clones that don't dismiss modal
857-
const btnClone = btn.cloneNode(true)
858-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
856+
btn.replaceWith(btn = btn.cloneNode(true))
859857
btn.onclick = () => modals.safeWinOpen(
860858
btn.textContent == 'Product Hunt' ? app.urls.review.productHunt
861859
: btn.textContent == 'Alternativeto' ? app.urls.review.alternativeTo
@@ -1031,10 +1029,9 @@
10311029
schemeModal.querySelector('.modal-buttons')
10321030
.style.cssText = 'justify-content: center ; margin: 18px 0 14px !important'
10331031

1034-
// Re-format each button
1035-
const buttons = schemeModal.querySelectorAll('button'),
1036-
schemeEmojis = { 'light': '☀️', 'dark': '🌘', 'auto': '🌗'}
1037-
for (const btn of buttons) {
1032+
// Hack buttons
1033+
const schemeEmojis = { 'light': '☀️', 'dark': '🌘', 'auto': '🌗'}
1034+
schemeModal.querySelectorAll('button').forEach(btn => {
10381035
const btnScheme = btn.textContent.toLowerCase()
10391036

10401037
// Emphasize active scheme
@@ -1050,19 +1047,19 @@
10501047
else btn.style.display = 'none' // hide Dismiss button
10511048

10521049
// Clone button to replace listener to not dismiss modal on click
1053-
const newBtn = btn.cloneNode(true) ; btn.parentNode.replaceChild(newBtn, btn)
1054-
newBtn.onclick = () => {
1050+
btn.replaceWith(btn = btn.cloneNode(true))
1051+
btn.onclick = () => {
10551052
const newScheme = btnScheme == 'auto' ? getScheme() : btnScheme
10561053
settings.save('scheme', btnScheme == 'auto' ? false : newScheme)
10571054
schemeModal.querySelectorAll('button').forEach(btn =>
10581055
btn.classList = '') // clear prev emphasized active scheme
1059-
newBtn.classList = 'primary-modal-btn' // emphasize newly active scheme
1060-
newBtn.style.cssText = 'pointer-events: none' // disable hover fx to show emphasis
1061-
setTimeout(() => { newBtn.style.pointerEvents = 'auto' }, // re-enable hover fx
1056+
btn.classList = 'primary-modal-btn' // emphasize newly active scheme
1057+
btn.style.cssText = 'pointer-events: none' // disable hover fx to show emphasis
1058+
setTimeout(() => { btn.style.pointerEvents = 'auto' }, // re-enable hover fx
10621059
100) // ...after 100ms to flicker emphasis
10631060
update.scheme(newScheme) ; schemeNotify(btnScheme)
10641061
}
1065-
}
1062+
})
10661063

10671064
log.debug('Success! Scheme modal shown')
10681065

@@ -3938,10 +3935,10 @@
39383935
: copyBtn.parentNode.parentNode ) // code container
39393936
const textToCopy = textContainer.textContent.replace(/^>> /, '').trim()
39403937
copyBtn.style.cursor = 'default' // remove finger
3941-
copyBtn.replaceChild(copySVGs.copied, copySVGs.copy) // change to Copied icon
3938+
copySVGs.copy.replaceWith(copySVGs.copied) // change to Copied icon
39423939
toggle.tooltip(event) // update tooltip
39433940
setTimeout(() => { // restore icon/cursor/tooltip after a bit
3944-
copyBtn.replaceChild(copySVGs.copy, copySVGs.copied)
3941+
copySVGs.copied.replaceWith(copySVGs.copy)
39453942
copyBtn.style.cursor = 'pointer' ; copyBtn.dispatchEvent(new Event('mouseenter'))
39463943
}, 1355)
39473944
navigator.clipboard.writeText(textToCopy) // copy text to clipboard

chatgpt-auto-continue/chromium/extension/components/modals.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ window.modals = {
5858

5959
// Replace link buttons w/ clones that don't dismiss modal
6060
if (/support|rate|discuss|extensions/i.test(btn.textContent)) {
61-
const btnClone = btn.cloneNode(true)
62-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
61+
btn.replaceWith(btn = btn.cloneNode(true))
6362
btn.onclick = () => this.safeWinOpen(
6463
btn.textContent.includes(this.getMsg('btnLabel_getSupport')) ? this.imports.app.urls.support
6564
: btn.textContent.includes(this.getMsg('btnLabel_rateUs')) ? this.imports.app.urls.review[
@@ -131,8 +130,7 @@ window.modals = {
131130

132131
// Replace link buttons w/ clones that don't dismiss modal
133132
if (!/dismiss/i.test(btn.textContent)) {
134-
const btnClone = btn.cloneNode(true)
135-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
133+
btn.replaceWith(btn = btn.cloneNode(true))
136134
btn.onclick = () => this.safeWinOpen(this.imports.app.urls.donate[
137135
btn.textContent == 'Cash App' ? 'cashApp'
138136
: btn.textContent == 'Github Sponsors' ? 'gitHub' : 'payPal'

chatgpt-auto-continue/firefox/extension/components/modals.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ window.modals = {
5858

5959
// Replace link buttons w/ clones that don't dismiss modal
6060
if (/support|rate|discuss|extensions/i.test(btn.textContent)) {
61-
const btnClone = btn.cloneNode(true)
62-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
61+
btn.replaceWith(btn = btn.cloneNode(true))
6362
btn.onclick = () => this.safeWinOpen(
6463
btn.textContent.includes(this.getMsg('btnLabel_getSupport')) ? this.imports.app.urls.support
6564
: btn.textContent.includes(this.getMsg('btnLabel_rateUs')) ? this.imports.app.urls.review[
@@ -131,8 +130,7 @@ window.modals = {
131130

132131
// Replace link buttons w/ clones that don't dismiss modal
133132
if (!/dismiss/i.test(btn.textContent)) {
134-
const btnClone = btn.cloneNode(true)
135-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
133+
btn.replaceWith(btn = btn.cloneNode(true))
136134
btn.onclick = () => this.safeWinOpen(this.imports.app.urls.donate[
137135
btn.textContent == 'Cash App' ? 'cashApp'
138136
: btn.textContent == 'Github Sponsors' ? 'gitHub' : 'payPal'

chatgpt-auto-refresh/greasemonkey/chatgpt-auto-refresh.user.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
// @description:zu *NGOKUPHEPHA* susa ukusetha kabusha ingxoxo yemizuzu eyi-10 + amaphutha enethiwekhi ahlala njalo + Ukuhlolwa kwe-Cloudflare ku-ChatGPT.
221221
// @author Adam Lui
222222
// @namespace https://github.com/adamlui
223-
// @version 2025.3.3.1
223+
// @version 2025.3.3.2
224224
// @license MIT
225225
// @icon https://assets.chatgptautorefresh.com/images/icons/openai/black/icon48.png?v=f11a0a8
226226
// @icon64 https://assets.chatgptautorefresh.com/images/icons/openai/black/icon64.png?v=f11a0a8
@@ -581,8 +581,7 @@
581581

582582
// Replace link buttons w/ clones that don't dismiss modal
583583
if (/support|discuss|extensions/i.test(btn.textContent)) {
584-
const btnClone = btn.cloneNode(true)
585-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
584+
btn.replaceWith(btn = btn.cloneNode(true))
586585
btn.onclick = () => modals.safeWinOpen(app.urls[
587586
btn.textContent.includes(app.msgs.btnLabel_getSupport) ? 'support'
588587
: btn.textContent.includes(app.msgs.btnLabel_discuss) ? 'discuss' : 'relatedExtensions'
@@ -648,8 +647,7 @@
648647

649648
// Replace link buttons w/ clones that don't dismiss modal
650649
if (!/dismiss/i.test(btn.textContent)) {
651-
const btnClone = btn.cloneNode(true)
652-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
650+
btn.replaceWith(btn = btn.cloneNode(true))
653651
btn.onclick = () => modals.safeWinOpen(app.urls.donate[
654652
btn.textContent == 'Cash App' ? 'cashApp'
655653
: btn.textContent == 'Github Sponsors' ? 'gitHub' : 'payPal'

chatgpt-auto-talk/greasemonkey/chatgpt-auto-talk.user.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
// @description:zu Dlala izimpendulo ze-ChatGPT ngokuzenzakalela
226226
// @author Adam Lui
227227
// @namespace https://github.com/adamlui
228-
// @version 2025.3.3.1
228+
// @version 2025.3.3.2
229229
// @license MIT
230230
// @icon https://assets.chatgptautotalk.com/images/icons/openai/black/icon48.png?v=9f1ed3c
231231
// @icon64 https://assets.chatgptautotalk.com/images/icons/openai/black/icon64.png?v=9f1ed3c
@@ -527,8 +527,7 @@
527527

528528
// Replace link buttons w/ clones that don't dismiss modal
529529
if (/support|discuss|extensions/i.test(btn.textContent)) {
530-
const btnClone = btn.cloneNode(true)
531-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
530+
btn.replaceWith(btn = btn.cloneNode(true))
532531
btn.onclick = () => modals.safeWinOpen(app.urls[
533532
btn.textContent.includes(app.msgs.btnLabel_getSupport) ? 'support'
534533
: btn.textContent.includes(app.msgs.btnLabel_discuss) ? 'discuss' : 'relatedExtensions'
@@ -594,8 +593,7 @@
594593

595594
// Replace link buttons w/ clones that don't dismiss modal
596595
if (!/dismiss/i.test(btn.textContent)) {
597-
const btnClone = btn.cloneNode(true)
598-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
596+
btn.replaceWith(btn = btn.cloneNode(true))
599597
btn.onclick = () => modals.safeWinOpen(app.urls.donate[
600598
btn.textContent == 'Cash App' ? 'cashApp'
601599
: btn.textContent == 'Github Sponsors' ? 'gitHub' : 'payPal'

chatgpt-infinity/chromium/extension/components/modals.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ window.modals = {
5959

6060
// Replace link buttons w/ clones that don't dismiss modal
6161
if (/support|extensions/i.test(btn.textContent)) {
62-
const btnClone = btn.cloneNode(true)
63-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
62+
btn.replaceWith(btn = btn.cloneNode(true))
6463
btn.onclick = () => this.safeWinOpen(this.imports.app.urls[
6564
btn.textContent.includes(this.getMsg('btnLabel_getSupport')) ? 'support' : 'relatedExtensions' ])
6665
}
@@ -124,8 +123,7 @@ window.modals = {
124123

125124
// Replace link buttons w/ clones that don't dismiss modal
126125
if (!/dismiss/i.test(btn.textContent)) {
127-
const btnClone = btn.cloneNode(true)
128-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
126+
btn.replaceWith(btn = btn.cloneNode(true))
129127
btn.onclick = () => this.safeWinOpen(this.imports.app.urls.donate[
130128
btn.textContent == 'Cash App' ? 'cashApp'
131129
: btn.textContent == 'Github Sponsors' ? 'gitHub' : 'payPal'
@@ -163,8 +161,7 @@ window.modals = {
163161
if (idx == 0) btn.style.display = 'none' // hide Dismiss button
164162

165163
// Replace buttons w/ clones that don't dismiss modal
166-
const btnClone = btn.cloneNode(true)
167-
btn.parentNode.replaceChild(btnClone, btn) ; btn = btnClone
164+
btn.replaceWith(btn = btn.cloneNode(true))
168165
btn.onclick = () => this.safeWinOpen(this.imports.app.urls.review[
169166
btn.textContent == 'Alternativeto' ? 'alternativeTo'
170167
: btn.textContent == 'Chrome Web Store' ? 'chromeWebStore'

0 commit comments

Comments
 (0)