Skip to content

Commit

Permalink
Added dom.js as dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlui committed Jan 27, 2025
1 parent a724796 commit 1f6be5d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 232 deletions.
4 changes: 2 additions & 2 deletions amazongpt/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default [
ecmaVersion: 'latest', sourceType: 'script',
globals: {
...globals.browser, ...globals.greasemonkey, chatgpt: 'readonly', CryptoJS: 'readonly',
cryptoUtils: 'readonly', GM_cookie: 'readonly', hljs: 'readonly', ipv4: 'readonly', marked: 'readonly',
renderMathInElement: 'readonly'
cryptoUtils: 'readonly', dom: 'readonly', GM_cookie: 'readonly', hljs: 'readonly', ipv4: 'readonly',
marked: 'readonly', renderMathInElement: 'readonly'
}
},
plugins: { 'import': importPlugin, 'js-styles': stylisticJS, regexp },
Expand Down
62 changes: 6 additions & 56 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 2025.1.26.16
// @version 2025.1.26.17
// @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 @@ -61,6 +61,7 @@
// @require https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.5.0/dist/chatgpt.min.js#sha256-+C0x4BOFQc38aZB3pvUC2THu+ZSvuCxRphGdtRLjCDg=
// @require https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js#sha256-dppVXeVTurw1ozOPNE3XqhYmDJPOosfbKQcHyQSE58w=
// @require https://assets.aiwebextensions.com/lib/crypto-utils.js/dist/crypto-utils.min.js?v=9e1e11d#sha256-bx3N1EAkmOTOFXxeyalh+IJnadXqVFHMBIPjRczmnEk=
// @require https://assets.aiwebextensions.com/lib/dom.js/dist/dom.min.js?v=a724796#sha256-oP9HSQKyQERkYfYRaQYxM3FIO9KXkgl/4tW55zjbGeE=
// @require https://cdn.jsdelivr.net/npm/generate-ip@2.4.4/dist/generate-ip.min.js#sha256-aQQKAQcMgCu8IpJp9HKs387x0uYxngO+Fb4pc5nSF4I=
// @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js#sha256-g3pvpbDHNrUrveKythkPMF2j/J7UFoHbUyFQcFe1yEY=
// @require https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.js#sha256-n0UwfFeU7SR6DQlfOmLlLvIhWmeyMnIDp/2RmVmuedE=
Expand Down Expand Up @@ -408,6 +409,9 @@
suggestOpenAI: `${app.msgs.alert_try} ${app.msgs.alert_switchingOff} ${app.msgs.mode_proxy}`
}})

// Export DEPENDENCIES to dom.js
dom.imports.import({ config, env }) // for config.bgAnimationsDisabled + env.ui.scheme in dom.fillStarryBg()

// Define MENU functions

const menu = {
Expand Down Expand Up @@ -1865,7 +1869,7 @@
Object.entries(headerElems).forEach(([key, elem]) => {
if (elem && key == 'byline' && getComputedStyle(elem).display == 'none')
elem.style.cssText += forceDisplayStyles // override hidden byline display style to measure width
widths[key] = dom.getComputedWidth(elem)
widths[key] = dom.get.computedWidth(elem)
if (elem?.style?.cssText.includes(forceDisplayStyles)) // restore display style for hidden byline
elem.style.cssText = elem.style.cssText.replace(forceDisplayStyles, '')
})
Expand Down Expand Up @@ -3024,60 +3028,6 @@
}
}

// Define DOM utilities

