Created
September 13, 2023 17:39
-
-
Save killroy42/3233a9aaa6b18faaa5151d6c8fb75f01 to your computer and use it in GitHub Desktop.
Replaces emoji symbols in SudokuPad (paste into console)
This file contains hidden or 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
(async () => { | |
const requireScript = async src => new Promise((onload, onerror) => document.getElementsByTagName('head')[0].appendChild(Object.assign(document.createElement('script'), {src, onload, onerror}))); | |
const requireDependencies = async deps => Promise.all(deps.filter(url=>performance.getEntriesByName(url, 'resource').length==0).map(requireScript)); | |
await requireDependencies([`https://unpkg.com/[email protected]/dist/twemoji.min.js`]); | |
const style = `img.emoji { height: 1em; width: 1em; margin: 0 .05em 0 .1em; vertical-align: -0.1em; }`; | |
await attachStylesheet(style); | |
const opts = {ext: '.svg', folder: 'svg'}; | |
twemoji.parse(document.querySelector('.controls-info'), opts); | |
const textNodes = document.querySelectorAll('#svgrenderer text'); | |
for(const node of textNodes) if([...node.innerHTML].length === 1 && node.innerHTML.length !== 1) { | |
node.insertAdjacentHTML('afterend', twemoji.parse(node.innerHTML, opts) | |
.replace(/^<img/, `<image`).replace(` src="`, ` href="`).replace(` draggable="false"`, ``) | |
); | |
let bb = node.getBBox(), next = node.nextSibling; | |
for(const [key, val] of ['x','y','width','height'].map(key => [key, bb[key]])) next.setAttribute(key, val); | |
node.remove(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment