Danbooru Artist Search Tweaks

Prepend the missing http protocol, and other tweaks.

נכון ליום 27-11-2016. ראה הגרסה האחרונה.

// ==UserScript==
// @name         Danbooru Artist Search Tweaks
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Prepend the missing http protocol, and other tweaks.
// @author       ForgottenUmbrella
// @match        https://danbooru.donmai.us/artists*
// ==/UserScript==

(function() {
    'use strict';
    var query = document.getElementById("search_name").value;
    if ([/.com(\/|$)/, /.net(\/|$)/, /.jp(\/|$)/].some(function(elem){ return ~query.search(elem); })) {
        var is_tweaked = false;
        //Missing protocol
        if (!query.startsWith("http")) {
            query = "http://" + query;
            is_tweaked = true;
        }
        //Pixiv
        if (query.includes("pixiv")) {
            if (query.includes("/whitecube/user/")) {
                query = query.replace("/whitecube/user/", "/member.php?id=");
		if (query.includes("/illust/")) {
	            query = query.replace(/\/illust\/.*/, "");
		}
                is_tweaked = true;
            }
            if (query.includes("#_=_")) {
	        query = query.replace("#_=_", "");
		is_tweaked = true;
            }
        }
        //Twitter
        if (query.includes("twitter")) {
            if (query.includes("/mobile.")) {
                query = query.replace("/mobile.", "");
		if (query.includes("?p=s")) {
                    query = query.replace("?p=s", "");
	        }
		if (query.includes("/status/")) {
		    query = query.replace(/\/status\/.*/, "");
		}
                is_tweaked = true;
            }
        }
	//Tumblr
	if (query.includes("tumblr")) {
	    if (query.substr(query.length-3) != "com" && query.substr(query.length-4) != "com/") {
		query = query.substr(0, query.search("com")+3);
		is_tweaked = true;
	    }
	}
        if (is_tweaked) {
            document.getElementById("search_name").value = query;
            document.getElementsByName("commit")[0].click();
        }
    }
})();