const dom = {

create: {
anchor(linkHref, displayContent, attrs = {}) {
const anchor = document.createElement('a'),
defaultAttrs = { href: linkHref, target: '_blank', rel: 'noopener' },
finalAttrs = { ...defaultAttrs, ...attrs }
Object.entries(finalAttrs).forEach(([attr, value]) => anchor.setAttribute(attr, value))
if (displayContent) anchor.append(displayContent)
return anchor
},

style(content) {
const style = document.createElement('style')
if (content) style.innerText = content
return style
},

svgElem(type, attrs) {
const elem = document.createElementNS('http://www.w3.org/2000/svg', type)
for (const attr in attrs) elem.setAttributeNS(null, attr, attrs[attr])
return elem
}
},

fillStarryBG(targetNode) { // requires https://assets.aiwebextensions.com/styles/rising-stars/css/<black|white>.min.css
if (targetNode.querySelector('[id*=stars]')) return
const starsDivsContainer = document.createElement('div')
starsDivsContainer.style.cssText = 'position: absolute ; top: 0 ; left: 0 ;' // hug targetNode's top-left corner
+ 'height: 100% ; width: 100% ; border-radius: 15px ; overflow: clip ;' // bound innards exactly by targetNode
+ 'z-index: -1'; // allow interactive elems to be clicked
['sm', 'med', 'lg'].forEach(starSize => {
const starsDiv = document.createElement('div')
starsDiv.id = config.bgAnimationsDisabled ? `stars-${starSize}-off`
: `${ env.ui.app.scheme == 'dark' ? 'white' : 'black' }-stars-${starSize}`
starsDivsContainer.append(starsDiv)
})
targetNode.prepend(starsDivsContainer)
},

getComputedWidth(...elems) { // including margins
let totalWidth = 0
elems.map(arg => arg instanceof NodeList ? [...arg] : arg).flat().forEach(elem => {
if (!(elem instanceof Element)) return
const elemStyle = getComputedStyle(elem) ; if (elemStyle.display == 'none') return
totalWidth += elem.getBoundingClientRect().width + parseFloat(elemStyle.marginLeft)
+ parseFloat(elemStyle.marginRight)
})
return totalWidth
}
}

// Run MAIN routine

menu.register()
Expand Down
4 changes: 2 additions & 2 deletions bravegpt/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default [
ecmaVersion: 'latest', sourceType: 'script',
globals: {
...globals.browser, ...globals.greasemonkey, chatgpt: 'readonly', CryptoJS: 'readonly',
cryptoUtils: 'readonly', GM_cookie: 'readonly', hljs: 'readonly', ipv4: 'readonly', marked: 'readonly',
renderMathInElement: 'readonly'
cryptoUtils: 'readonly', dom: 'readonly', GM_cookie: 'readonly', hljs: 'readonly', ipv4: 'readonly',
marked: 'readonly', renderMathInElement: 'readonly'
}
},
plugins: { 'import': importPlugin, 'js-styles': stylisticJS, regexp },
Expand Down
62 changes: 6 additions & 56 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 2025.1.26.16
// @version 2025.1.26.17
// @license MIT
// @icon https://assets.bravegpt.com/images/icons/bravegpt/icon48.png?v=df624b0
// @icon64 https://assets.bravegpt.com/images/icons/bravegpt/icon64.png?v=df624b0
Expand Down Expand Up @@ -183,6 +183,7 @@
// @require https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.5.0/dist/chatgpt.min.js#sha256-+C0x4BOFQc38aZB3pvUC2THu+ZSvuCxRphGdtRLjCDg=
// @require https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js#sha256-dppVXeVTurw1ozOPNE3XqhYmDJPOosfbKQcHyQSE58w=
// @require https://assets.aiwebextensions.com/lib/crypto-utils.js/dist/crypto-utils.min.js?v=9e1e11d#sha256-bx3N1EAkmOTOFXxeyalh+IJnadXqVFHMBIPjRczmnEk=
// @require https://assets.aiwebextensions.com/lib/dom.js/dist/dom.min.js?v=a724796#sha256-oP9HSQKyQERkYfYRaQYxM3FIO9KXkgl/4tW55zjbGeE=
// @require https://cdn.jsdelivr.net/npm/generate-ip@2.4.4/dist/generate-ip.min.js#sha256-aQQKAQcMgCu8IpJp9HKs387x0uYxngO+Fb4pc5nSF4I=
// @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js#sha256-g3pvpbDHNrUrveKythkPMF2j/J7UFoHbUyFQcFe1yEY=
// @require https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.js#sha256-n0UwfFeU7SR6DQlfOmLlLvIhWmeyMnIDp/2RmVmuedE=
Expand Down Expand Up @@ -580,6 +581,9 @@
suggestOpenAI: `${app.msgs.alert_try} ${app.msgs.alert_switchingOff} ${app.msgs.mode_proxy}`
}})

// Export DEPENDENCIES to dom.js
dom.imports.import({ config, env }) // for config.bgAnimationsDisabled + env.ui.scheme in dom.fillStarryBg()

// Define MENU functions

const menu = {
Expand Down Expand Up @@ -2331,7 +2335,7 @@
Object.entries(headerElems).forEach(([key, elem]) => {
if (elem && key == 'byline' && getComputedStyle(elem).display == 'none')
elem.style.cssText += forceDisplayStyles // override hidden byline display style to measure width
widths[key] = dom.getComputedWidth(elem)
widths[key] = dom.get.computedWidth(elem)
if (elem?.style?.cssText.includes(forceDisplayStyles)) // restore display style for hidden byline
elem.style.cssText = elem.style.cssText.replace(forceDisplayStyles, '')
})
Expand Down Expand Up @@ -3911,60 +3915,6 @@
}
}

