당신은 아약스 호출을 수신 할 수 있지만, 그 대상 페이지에 따라 지나치게 복잡해진다. 야생 페이지 아약스 - 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;
}
당신이 필요하지 않을 수 있도록 그리스 몽키는 Iframe을 실행할 수 있음을주의 스크립트의 목적에 따라 iFrame에 있다면 다른 것을하기 위해서입니다.
반대로, GM 스크립트가 계획되지 않은 경우 iFrame URL에서 실행되는 경우 예기치 않은 결과가 발생할 수 있습니다.
<body>
<iframe src="URL_B"></iframe>
</body>
을 그리고 GM 스크립트의 // @include
지침 (들) 두 URL (// @include URL_*
등) 적용 :
예를 들어
, 당신은 URL_A에서이 페이지를했다 가정합니다.
그런 다음 스크립트에 alert ('Script start.');
이있는 경우 페이지를로드 할 때 2 개의 경고가 표시됩니다.
GM 스크립트의 지시문을 사용하여 iframe이로드 될 때만 실행했습니다. 스크립트를 편집하고 iframe 매개 변수를 꺼내서 지금 치료를합니다. :) –
우수. 다행 이군요. –
그건 뜻밖의 코드 보스입니다. +1 – Tim