Fixed sort:score Button

Fixed version of the sort:score button

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

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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        Fixed sort:score Button
// @namespace   Violentmonkey Scripts
// @version     1
// @author      usnkw, hetisnietgay
// @description Fixed version of the sort:score button
// @license MIT
// @match       *://rule34.xxx/*
// ==/UserScript==
// Don't need so many comments, it's clear what we're doing

// Removed on ready/load call since grease/violent/tampermonkey
// scripts are executed on DOMContentLoaded

(() => {
    'use strict';

     // Create our button
    var newButton = document.createElement("Button");
    newButton.innerHTML = "sort:score";
    newButton.style.cursor = "pointer";

    // Better not to use inline events
    newButton.addEventListener('click', (e) => {

        var searchField = document.getElementsByName("tags")[0];

        if (searchField.value.toLowerCase().indexOf("sort:score") == -1) {
            searchField.value += " sort:score"
        }

        e.preventDefault();
    });

    // Search box has class awesomplete, add our button after it
    document.getElementsByClassName("awesomplete")[0].appendChild(newButton);

})();