如何在页面上执行函数

How to execute function on page?

本文关键字:执行 函数      更新时间:2023-09-26

在下文中,我使用此页面进行测试 http://nitroflare.com/view/A71F0994E20F2E0/security-privacy.jpg

下面的脚本点击慢速下载并删除点击后显示的弹出广告。

而不是点击免费下载,它会首先弹出一个窗口,我想调用它的第二个点击函数,即

function () {
    $(this).hide();
    $("#CountDownTimerContainer").show();
    startFreeDownload();
}

我的脚本执行$("#CountDownTimerContainer").show()但由于某种原因没有执行startFreeDownload()

问题

如何调用页面上的startFreeDownload()

// ==UserScript==
// @name        NitroFlare
// @namespace   https://nitroflare.com/
// @description https://nitroflare.com/
// @include     https://nitroflare.com/*
// @version     1
// @grant       none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @require https://greasyfork.org/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=115012
// ==/UserScript==
function SkipId(objId){
  var oId = document.getElementById(objId);
  oId.click();
}
window.onload = function(){
  SkipId('slow-download');
};
waitForKeyElements("div.superbox-wrapper", removeSuperbox);
function removeSuperbox() {
  document.getElementById('superbox-wrapper').hide();
}
$("#CountDownTimerContainer").show();
startFreeDownload();

document.getElementById返回一个DOM节点,该节点没有hide()方法。

要么手动使用 jQuery: $('#superbox-wrapper').hide(),要么使用 waitForKeyElements,如其示例所示:

function removeSuperbox(jNode) {
  jNode.hide();
}

此外,由于您将自己的jQuery注入页面并使用@grant none如果站点有自己的jQuery,则可能需要使用jQuery.noConflict((。

(function (){
    $("#CountDownTimerContainer").show();
    console.log(0);
    startFreeDownload();
})();
function startFreeDownload(){
  console.log(1);
}

试试这个它应该对你有用。