Created
September 6, 2021 15:03
-
-
Save CaptainJiNX/1932e959dbdd5ae606d53fec7c94475f to your computer and use it in GitHub Desktop.
Pseudo translates all text on a page, when 'L' is pressed...
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
// ==UserScript== | |
// @name Pseudolocalization | |
// @namespace https://yagisoft.se/ | |
// @version 1.0 | |
// @description Pseudo translates all text on a page, when 'L' is pressed... | |
// @author ctjinx@gmail.com | |
// @match http://* | |
// @match https://* | |
// @match http://*/* | |
// @match https://*/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const ESCAPED_REGEX = /<.*?>|{{.*?}}|%{.*?}|https?:\/\/\S+|&\S*?;/gm | |
const VOWELS = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']; | |
const LETTERS = { | |
'a': 'α', | |
'b': 'ḅ', | |
'c': 'ͼ', | |
'd': 'ḍ', | |
'e': 'ḛ', | |
'f': 'ϝ', | |
'g': 'ḡ', | |
'h': 'ḥ', | |
'i': 'ḭ', | |
'j': 'ĵ', | |
'k': 'ḳ', | |
'l': 'ḽ', | |
'm': 'ṃ', | |
'n': 'ṇ', | |
'o': 'ṓ', | |
'p': 'ṗ', | |
'q': 'ʠ', | |
'r': 'ṛ', | |
's': 'ṡ', | |
't': 'ṭ', | |
'u': 'ṵ', | |
'v': 'ṽ', | |
'w': 'ẁ', | |
'x': 'ẋ', | |
'y': 'ẏ', | |
'z': 'ẓ', | |
'A': 'Ḁ', | |
'B': 'Ḃ', | |
'C': 'Ḉ', | |
'D': 'Ḍ', | |
'E': 'Ḛ', | |
'F': 'Ḟ', | |
'G': 'Ḡ', | |
'H': 'Ḥ', | |
'I': 'Ḭ', | |
'J': 'Ĵ', | |
'K': 'Ḱ', | |
'L': 'Ḻ', | |
'M': 'Ṁ', | |
'N': 'Ṅ', | |
'O': 'Ṏ', | |
'P': 'Ṕ', | |
'Q': 'Ǫ', | |
'R': 'Ṛ', | |
'S': 'Ṣ', | |
'T': 'Ṫ', | |
'U': 'Ṳ', | |
'V': 'Ṿ', | |
'W': 'Ŵ', | |
'X': 'Ẋ', | |
'Y': 'Ŷ', | |
'Z': 'Ż', | |
}; | |
function onKeydown(evt) { | |
if (evt.code === 'KeyL') { | |
translateNode(document); | |
} | |
} | |
function translateNode(node) { | |
if (node.nodeType === Node.ATTRIBUTE_NODE || node.nodeName === 'STYLE' || node.nodeName === 'SCRIPT') { | |
return; | |
} | |
if (node.nodeType && node.nodeType === Node.TEXT_NODE) { | |
node.textContent = translateString(node.textContent); | |
return; | |
} | |
if (node.childNodes && node.childNodes.length) { | |
node.childNodes.forEach(translateNode); | |
} | |
} | |
function translateString(str) { | |
return str.split('').map(translateChar).join(''); | |
} | |
function translateChar(char) { | |
if(VOWELS.includes(char)) { | |
return LETTERS[char] + LETTERS[char]; | |
} | |
return LETTERS[char] || char; | |
} | |
document.addEventListener('keydown', onKeydown, true); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment