Derpibooru - Sort-by-Score Button

Adds a button to automatically sort by score after a search. Also, remove pointless scope stuff from URLs.

Ekde 2019/01/07. Vidu La ĝisdata versio.

// ==UserScript==
// @name        Derpibooru - Sort-by-Score Button
// @namespace   Selbi
// @version     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 INDEX_SORTBYSCORE = 2;
const INDEX_DESCENDING = 0;

var sortButtonIcon = document.createElement("i");
sortButtonIcon.classList = "fas fa-sort-amount-down";
Object.assign(sortButtonIcon.style, {
  width: "28px",
  textAlign: "center"
});

var sortButton = document.createElement("a");
sortButton.classList = "header__search__button";
sortButton.title = "Sort by descending score";
sortButton.onclick = function() {
  document.querySelector("select.input--separate-left:nth-child(3)").selectedIndex = INDEX_SORTBYSCORE;
  document.querySelector("#sd").selectedIndex = INDEX_DESCENDING;
  
  document.querySelector(".field > input.button:first-child").click();
};

sortButton.appendChild(sortButtonIcon);
document.querySelector(".header__search").appendChild(sortButton);