あなたはAJAX呼び出しのために聞くことができますが、それは、ターゲットページに応じて、過度に複雑になります。野生ページのAJAX-ifiedコンテンツを取得するための最も強力な方法は、それをポーリングすることで、そのように:あなたは必要ないかもしれないので、
function myCode (jNode) {
//YOUR CODE HERE
var damageMessage = jNode.text();
//...
}
waitForKeyElements (".mw_error", myCode, false, "iframe");
function waitForKeyElements (
selectorTxt, /* Required: The jQuery selector string that
specifies the desired element(s).
*/
actionFunction, /* Required: The code to run when elements are
found. It is passed a jNode to the matched
element.
*/
bWaitOnce, /* Optional: If false, will continue to scan for
new elements even after the first match is
found.
*/
iframeSelector /* Optional: If set, identifies the iframe to
search.
*/
)
{
var targetNodes, btargetsFound;
if (typeof iframeSelector == "undefined")
targetNodes = $(selectorTxt);
else
targetNodes = $(iframeSelector).contents()
.find (selectorTxt);
if (targetNodes && targetNodes.length > 0) {
/*--- Found target node(s). Go through each and act if they
are new.
*/
targetNodes.each (function() {
var jThis = $(this);
var alreadyFound = jThis.data ('alreadyFound') || false;
if (!alreadyFound) {
//--- Call the payload function.
actionFunction (jThis);
jThis.data ('alreadyFound', true);
}
});
btargetsFound = true;
}
else {
btargetsFound = false;
}
//--- Get the timer-control variable for this selector.
var controlObj = waitForKeyElements.controlObj || {};
var controlKey = selectorTxt.replace (/[^\w]/g, "_");
var timeControl = controlObj [controlKey];
//--- Now set or clear the timer as appropriate.
if (btargetsFound && bWaitOnce && timeControl) {
//--- The only condition where we need to clear the timer.
clearInterval (timeControl);
delete controlObj [controlKey]
}
else {
//--- Set a timer, if needed.
if (! timeControl) {
timeControl = setInterval (function() {
waitForKeyElements ( selectorTxt,
actionFunction,
bWaitOnce,
iframeSelector
);
},
500
);
controlObj [controlKey] = timeControl;
}
}
waitForKeyElements.controlObj = controlObj;
}
、GreasemonkeyのものiFrame上で実行できることに注意してくださいスクリプトの目的に応じて、あなたがiFrameにいるかどうかを知る以外のことをする。
逆に、計画していないときにGMスクリプトがiFrame URLで起動すると、予期しない結果が発生する可能性があります。例えば
、あなたはURL_Aでこのページ持っていたとします
<body>
<iframe src="URL_B"></iframe>
</body>
をそしてGMスクリプトの// @include
ディレクティブ(s)は、両方のURL(// @include URL_*
など)をカバーしました。
スクリプトにちょうどalert ('Script start.');
がある場合、ページを読み込むと2つの警告が表示されます。
GMスクリプトの指示文を使って、iframeが読み込まれたときにのみ実行しました。私はスクリプトを編集し、iframeパラメータを取り出し、今すぐ治療を行います。 :) –
優れています。うれしいです。 –
それはいくつかの平均的なコードのボスです。 +1 – Tim