问题描述
有关此目标页面(很抱歉,但等不允许超链接62.0.54.118):
<$p$p><$c$c>http://62.0.54.118/search?&q=42&oq=42&sourceid=chrome&ie=UTF-8&filter=0,我想换一个&LT的名称字段;输入&GT;默认使用userscript
输入为:
&LT;输入类=gsfiID =LST-IBNAME =Q最大长度=2048值=42......&GT;
我想将其更改为:
&LT;输入类=gsfiID =LST-IBNAME =&放大器; Q最大长度=2048值=42......&GT;
也就是说,我想换个①
到&放,Q
在名称
输入默认的领域。
我试着写一个脚本,(即不工作):
// == UserScript ==
// @name普通谷歌输入
// @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 ==
/ * - 的@grant指令需要解决设计变更
通用汽车1.0推出。它恢复了沙箱。
* /
waitForKeyElements(输入[姓名* ='Q'],changeLinkQuery);
功能changeLinkQuery(jNode){
VAR使用oldName = jNode.attr('名');
VAR了newName = oldName.replace(/ \ Q /&放大器; Q);
jNode.attr(名称,了newName);
返回true;
}
此外,该页面是一个Ajax驱动的页面。
请修复我的坏脚本或帮我写一个又一个,谢谢你。
更新:我解决了其中的一部分,通过改变行我的脚本的来源:
VAR了newName = oldName.replace(/ \ Q /&放大器; Q);
到
VAR了newName = oldName.replace(/ Q /&放大器; Q);
然后我的脚本效果更好。感谢@Gerard塞克斯顿的提示。
但有一个新的错误,现在,与 waitForKeyElements
回调设置为返回true;
的页面的AJAX ,它添加了&安培;
不停。
这导致该领域是 NAME =&放大器;&安培;&安培;&安培;&安培;&安培;&安培;&安培;&安培; Q。
等
我该如何解决这个问题?
如果输入的名字只是①
,其本身则仅仅是改变waitForKeyElements来电:
waitForKeyElements(输入[名称='Q'],changeLinkQuery);
这样它查找的完全的①
,而不是AQ字符串中的任何位置。
如果这不是的完全的那名&LT;输入&GT;
,下面评论
For this target page (Sorry but SO doesn't allow hyperlinks to 62.0.54.118):
http://62.0.54.118/search?&q=42&oq=42&sourceid=chrome&ie=UTF-8&filter=0
, I want to change the name field of an <input>
by default with a userscript.
The input is:
<input class="gsfi" id="lst-ib" name="q" maxlength="2048" value="42"...>
I want to change it to:
<input class="gsfi" id="lst-ib" name="&q" maxlength="2048" value="42"...>
That is, I Want to change the q
into &q
in the name
field of the input by default.
I try to write a script, (that doesn't work):
// ==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;
}
In addition, the page is an Ajax-driven page.
Please fix my bad script or help me to write another one,Thanks.
Update:I solved a part of that by changing a line of my script from:
var newName = oldName.replace (/\q/, "&q");
to
var newName = oldName.replace (/q/, "&q");
and then my script works better. Thanks to @Gerard Sexton for suggesting that.
But there is a new bug now, with the waitForKeyElements
callback set to return true;
for the page's AJAX, It adds the &
non stop.
It causes this field to be name="&&&&&&&&&q"
, etc.
How can I fix it?
If the input name is just q
, by itself, then merely change the waitForKeyElements call to:
waitForKeyElements ("input[name='q']", changeLinkQuery);
So that it looks for exactly q
, rather than a q anywhere in the string.
If that's not exactly the name of that <input>
, comment below.
这篇关于如何更改&LT的名称字段;输入&GT;在AJAX驱动页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!