added toggle switches
This commit is contained in:
parent
09caab1e59
commit
bfa0c65a98
3 changed files with 109 additions and 20 deletions
|
@ -1,10 +1,37 @@
|
|||
var vocabStyle = `
|
||||
.furikani-vocabulary {
|
||||
display: none;
|
||||
}
|
||||
`
|
||||
|
||||
var kanjiStyle = `
|
||||
.furikani-kanji {
|
||||
display: none;
|
||||
}
|
||||
`
|
||||
|
||||
var vocabStyleSheet = document.createElement("style")
|
||||
var kanjiStyleSheet = document.createElement("style")
|
||||
|
||||
document.head.appendChild(vocabStyleSheet)
|
||||
document.head.appendChild(kanjiStyleSheet)
|
||||
|
||||
// Get stored word list from chrome storage
|
||||
chrome.storage.local.get(["vocabulary", "kanji", "validUserLevel"], (data) => {
|
||||
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
|
||||
// WaniKani requires that devs check if users are actually allowed to access content of this level
|
||||
if(!data.validUserLevel)
|
||||
return
|
||||
|
||||
if(data.enabled)
|
||||
{
|
||||
if(data.enabledVocab)
|
||||
vocabStyleSheet.innerHTML = vocabStyle
|
||||
|
||||
if(data.enabledKanji)
|
||||
kanjiStyleSheet.innerHTML = kanjiStyle
|
||||
}
|
||||
|
||||
const vocabulary = data.vocabulary
|
||||
const kanji = data.kanji
|
||||
|
||||
|
@ -32,17 +59,32 @@ chrome.storage.local.get(["vocabulary", "kanji", "validUserLevel"], (data) => {
|
|||
}
|
||||
|
||||
// If the contents of the <ruby> tag are in the word list, remove the <rt> tag
|
||||
if(vocabulary.includes(ruby.innerText) || kanji.includes(ruby.innerText))
|
||||
{
|
||||
var rtTag = rubyTags.item(tag).getElementsByTagName("rt").item(0)
|
||||
try
|
||||
{
|
||||
rtTag.parentNode.removeChild(rtTag)
|
||||
} catch(error)
|
||||
{
|
||||
console.error(error)
|
||||
console.log(rubyTags.item(tag))
|
||||
}
|
||||
}
|
||||
var rtTag = rubyTags.item(tag).getElementsByTagName("rt").item(0)
|
||||
if(vocabulary.includes(ruby.innerText))
|
||||
rtTag.classList.add("furikani-vocabulary")
|
||||
else if(kanji.includes(ruby.innerText))
|
||||
rtTag.classList.add("furikani-kanji")
|
||||
}
|
||||
})
|
||||
|
||||
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
||||
if(msg.action === "settingsUpdated")
|
||||
{
|
||||
chrome.storage.local.get(["enabled", "enabledVocab", "enabledKanji"], (data) => {
|
||||
console.log(data)
|
||||
|
||||
if(!data.enabled)
|
||||
{
|
||||
vocabStyleSheet.innerHTML = ""
|
||||
kanjiStyleSheet.innerHTML = ""
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
vocabStyleSheet.innerHTML = data.enabledVocab ? vocabStyle : ""
|
||||
kanjiStyleSheet.innerHTML = data.enabledKanji ? kanjiStyle : ""
|
||||
})
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue