-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6871a31
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
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
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 }); |
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
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" | ||
] | ||
} | ||
] | ||
} |