Last active
April 23, 2024 00:14
-
-
Save dougbacelar/481a95dfea33677bc04e74cde6eebea2 to your computer and use it in GitHub Desktop.
more convenient way to mark easy words as 'Never Forget' when starting to study on jpdb. https://jpdb.io/deck?id=3&sort_by=by-frequency-global&show_only=new
This file contains hidden or 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
const targetNode = document.querySelector("div.vocabulary-list"); | |
const config = { attributes: false, childList: true, subtree: true }; | |
const handleMutations = function (mutationsList) { | |
for (const mutation of mutationsList) { | |
if (mutation.type === "childList") { | |
if (mutation.removedNodes.length > 0) { | |
console.log("appending buttons"); | |
appendButtons(); | |
removeFurigana(); | |
} | |
} | |
} | |
}; | |
const observer = new MutationObserver(handleMutations); | |
observer.observe(targetNode, config); | |
const appendButtons = () => | |
[ | |
...document.querySelectorAll('form[action="/deck/never-forget/add"]'), | |
].forEach((elem) => | |
elem?.parentElement?.parentElement?.parentElement?.parentElement?.parentElement?.parentElement?.parentElement?.parentElement?.append( | |
elem, | |
), | |
); | |
appendButtons(); | |
const removeFurigana = () => | |
document.querySelectorAll("ruby rt").forEach((elem) => elem.remove()); | |
removeFurigana(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment