Skip to content

Commit

Permalink
0.2 增加淘宝阅读搜索,改为 document-start 和 ready 2种运行时间
Browse files Browse the repository at this point in the history
  • Loading branch information
ywzhaiqi committed Dec 31, 2014
1 parent 661ab44 commit 29377b6
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions searchHelper.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// @name Search Hepler
// @namespace https://github.com/ywzhaiqi
// @author ywzhaiqi
// @version 0.1
// @version 0.2
// @description 让一些特殊的搜索支持搜索串
// @include http://kindleren.com/search.php?mod=forum&mq=*
// @include http://shuzi.taobao.com/item/search---50094067.htm?q=*
// @grant GM_addStyle
// @require http://cdn.staticfile.org/zepto/1.1.4/zepto.min.js
// @run-at document-end
// @run-at document-start
// @noframes
// ==/UserScript==

Expand All @@ -23,17 +24,34 @@ function getParam(name, url) {
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() {
var search = getParam('mq', location.href);

$('#scform_srchtxt').val(search);
$('#scform_submit').click();
goSearch('mq', '#scform_srchtxt', '#scform_submit');
},
taobao: function() { // 解决乱码问题
goSearch2('http://shuzi.taobao.com/item/search-.htm?q=%s&isbook=ebook', 'q');
}
};


function run() { // 自动运行符合 host 的函数
var host = location.host;

Expand Down

0 comments on commit 29377b6

Please sign in to comment.