-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added dom.js as dependency ↞ [auto-sync from https://github.com/adaml…
- Loading branch information
1 parent
6bc7122
commit c791e67
Showing
2 changed files
with
8 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -184,6 +184,7 @@ | |
// @require https://cdn.jsdelivr.net/npm/@kudoai/[email protected]/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/[email protected]/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/[email protected]/dist/katex.min.js#sha256-n0UwfFeU7SR6DQlfOmLlLvIhWmeyMnIDp/2RmVmuedE= | ||
|
@@ -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 = { | ||
|
@@ -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, '') | ||
}) | ||
|
@@ -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() | ||
|