From 60a2943d2dd22822d58bb1e1d3386c2170cdc167 Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Fri, 1 Apr 2022 14:09:24 +0200 Subject: [PATCH 1/7] v0.7 --- VERSIONS.md | 6 +++++- manifest.json | 2 +- src/popup.html | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/VERSIONS.md b/VERSIONS.md index c133214..3d3c46e 100644 --- a/VERSIONS.md +++ b/VERSIONS.md @@ -10,4 +10,8 @@ ## 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 \ No newline at end of file diff --git a/manifest.json b/manifest.json index ba59a81..770898f 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", "icons": { "16": "res/icon16.png", "48": "res/icon48.png", diff --git a/src/popup.html b/src/popup.html index f0e235f..1ef9b4b 100644 --- a/src/popup.html +++ b/src/popup.html @@ -6,7 +6,7 @@

FuriKani

-

v0.6.3

+

v0.7

From 1cb190d2e8e47afd0ff8f1bcd5143425998ece1d Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Fri, 1 Apr 2022 14:24:43 +0200 Subject: [PATCH 2/7] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8ed7602..51aca08 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ 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/de/firefox/addon/furikani/) --- From 64634405beb773c6dd984d6ce473cb09a0acebff Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Fri, 1 Apr 2022 14:27:46 +0200 Subject: [PATCH 3/7] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 51aca08..11f0b94 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ 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/de/firefox/addon/furikani/) --- From 8df65ea893709acbbe715ba8ce8982b3e36e3eea Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Fri, 1 Apr 2022 15:08:44 +0200 Subject: [PATCH 4/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 11f0b94..e5a03f1 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ 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/de/firefox/addon/furikani/) +[Download it from the Firefox Add-On Store](https://addons.mozilla.org/en-US/firefox/addon/furikani/) --- From 18d679476e144a235a62dc9dd348ad203e05fbef Mon Sep 17 00:00:00 2001 From: lauchmelder Date: Sun, 9 Mar 2025 20:00:20 +0100 Subject: [PATCH 5/7] fix unstable behaviour for non static websites --- VERSIONS.md | 5 +++- build.sh | 0 manifest.json | 2 +- src/content.js | 71 +++++++++++++++++++++++++++++--------------------- 4 files changed, 46 insertions(+), 32 deletions(-) mode change 100644 => 100755 build.sh diff --git a/VERSIONS.md b/VERSIONS.md index 3d3c46e..c2d9511 100644 --- a/VERSIONS.md +++ b/VERSIONS.md @@ -14,4 +14,7 @@ # v0.7 * FuriKani now supports Firefox! - * Fixed potential innerHTML risks \ No newline at end of file + * Fixed potential innerHTML risks + +## v0.7.1 + * Add support for non-static websites diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 diff --git a/manifest.json b/manifest.json index 770898f..9efc9d9 100644 --- a/manifest.json +++ b/manifest.json @@ -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..d5a01b3 100644 --- a/src/content.js +++ b/src/content.js @@ -19,6 +19,35 @@ 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") +} + + // 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 +68,19 @@ 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") + let observer = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + mutation.addedNodes.forEach((node, _key, _parent) => { + if (node.tagName?.toLowerCase() !== "ruby") { + return; + } - 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 + handleRubyTag(node, vocabulary, kanji) + }) + }); + }) - // 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 = 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 +107,4 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { } return true; -}) \ No newline at end of file +}) From 303879145b1f146d0c4926f8f387af4ad16ff014 Mon Sep 17 00:00:00 2001 From: lauchmelder Date: Sun, 9 Mar 2025 20:01:03 +0100 Subject: [PATCH 6/7] update links to repo --- src/popup.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/popup.html b/src/popup.html index 1ef9b4b..552f71c 100644 --- a/src/popup.html +++ b/src/popup.html @@ -53,10 +53,10 @@ - \ No newline at end of file + From 597a1d9d20b4339e4ed59e6efd105aa1934b350c Mon Sep 17 00:00:00 2001 From: lauchmelder Date: Fri, 18 Apr 2025 17:30:36 +0200 Subject: [PATCH 7/7] add initial cleanse of ruby tags on page load --- VERSIONS.md | 3 +++ manifest.json | 2 +- src/content.js | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/VERSIONS.md b/VERSIONS.md index c2d9511..b4e95f3 100644 --- a/VERSIONS.md +++ b/VERSIONS.md @@ -18,3 +18,6 @@ ## v0.7.1 * Add support for non-static websites + +## v0.7.2 + * Explicitly handle ruby tags on initial page load diff --git a/manifest.json b/manifest.json index 9efc9d9..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.7", + "version": "0.7.2", "icons": { "16": "res/icon16.png", "48": "res/icon48.png", diff --git a/src/content.js b/src/content.js index d5a01b3..73a020f 100644 --- a/src/content.js +++ b/src/content.js @@ -47,6 +47,12 @@ function handleRubyTag(tag, vocabulary, kanji) { 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) => { @@ -68,6 +74,8 @@ chrome.storage.local.get(["vocabulary", "kanji", "validUserLevel", "enabled", "e const vocabulary = data.vocabulary const kanji = data.kanji + removeExistingTags(vocabulary, kanji) + let observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { mutation.addedNodes.forEach((node, _key, _parent) => {