对于此目标页面(抱歉,SO 不允许超链接到 62.0.54.118):
http://62.0.54.118/search?&q=42&oq=42&sourceid=chrome&ie=UTF-8&filter=0
,我想<input>
默认使用用户脚本更改名称字段。
输入是:
<input class="gsfi" id="lst-ib" name="q" maxlength="2048" value="42"...>
我想将其更改为:
<input class="gsfi" id="lst-ib" name="&q" maxlength="2048" value="42"...>
也就是我想默认将输入字段中的inq
改为&q
in 。name
我尝试编写一个脚本,(这不起作用):
// ==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;
}
此外,该页面是一个 Ajax 驱动的页面。
请修复我的错误脚本或帮助我编写另一个脚本,谢谢。
更新: 我通过更改脚本的一行从以下内容解决了部分问题:
var newName = oldName.replace (/\q/, "&q");
至
var newName = oldName.replace (/q/, "&q");
然后我的脚本效果更好。感谢@Gerard Sexton 的建议。
但是现在有一个新的错误,将waitForKeyElements
回调设置return true;
为页面的 AJAX,它添加了&
不间断。
它导致该字段为name="&&&&&&&&&q"
等。
我该如何解决?