diff --git a/README.md b/README.md index 8ed7602..e5a03f1 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ This is a chrome extension that automatically removes furigana from websites bas ## Installation [Download it from the Chrome Web Store](https://chrome.google.com/webstore/detail/furikani/lbjenjfljjnlkbdfbgmgcnkfnddaeccl) +[Download it from the Firefox Add-On Store](https://addons.mozilla.org/en-US/firefox/addon/furikani/) + --- ## How to use diff --git a/VERSIONS.md b/VERSIONS.md index c133214..b4e95f3 100644 --- a/VERSIONS.md +++ b/VERSIONS.md @@ -10,4 +10,14 @@ ## v0.6.3 * Startup sync check is now more consistent * Level number updates in realtime after sync - * Fixed bug where internal Kanji list would get reset on sync \ No newline at end of file + * Fixed bug where internal Kanji list would get reset on sync + +# v0.7 + * FuriKani now supports Firefox! + * Fixed potential innerHTML risks + +## v0.7.1 + * Add support for non-static websites + +## v0.7.2 + * Explicitly handle ruby tags on initial page load diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 diff --git a/manifest.json b/manifest.json index ba59a81..3223517 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "FuriKani", "description": "Removes furigana on websites based on your WaniKani level", - "version": "0.6.3", + "version": "0.7.2", "icons": { "16": "res/icon16.png", "48": "res/icon48.png", @@ -21,4 +21,4 @@ "scripts": ["src/background.js"] }, "permissions": ["storage"] -} \ No newline at end of file +} diff --git a/src/content.js b/src/content.js index 9fb24bd..73a020f 100644 --- a/src/content.js +++ b/src/content.js @@ -19,6 +19,41 @@ var kanjiStyleSheet = document.createElement("style") document.head.appendChild(vocabStyleSheet) document.head.appendChild(kanjiStyleSheet) +function handleRubyTag(tag, vocabulary, kanji) { + // Copy the ruby element into a new ruby element so we can modify it + // without modifying the website + var ruby = document.createElement("ruby") + ruby.innerHTML = tag.innerHTML; + + // Remove all tags (except for , ) + while(ruby.lastElementChild) + { + if(ruby.lastElementChild.tagName.toLowerCase() === "rb" || + ruby.lastElementChild.tagName.toLowerCase() === "span") + { + ruby.innerHTML = ruby.lastElementChild.innerHTML + break + } + + ruby.removeChild(ruby.lastElementChild) + } + + // If the contents of the tag are in the word list, tag the tag + // with the correct class + var rtTag = tag.getElementsByTagName("rt").item(0) + if(vocabulary.includes(ruby.innerText)) + rtTag.classList.add("furikani-vocabulary") + if(kanji.includes(ruby.innerText)) + rtTag.classList.add("furikani-kanji") +} + +function removeExistingTags(vocabulary, kanji) { + let nodes = document.querySelectorAll("ruby") + nodes.forEach((node, _key, _parent) => { + handleRubyTag(node, vocabulary, kanji) + }); +}; + // Get stored word list from chrome storage chrome.storage.local.get(["vocabulary", "kanji", "validUserLevel", "enabled", "enabledVocab", "enabledKanji"], (data) => { // The users level is not valid, e.g. it exceeds the maximum allowed level @@ -39,37 +74,21 @@ chrome.storage.local.get(["vocabulary", "kanji", "validUserLevel", "enabled", "e const vocabulary = data.vocabulary const kanji = data.kanji - // Fetch all tags on the website - var rubyTags = document.body.getElementsByTagName("ruby") + removeExistingTags(vocabulary, kanji) - for(let tag in rubyTags) - { - // Copy the ruby element into a new ruby element so we can modify it - // without modifying the website - var ruby = document.createElement("ruby") - ruby.innerHTML = rubyTags.item(tag).innerHTML + let observer = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + mutation.addedNodes.forEach((node, _key, _parent) => { + if (node.tagName?.toLowerCase() !== "ruby") { + return; + } - // Remove all tags (except for , ) - while(ruby.lastElementChild) - { - if(ruby.lastElementChild.tagName.toLowerCase() === "rb" || - ruby.lastElementChild.tagName.toLowerCase() === "span") - { - ruby.innerHTML = ruby.lastElementChild.innerHTML - break - } + handleRubyTag(node, vocabulary, kanji) + }) + }); + }) - ruby.removeChild(ruby.lastElementChild) - } - - // If the contents of the tag are in the word list, tag the tag - // with the correct class - var rtTag = rubyTags.item(tag).getElementsByTagName("rt").item(0) - if(vocabulary.includes(ruby.innerText)) - rtTag.classList.add("furikani-vocabulary") - if(kanji.includes(ruby.innerText)) - rtTag.classList.add("furikani-kanji") - } + observer.observe(document.documentElement, { subtree: true, childList: true }); }) chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { @@ -96,4 +115,4 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { } return true; -}) \ No newline at end of file +}) diff --git a/src/popup.html b/src/popup.html index f0e235f..552f71c 100644 --- a/src/popup.html +++ b/src/popup.html @@ -6,7 +6,7 @@

FuriKani

-

v0.6.3

+

v0.7

@@ -53,10 +53,10 @@ - \ No newline at end of file +