// Define DOM utilities

const dom = {

create: {
anchor(linkHref, displayContent, attrs = {}) {
const anchor = document.createElement('a'),
defaultAttrs = { href: linkHref, target: '_blank', rel: 'noopener' },
finalAttrs = { ...defaultAttrs, ...attrs }
Object.entries(finalAttrs).forEach(([attr, value]) => anchor.setAttribute(attr, value))
if (displayContent) anchor.append(displayContent)
return anchor
},

style(content) {
const style = document.createElement('style')
if (content) style.innerText = content
return style
},

svgElem(type, attrs) {
const elem = document.createElementNS('http://www.w3.org/2000/svg', type)
for (const attr in attrs) elem.setAttributeNS(null, attr, attrs[attr])
return elem
}
},

fillStarryBG(targetNode) { // requires https://assets.aiwebextensions.com/styles/rising-stars/css/<black|white>.min.css
if (targetNode.querySelector('[id*=stars]')) return
const starsDivsContainer = document.createElement('div')
starsDivsContainer.style.cssText = 'position: absolute ; top: 0 ; left: 0 ;' // hug targetNode's top-left corner
+ 'height: 100% ; width: 100% ; border-radius: 15px ; overflow: clip ;' // bound innards exactly by targetNode
+ 'z-index: -1'; // allow interactive elems to be clicked
['sm', 'med', 'lg'].forEach(starSize => {
const starsDiv = document.createElement('div')
starsDiv.id = config.bgAnimationsDisabled ? `stars-${starSize}-off`
: `${ env.ui.app.scheme == 'dark' ? 'white' : 'black' }-stars-${starSize}`
starsDivsContainer.append(starsDiv)
})
targetNode.prepend(starsDivsContainer)
},

getComputedWidth(...elems) { // including margins
let totalWidth = 0
elems.map(arg => arg instanceof NodeList ? [...arg] : arg).flat().forEach(elem => {
if (!(elem instanceof Element)) return
const elemStyle = getComputedStyle(elem) ; if (elemStyle.display == 'none') return
totalWidth += elem.getBoundingClientRect().width + parseFloat(elemStyle.marginLeft)
+ parseFloat(elemStyle.marginRight)
})
return totalWidth
}
}

// Run MAIN routine

menu.register()
Expand Down
4 changes: 2 additions & 2 deletions duckduckgpt/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default [
ecmaVersion: 'latest', sourceType: 'script',
globals: {
...globals.browser, ...globals.greasemonkey, chatgpt: 'readonly', CryptoJS: 'readonly',
cryptoUtils: 'readonly', GM_cookie: 'readonly', hljs: 'readonly', ipv4: 'readonly', marked: 'readonly',
renderMathInElement: 'readonly'
cryptoUtils: 'readonly', dom: 'readonly', GM_cookie: 'readonly', hljs: 'readonly', ipv4: 'readonly',
marked: 'readonly', renderMathInElement: 'readonly'
}
},
plugins: { 'import': importPlugin, 'js-styles': stylisticJS, regexp },
Expand Down
62 changes: 6 additions & 56 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 2025.1.26.17
// @version 2025.1.26.18
// @license MIT
// @icon https://assets.ddgpt.com/images/icons/duckduckgpt/icon48.png?v=06af076
// @icon64 https://assets.ddgpt.com/images/icons/duckduckgpt/icon64.png?v=06af076
Expand Down Expand Up @@ -184,6 +184,7 @@
// @require https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.5.0/dist/chatgpt.min.js#sha256-+C0x4BOFQc38aZB3pvUC2THu+ZSvuCxRphGdtRLjCDg=
// @require https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js#sha256-dppVXeVTurw1ozOPNE3XqhYmDJPOosfbKQcHyQSE58w=
// @require https://assets.aiwebextensions.com/lib/crypto-utils.js/dist/crypto-utils.min.js?v=9e1e11d#sha256-bx3N1EAkmOTOFXxeyalh+IJnadXqVFHMBIPjRczmnEk=
// @require https://assets.aiwebextensions.com/lib/dom.js/dist/dom.min.js?v=a724796#sha256-oP9HSQKyQERkYfYRaQYxM3FIO9KXkgl/4tW55zjbGeE=
// @require https://cdn.jsdelivr.net/npm/generate-ip@2.4.4/dist/generate-ip.min.js#sha256-aQQKAQcMgCu8IpJp9HKs387x0uYxngO+Fb4pc5nSF4I=
// @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js#sha256-g3pvpbDHNrUrveKythkPMF2j/J7UFoHbUyFQcFe1yEY=
// @require https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.js#sha256-n0UwfFeU7SR6DQlfOmLlLvIhWmeyMnIDp/2RmVmuedE=
Expand Down Expand Up @@ -589,6 +590,9 @@
suggestOpenAI: `${app.msgs.alert_try} ${app.msgs.alert_switchingOff} ${app.msgs.mode_proxy}`
}})

