0

In the following I use this page for testing http://nitroflare.com/view/A71F0994E20F2E0/security-privacy.jpg

The below script clicks on Slow Download and removes the popup ad that shows up after the click.

Instead of clicking on Free Download, which will first popup a window, I want to call its second click function which is

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

My script executes $("#CountDownTimerContainer").show() but it doesn't execute startFreeDownload() for some reason.

Question

How can I call startFreeDownload() which is on the page?

// ==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();
Jasmine Lognnes
  • 6,597
  • 9
  • 38
  • 58

2 Answers2

2

document.getElementById returns a DOM node, which doesn't have hide() method.

Either use jQuery manually: $('#superbox-wrapper').hide() or use waitForKeyElements as shown in its example:

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

Also, since you're injecting your own jQuery into the page and use @grant none you may need to use jQuery.noConflict() if the site has its own jQuery.

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
  • The super-box is removed with the current script. I need to call `startFreeDownload()` somehow. – Jasmine Lognnes Nov 13 '16 at 14:12
  • It may just be a timing issue. Since you are using `@grant none`, try adding `startFreeDownload()` inside `removeSuperbox`, just after the `jNode.hide();` line. – Brock Adams Nov 13 '16 at 16:19
  • That didn't help. How does the script know `startFreeDownload()` is the one on the page and not a function that I (haven't yet) implemented have in my script? – Jasmine Lognnes Nov 13 '16 at 16:34
  • Look up javascript "scope". Anyway, there may be other requirements for that function. I'd look into it, but I'm not going to help (too much) someone violate the business model (and probably the TOS) for a site unless I know that the site really deserves it. – Brock Adams Nov 13 '16 at 16:54
  • @BrockAdams When you say scope do you mean `unsafeWindow()`? As for the business model for the site, I am sure it earns its money on piracy looking at http://nitroflare.com/affiliate . I doubt any content creator would be satisfied with only getting 10% of the pay. And anyone proud of their work won't have it distributed with popup ads. I only use it because I share files to myself on different locations where 1.2GB can be downloaded over night, so the speed isn't an issue for me. – Jasmine Lognnes Nov 13 '16 at 18:00
  • Look up "javascript scope". And no, you don't generally need `unsafeWindow` when the script operates in `@grant none` mode. – Brock Adams Nov 13 '16 at 23:00
  • @BrockAdams Ok, I am very stock here. Is it `window.startFreeDownload()` you mean? – Jasmine Lognnes Nov 14 '16 at 18:01
  • 1
    No. If that would work, the code I told you to try earlier would've worked. Your script is not setting up whatever requirements are needed for `startFreeDownload()`. Reread [this Q&A](http://stackoverflow.com/q/15048223/) for a more likely approach. Anywho, this is the last I will respond to questions on this particular website/subtopic. Good luck. – Brock Adams Nov 14 '16 at 19:27
0
(function (){
    $("#CountDownTimerContainer").show();
    console.log(0);
    startFreeDownload();
})();

function startFreeDownload(){
  console.log(1);
}

Try this It should work for you.

Andy
  • 29,707
  • 9
  • 41
  • 58