このターゲット ページ (申し訳ありませんが、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"...>
つまり、デフォルトで入力のフィールドに を変更q
したいのです。&q
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"
は などになります。
どうすれば修正できますか?