Derpibooru - Sort-by-Score Button

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

Від 01.06.2019. Дивіться остання версія.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Derpibooru - Sort-by-Score Button
// @namespace   Selbi
// @version     2.0.1
// @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 = 3;
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);