Created
July 21, 2022 08:29
-
-
Save mimonelu/35516a37f1561a7a785143e13d643f8d to your computer and use it in GitHub Desktop.
文字モザイクブックマークレット
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
(() => { | |
const exclusionTags = [ 'SCRIPT', 'STYLE' ] | |
const exclusionCharacters = [ ' ', ' ' ] | |
const emptyRegex = new RegExp('^[\\s ]*$', 's') | |
const maskCharacters = [ '▀', '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█', '▔', '▙', '▚', '▛', '▜', '▞', '▟' ] | |
const irandom = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min | |
const traverseElement = (currentElement) => { | |
if (currentElement.nodeType === 1 && !exclusionTags.includes(currentElement.tagName)) { | |
currentElement.childNodes.forEach(traverseElement) | |
} else if (currentElement.nodeType === 3 && !emptyRegex.test(currentElement.nodeValue)) { | |
const maskElement = document.createElement('span') | |
maskElement.innerText = '' | |
for (let i = 0; i < currentElement.nodeValue.length; i ++) { | |
let character = currentElement.nodeValue.charAt(i) | |
if (!exclusionCharacters.includes(character)) { | |
character = maskCharacters[irandom(0, maskCharacters.length - 1)] | |
} | |
maskElement.innerText += character | |
} | |
currentElement.parentNode.replaceChild(maskElement, currentElement) | |
} | |
} | |
traverseElement(document.documentElement) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
圧縮はここ: https://www.toptal.com/developers/javascript-minifier
元ネタ: https://motemen.hatenablog.com/entry/2022/07/extension-obfuscate-texts