1
Greasemonkeyを使用してクラスの値を変更する方法はありますか?単純な静的ページについてGreasemonkeyを使用してクラス値を変更しますか?
<a id="Test" class="button_primary button_left_padding tlignore enabled" role="button"
Greasemonkeyを使用してクラスの値を変更する方法はありますか?単純な静的ページについてGreasemonkeyを使用してクラス値を変更しますか?
<a id="Test" class="button_primary button_left_padding tlignore enabled" role="button"
とid="Test"
はユニークかつ安定していると仮定して、以下のようなコードは動作します:
<a id="Test" class="button_primary button_left_padding tlignore disabled" role="button"
へ:
例えば、私は変更したいですAJAX-Dについてはvar targNode = document.getElementById ("Test");
targNode.classList.remove ("disabled");
targNode.classList.add ("enabled");
この完全なスクリプトは動作します:
// ==UserScript==
// @name _Flip CSS classes
// @match http://YOUR_SERVER.COM/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 restore the proper sandbox.
waitForKeyElements ("#Test", swapClass);
function swapClass (jNode) {
jNode.removeClass ("disabled").addClass ("enabled");
}