Danbooru Artist Search Tweaks

Make Danbooru Artist search slightly, subjectively better.

Versión del día 8/12/2016. Echa un vistazo a la versión más reciente.

// ==UserScript==
// @name         Danbooru Artist Search Tweaks
// @version      2.2.0
// @description  Make Danbooru Artist search slightly, subjectively better.
// @author       ForgottenUmbrella
// @match        https://danbooru.donmai.us/artists*
// @namespace    https://greasyfork.org/users/83187
// ==/UserScript==

(function() {
    'use strict';
    var query = document.getElementById("search_name").value;
    var old_query = query;

    var domains = [/.com(\/|$)/, /.net(\/|$)/, /.jp(\/|$)/];
    if (domains.some(function(elem){ return ~query.search(elem); }) ||
      (query.match(/\./g).length > 1
      && query.split(".").every(function(elem){ return elem > 1; })
      && query.substr(query.length) !== ".")) {
        switch (true) {
            case !query.startsWith("http://"):
                query = "http://" + query;
            case query.includes("pixiv"):
                case query.includes("/whitecube/user/"):
                    query = query.replace("/whitecube/user/", "/member.php?id=");
                case query.includes("/illust/"):
                    query = query.replace(/\/illust\/.*/, "");
                case query.includes("#_=_"):
                    query = query.replace("A#_=_", "");
                break;
            case query.includes("twitter"):
                case query.includes("/mobile."):
                    query = query.replace("/mobile.", "");
                case query.includes("?p=s"):
                    query = query.replace("?p=s", "");
                case query.includes("/status/"):
                    query = query.replace(/\/status\/.*/, "");
                break;
            case query.includes("tumblr"):
                case !query.endsWith("com"):
                    query = query.substr(0, query.search("com") + "com".length);
                break;
            default:
                break;

        }
        if (query !== old_query) {
            document.getElementById("search_name").value = query;
            document.getElementsByName("commit")[0].click();
        }
    }

    var artists_list = document.getElementsByTagName("tbody")[1];
    if (artists_list.childElementCount === 1) {
        //Redundant variables because it would otherwise be too unwieldy.
        var first_artist = artists_list.firstElementChild;
        var artist_table_data = first_artist.getElementsByTagName("td")[0];
        var url = artist_table_data.getElementsByTagName("a")[0].href;
        document.location = url;
    }
})();