Last active
August 4, 2021 23:32
-
-
Save MarvNC/0f4122767e4fbc191ad86cebd4e5b73b to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name VNDB Time Flags | |
// @namespace https://github.com/MarvNC | |
// @match https://vndb.org/v*/lengthvotes | |
// @grant none | |
// @version 1.0 | |
// @author Marv | |
// @description Adds language flags to the time votes table. | |
// @grant GM_addStyle | |
// ==/UserScript== | |
let delayMs = 300; | |
const vnURL = 'https://vndb.org/v'; | |
const relRegex = /vndb.org\/r\d+/; | |
const flagHtml = (flag) => `<abbr class="icons lang ${flag}"></abbr>`; | |
(async function () { | |
GM_addStyle(`div.lengthlist .tc5 { | |
width: 60px; | |
}`); | |
const vnID = document.URL.match(/vndb\.org\/v([0-9]+)\/lengthvotes/)[1]; | |
const url = vnURL + vnID; | |
let doc = document.createElement('html'); | |
doc.innerHTML = await getUrl(url); | |
const langs = [...doc.querySelectorAll('.mainbox.vnreleases details')]; | |
const flags = {}; | |
langs.forEach((elem) => { | |
const flag = elem.dataset.saveId.substr(7); | |
const releases = [...elem.querySelectorAll('a[href]')] | |
.map((elem) => elem.href) | |
.filter((href) => href.match(relRegex)); | |
for (let release of releases) { | |
flags[release] = flag; | |
} | |
}); | |
console.log(flags); | |
[...document.querySelectorAll('a[href]')] | |
.filter((elem) => elem.href.match(relRegex)) | |
.forEach((elem) => { | |
const flag = flags[elem.href]; | |
elem.parentElement.innerHTML = flagHtml(flag) + elem.parentElement.innerHTML; | |
}); | |
})(); | |
async function getUrl(url) { | |
let response = await fetch(url); | |
return await response.text(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment