Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yanirmr authored Mar 14, 2023
0 parents commit 6871a31
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
54 changes: 54 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function replaceMandaicCharacters() {
const mandaicLetters = "\u{0840}\u{0841}\u{0842}\u{0843}\u{0844}\u{0845}\u{0846}\u{0847}\u{0848}\u{0849}\u{084A}\u{084B}\u{084C}\u{084D}\u{084E}\u{084F}\u{0850}\u{0851}\u{0852}\u{0853}\u{0854}\u{0855}";
const hebrewLetters = "אבגדחוזהטיכלמנסעפצקרשת";
const targetTags = ["b", "td"];

// Replace Mandaic characters in specific HTML tags
for (const tag of targetTags) {
const elements = document.getElementsByTagName(tag);
for (const element of elements) {
const originalText = element.textContent;
const regex = new RegExp(`[${mandaicLetters}\u{0856}]`, "g");
const newText = originalText.replace(regex, (match) => {
if (match === '\u{0856}') {
return '\u{05D3}\u{05B7}';
}
const index = mandaicLetters.indexOf(match);
return hebrewLetters.charAt(index);
});
// const regex = new RegExp(`[${mandaicLetters}]`, "g");
// const newText = originalText.replace(regex, (match) => {
// const index = mandaicLetters.indexOf(match);
//return hebrewLetters.charAt(index);
// });
if (newText !== originalText) {
element.textContent = newText;
}
}
}

// Replace Mandaic characters in all text nodes on the webpage
const textNodes = document.evaluate(
"//text()",
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null
);
for (let i = 0; i < textNodes.snapshotLength; i++) {
const textNode = textNodes.snapshotItem(i);
const originalText = textNode.textContent;
const regex = new RegExp(`[${mandaicLetters}]`, "g");
const newText = originalText.replace(regex, (match) => {
const index = mandaicLetters.indexOf(match);
return hebrewLetters.charAt(index);
});
if (newText !== originalText) {
textNode.textContent = newText;
}
}
}

// Call replaceMandaicCharacters() whenever the DOM is updated
const observer = new MutationObserver(replaceMandaicCharacters);
observer.observe(document, { subtree: true, childList: true });
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Mandaic Transcriber Plugin",
"version": "1.0",
"manifest_version": 3,
"host_permissions": [
"<all_urls>"
],
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"content.js"
]
}
]
}

0 comments on commit 6871a31

Please sign in to comment.