Created
November 6, 2018 17:12
-
-
Save loxaxs/c07f85ecc9373e2f566324f6127c87e0 to your computer and use it in GitHub Desktop.
A JS script for Derpibooru which orders any tag list of the page by tag count. It's supposed to be used in the developer console (F12 or Ctrl+Shift+I/J).
This file contains 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
/* A function to change the page display */ | |
function appendCss(css) { | |
var styleElem = document.createElement('style'); | |
styleElem.textContent = css; | |
document.head.appendChild(styleElem); | |
} | |
/* A function to extract the tag-count of a tag element */ | |
function extractCount(tagElem) { | |
return parseInt(tagElem.innerText.replace(/^.* \((\d+)\) \+$/, "$1")); | |
} | |
/* For all tag list of the page */ | |
for (let tagList of document.querySelectorAll(".tag-list")) { | |
let tagV = Array.from(tagList.children); | |
/* The below line computes the new ordre */ | |
tagV.sort((tagA, tagB) => extractCount(tagB) - extractCount(tagA)); | |
/* For all element of the now ordered list */ | |
for (let el of tagV) { | |
/* Move it to the end of the list */ | |
tagList.appendChild(el); | |
} | |
} | |
/* The below code changes the display of the tags from horizontal to vertical */ | |
appendCss(` | |
.tag-list > * { | |
display: table; | |
} | |
`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment