This commit is contained in:
Lauchmelder 2022-03-19 20:07:22 +01:00
commit b9acf06be5
No known key found for this signature in database
GPG key ID: C2403C69D78F011D
4 changed files with 139 additions and 0 deletions

34
content.js Normal file
View file

@ -0,0 +1,34 @@
chrome.storage.local.get("characters", (data) => {
const characters = data.characters
var rubyTags = document.body.getElementsByTagName("ruby")
for(let tag in rubyTags)
{
var ruby = document.createElement("ruby")
ruby.innerHTML = rubyTags.item(tag).innerHTML
var dummyRtTag = ruby.getElementsByTagName("rt").item(0)
try
{
dummyRtTag.parentNode.removeChild(dummyRtTag)
} catch(error)
{
console.error(error)
console.log(ruby)
}
if(characters.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))
}
}
}
})

16
manifest.json Normal file
View file

@ -0,0 +1,16 @@
{
"name": "FuriKani",
"description": "Removes furigana on websites based on your WaniKani level",
"version": "0.2",
"manifest_version": 3,
"action": {
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["content.js"]
}
],
"permissions": ["storage"]
}

20
popup.html Normal file
View file

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<input type="text" id="token" />
<button id="submit-token">
Submit
</button>
<button id="download">
Download Data
</button>
<button id="print">
Print Data
</button>
<script src="popup.js"></script>
</body>
</html>

69
popup.js Normal file
View file

@ -0,0 +1,69 @@
const getStorageData = key =>
new Promise((resolve, reject) =>
chrome.storage.local.get(key, result =>
chrome.runtime.lastError
? reject(Error(chrome.runtime.lastError.message))
: resolve(result)
)
)
const query = async (token, url) => {
const requestHeaders = new Headers()
requestHeaders.append("Authorization", "Bearer " + token)
const endpoint = new Request(
url,
{
method: "GET",
headers: requestHeaders
}
)
var result = await fetch(endpoint)
return result.json()
}
const submitButton = document.getElementById("submit-token");
const inputField = document.getElementById("token");
submitButton.addEventListener( "click", () => {
chrome.storage.local.set({"token": inputField.value})
})
const downloadButton = document.getElementById("download");
downloadButton.addEventListener("click", async () => {
const userData = await getStorageData("token")
var url = "https://api.wanikani.com/v2/level_progressions"
var response = await query(userData.token, url)
var level = response.total_count
var levelArray = []
for(var i = 1; i < level; i++)
levelArray.push(i)
var levelURLString = levelArray.join(",")
var url = "https://api.wanikani.com/v2/subjects?types=vocabulary&levels=" + levelURLString
var parsedData = []
do
{
var response = await query(userData.token, url)
for(let i in response.data)
{
parsedData.push(response.data[i].data.characters)
}
console.log(response)
url = response.pages.next_url
} while(url !== null)
chrome.storage.local.set({"characters": parsedData})
console.log("Downloaded data!")
})
const printButton = document.getElementById("print");
printButton.addEventListener("click", () => {
chrome.storage.local.get("characters", (data) => {
console.log(data.characters)
})
})