我写了两个非常相似的脚本,我希望它们都在一个脚本下一起工作,我该怎么做?
首先:
// ==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==
// @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;
}
如何将这些用户脚本组合在一起?
这是一个糟糕的解决方案,我尝试编写它不起作用。
我究竟做错了什么?
// ==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;
}