Skip to content

Instantly share code, notes, and snippets.

@IlanFrumer
Created April 8, 2024 16:01
Show Gist options
  • Save IlanFrumer/2fd67562c4cb11686fd18863e995a1d0 to your computer and use it in GitHub Desktop.
Save IlanFrumer/2fd67562c4cb11686fd18863e995a1d0 to your computer and use it in GitHub Desktop.
Convert Classical Syriac text to Hebrew script on Wikipedia
// ==UserScript==
// @name Classical Syriac Wikipedia to Hebrew
// @namespace http://tampermonkey.net/
// @version 2024-04-08
// @description Convert Classical Syriac text to Hebrew script on Wikipedia
// @author [email protected]
// @match https://arc.wikipedia.org/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=wikipedia.org
// @grant none
// ==/UserScript==
(function () {
"use strict";
const SyriacMap = {
ܐ: /* Aleph */ "א",
ܒ: /* Beth */ "ב",
ܓ: /* Gimel */ "ג",
ܕ: /* Daleth */ "ד",
ܗ: /* He */ "ה",
ܘ: /* Vav */ "ו",
ܙ: /* Zayin */ "ז",
ܚ: /* Het */ "ח",
ܛ: /* Tet */ "ט",
ܝ: /* Yod */ "י",
ܟ: /* Kaf */ "כ",
ܠ: /* Lemed */ "ל",
ܡ: /* Mem */ "מ",
ܢ: /* Nun */ "נ",
ܣ: /* Samekh */ "ס",
ܤ: /* Samekh */ "ס",
ܥ: /* Ayin */ "ע",
ܦ: /* Pe */ "פ",
ܨ: /* Tsadi */ "צ",
ܩ: /* Qof */ "ק",
ܪ: /* Resh */ "ר",
ܫ: /* Shin */ "ש",
ܬ: /* Tav */ "ת",
};
const finalFormMap = {
מ: /** Mem */ "ם",
נ: /** Nun */ "ן",
צ: /** Tsadi */ "ץ",
פ: /** Pe */ "ף",
כ: /** Kaf */ "ך",
};
const chars = new Map();
function transformNodes(node) {
// If the node is a text node, add it to the array
if (node.nodeType === Node.TEXT_NODE) {
const textContent = node.textContent;
let text = "";
for (let i = 0; i < textContent.length; i++) {
let char = textContent[i];
let out = SyriacMap[char];
const code = char.codePointAt(0);
text += out ?? char;
if (code > 200 && !out) chars.set(code.toString(16), char);
}
text = text
.replace(/\u0700/g, ".")
.replace(/\u0706/g, ",")
.replace(/\u0308/g, "")
.replace(
/([מנצפכ])([^\u05D0-\u05EA])/g,
(_m, m1, m2) => finalFormMap[m1] + m2
)
.replace(/([מנצפכ])$/g, (_m, m1) => finalFormMap[m1]);
if (textContent != text) {
node.textContent = text;
}
} else {
// If the node has children, recursively call this function on each child
if (node.childNodes.length > 0) {
for (let i = 0; i < node.childNodes.length; i++) {
transformNodes(node.childNodes[i]);
}
}
}
}
transformNodes(document.body);
console.log(chars);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment