1
我寫了兩個非常相似的腳本,我希望它們在一個腳本下一起工作,我該怎麼做?如何將兩個用戶腳本合併爲一個?
第一:
// ==UserScript==
// @name Normal Google
// @include http://62.0.54.118/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
waitForKeyElements ("a[href*='?q=']", changeLinkQuery);
function changeLinkQuery (jNode) {
var oldHref = jNode.attr ('href');
var newHref = oldHref.replace (/\?q=/, "?&q=");
jNode.attr ('href', newHref);
return true;
}
第二userscript:
// ==UserScript==
// @name Normal Google Input
// @include http://62.0.54.118/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
waitForKeyElements ("input[name*='q']", changeLinkQuery);
function changeLinkQuery (jNode) {
var oldName = jNode.attr ('name');
var newName = oldName.replace (/q/, "&q");
jNode.attr ('name', newName);
return true;
}
我如何可以結合使用這些userscripts在一起嗎?
這是一個不好的解決我試着寫不起作用。
我在做什麼錯?
// ==UserScript==
// @name Google
// @include http://62.0.54.118/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
waitForKeyElements ("a[href*='?q=']","input[name*='q']", changeLinkQuery);
function changeLinkQuery (j1,j2) {
var oldHref = j1.attr ('href');
var newHref = oldHref.replace (/\?q=/, "?&q=");
var oldName = j2.attr ('name');
var newName = oldName.replace (/q/, "&q");
j1.attr ('href', newHref);
j2.attr ('name', newName);
return true;
}
我個人認爲,這兩個劇本有足夠的不同讓他們分開。 – phuzi