Adds a button to automatically sort by score after a search. Also, remove pointless scope stuff from URLs.
当前为
// ==UserScript==
// @name Derpibooru - Sort-by-Score Button
// @namespace Selbi
// @version 2.0.2
// @include http*://*derpiboo.ru/tags*
// @include http*://*derpibooru.org/tags*
// @include http*://*derpiboo.ru/search*
// @include http*://*derpibooru.org/search*
// @grant none
// @description Adds a button to automatically sort by score after a search. Also, remove pointless scope stuff from URLs.
// ==/UserScript==
const TARGET_SCORE = "score";
const TARGET_DESCENDING = "desc";
let sortButtonIcon = document.createElement("i");
sortButtonIcon.classList = "fas fa-sort-amount-down";
Object.assign(sortButtonIcon.style, {
width: "28px",
textAlign: "center"
});
let sortButton = document.createElement("a");
sortButton.classList = "header__search__button";
sortButton.title = "Sort by descending score";
sortButton.onclick = function() {
let sortDropdown = document.querySelector("#search_sf");
sortDropdown.selectedIndex = findOptionIndex(sortDropdown, TARGET_SCORE);
let orderDropdown = document.querySelector("#search_sd");
orderDropdown.selectedIndex = findOptionIndex(orderDropdown, TARGET_DESCENDING);
document.querySelector(".field > button:first-child").click();
};
sortButton.appendChild(sortButtonIcon);
document.querySelector(".header__search").appendChild(sortButton);
function findOptionIndex(elem, value) {
let options = elem.getElementsByTagName("option");
let index = 0;
for (o of options) {
if (o.value == value) {
return index;
}
index++;
}
return -1;
}