[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/dumpmemory/userscript/master/scripts/searchHelper.user.js [Back]  [Original]

// ==UserScript==
// @name         Search Hepler
// @namespace    https://github.com/ywzhaiqi
// @author       ywzhaiqi
// @version      0.3
// @description  
// @include      http://kindleren.com/search.php?mod=forum&mq=*
// @include      http://shuzi.taobao.com/item/search---50094067.htm?q=*
// @include      http://www.xiaopian.com/?q=*
// @include      https://www.jiumodiary.com/?q=*
// @include      http://www.yiwulib.cn:8088/websearch.asp?q=*
// @grant        GM_addStyle
// @require      http://cdn.staticfile.org/jquery/2.1.1/jquery.min.js
// @run-at       document-start
// @noframes
// ==/UserScript==

if (typeof String.prototype.includes != 'function') {
    String.prototype.includes = function(str) {
        return this.indexOf(str) != -1;
    };
}

function getParam(name, url) {
    var regexp = new RegExp("(?:^|\\?|#|&)" + name + "=([^&#]*)(?:$|&|#)", "i"),
        matches = regexp.exec(url || location.href);
    return matches ? decodeURIComponent(matches[1]) : ""
}

function goSearch(param, input, submit) {
    $(function() {
        var search = getParam(param, location.href);
        if (search) {
            $(input).val(search);
            $(submit).click();
        }
    });
}

//  document-start taobao 
function goSearch2(url, param) {
    var search = getParam(param, location.href);
    if (search) {
        location.href = url.replace('%s', search);
    }
}


var ns = {
    kindleren: function() {
        goSearch('mq', '#scform_srchtxt', '#scform_submit');
    },
    taobao: function() {  // 
        goSearch2('http://shuzi.taobao.com/item/search-.htm?q=%s&isbook=ebook', 'q');
    },
    xiaopian: function() {
        goSearch('q', 'input[name="keyboard"]', 'input[name="Submit"]')
    },
    jiumodiary() {
      goSearch('q', '#SearchWord', '#SearchButton')
    },
    yiwulib() {
      goSearch('q', 'input[name="taah"]', 'input[name="submit"]')
    }
};

function run() {  //  host 
    var host = location.host;

    Object.keys(ns).some(function(key) {
        if (host.includes(key)) {
            ns[key]();
            return true;
        }
    });
}


run();

Web Proxy Viewer  |  New URL  |  Original Page