// Export DEPENDENCIES to dom.js
dom.imports.import({ config, env }) // for config.bgAnimationsDisabled + env.ui.scheme in dom.fillStarryBg()

// Define MENU functions

const menu = {
Expand Down Expand Up @@ -2328,7 +2332,7 @@
Object.entries(headerElems).forEach(([key, elem]) => {
if (elem && key == 'byline' && getComputedStyle(elem).display == 'none')
elem.style.cssText += forceDisplayStyles // override hidden byline display style to measure width
widths[key] = dom.getComputedWidth(elem)
widths[key] = dom.get.computedWidth(elem)
if (elem?.style?.cssText.includes(forceDisplayStyles)) // restore display style for hidden byline
elem.style.cssText = elem.style.cssText.replace(forceDisplayStyles, '')
})
Expand Down Expand Up @@ -3788,60 +3792,6 @@
}
}

// Define DOM utilities

const dom = {

create: {
anchor(linkHref, displayContent, attrs = {}) {
const anchor = document.createElement('a'),
defaultAttrs = { href: linkHref, target: '_blank', rel: 'noopener' },
finalAttrs = { ...defaultAttrs, ...attrs }
Object.entries(finalAttrs).forEach(([attr, value]) => anchor.setAttribute(attr, value))
if (displayContent) anchor.append(displayContent)
return anchor
},

style(content) {
const style = document.createElement('style')
if (content) style.innerText = content
return style
},

svgElem(type, attrs) {
const elem = document.createElementNS('http://www.w3.org/2000/svg', type)
for (const attr in attrs) elem.setAttributeNS(null, attr, attrs[attr])
return elem
}
},

fillStarryBG(targetNode) { // requires https://assets.aiwebextensions.com/styles/rising-stars/css/<black|white>.min.css
if (targetNode.querySelector('[id*=stars]')) return
const starsDivsContainer = document.createElement('div')
starsDivsContainer.style.cssText = 'position: absolute ; top: 0 ; left: 0 ;' // hug targetNode's top-left corner
+ 'height: 100% ; width: 100% ; border-radius: 15px ; overflow: clip ;' // bound innards exactly by targetNode
+ 'z-index: -1'; // allow interactive elems to be clicked
['sm', 'med', 'lg'].forEach(starSize => {
const starsDiv = document.createElement('div')
starsDiv.id = config.bgAnimationsDisabled ? `stars-${starSize}-off`
: `${ env.ui.app.scheme == 'dark' ? 'white' : 'black' }-stars-${starSize}`
starsDivsContainer.append(starsDiv)
})
targetNode.prepend(starsDivsContainer)
},

getComputedWidth(...elems) { // including margins
let totalWidth = 0
elems.map(arg => arg instanceof NodeList ? [...arg] : arg).flat().forEach(elem => {
if (!(elem instanceof Element)) return
const elemStyle = getComputedStyle(elem) ; if (elemStyle.display == 'none') return
totalWidth += elem.getBoundingClientRect().width + parseFloat(elemStyle.marginLeft)
+ parseFloat(elemStyle.marginRight)
})
return totalWidth
}
}

// Run MAIN routine

menu.register()
Expand Down
4 changes: 2 additions & 2 deletions googlegpt/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default [
ecmaVersion: 'latest', sourceType: 'script',
globals: {
...globals.browser, ...globals.greasemonkey, chatgpt: 'readonly', CryptoJS: 'readonly',
cryptoUtils: 'readonly', GM_cookie: 'readonly', hljs: 'readonly', ipv4: 'readonly', marked: 'readonly',
renderMathInElement: 'readonly'
cryptoUtils: 'readonly', dom: 'readonly', GM_cookie: 'readonly', hljs: 'readonly', ipv4: 'readonly',
marked: 'readonly', renderMathInElement: 'readonly'
}
},
plugins: { 'import': importPlugin, 'js-styles': stylisticJS, regexp },
Expand Down
Loading

0 comments on commit 1f6be5d

Please sign in to comment.