jQueryを使用すると、これは非常に簡単です。完全なスクリプトは次のとおりです。
// ==UserScript==
// @name _Radio button check
// @include http://YOUR_SITE/YOUR_PATH/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.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.
*/
$("input[name='11'][value='zzzz']").prop ('checked', true);
input[name='11'][value='zzzz']
jQueryセレクターは、初期値<input>
を持つすべてのを取得しますが、それらが。を含むラジオボタンのグループにある場合に限ります。zzzz
name="11"
参照:
重要: 上記はほとんどのページで機能しますが、AJAX駆動型のページでは、多くの場合、 AJAX対応の手法を使用する必要があります。 これは、気になるチェックボックスが読み込まれる前に、Greasemonkeyスクリプトが実行されるためです。
これに対処する1つの方法は、waitForKeyElements
ユーティリティを使用することです。そのようです:
// ==UserScript==
// @name _Radio button check
// @include http://YOUR_SITE/YOUR_PATH/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/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='11'][value='zzzz']", selectRadioButton, true);
function selectRadioButton (jNode) {
jNode.prop ('checked', true);
}
質問がされたときに「最先端」だった古い答え:):
// ==UserScript==
// @name _Radio button check
// @include http://YOUR_SITE/YOUR_PATH/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
// ==/UserScript==
$("input[name='11'][value='zzzz']").attr ("checked", "checked");