Sleazy Fork is available in English.

Better Danbooru Artist Search

Improve URL handling within the Danbooru artist search engine and automatically navigate to the wiki page if indubitable.

Tính đến 27-01-2017. Xem phiên bản mới nhất.

// ==UserScript==
// @name         Better Danbooru Artist Search
// @version      2.3.3
// @description  Improve URL handling within the Danbooru artist search engine and automatically navigate to the wiki page if indubitable.
// @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(/\./)
      && query.split(".").every(function(elem){ return elem.length > 1; }))) {
        switch (true) {
            case !query.startsWith("http://") && !query.startsWith("https://"):
                query = "http://" + query;
                console.log('(arsearch) Does not begin with protocol');
            /*falls through*/
            case query.includes("pixiv"):
                console.log('(arsearch) Is pixiv');
                switch (true) {
                case query.includes("/whitecube/user/"):
                    query = query.replace("/whitecube/user/", "/member.php?id=");
                    console.log('(arsearch) whitecube replaced');
                /*falls through*/
                case query.includes("/illust/"):
                    query = query.replace(/\/illust\/.*/, "");
                    console.log('(arsearch) illust removed');
                /*falls through*/
                case query.includes("#_=_"):
                    query = query.replace("A#_=_", "");
                    console.log('(arsearch) weird stuff removed');
                }
            break;
            case query.includes("twitter"):
                console.log('(arsearch) Is twitter');
                switch (true) {
                case query.includes("/mobile."):
                    query = query.replace("/mobile.", "");
                    console.log('(arsearch) Is mobile');
                /*falls through*/
                case query.includes("?p=s"):
                    query = query.replace("?p=s", "");
                    console.log('(arsearch) weird stuff removed');
                /*falls through*/
                case query.includes("/status/"):
                    query = query.replace(/\/status\/.*/, "");
                    console.log('(arsearch) Navigated to twitter account home');
                }
            break;
            case query.includes("tumblr"):
                console.log('(arsearch) Is tumblr');
                switch (true) {
                case !query.endsWith("com"):
                    console.log('(arsearch) Does not end with communism');
                    query = query.substr(0, query.search("com") + "com".length);
                }
            break;
            case query.includes("nicovideo"):
                console.log('(arsearch) Is nico');
                switch (true) {
                case query.includes("sp"):
                    query = "http://seiga.nicovideo.jp/seiga/" + query.substr(
                        query.length - "imXXXXXXX".length);
                    console.log('(arsearch) Contains sp');
                }
            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;
    }
})();