3

Trying to eliminate the annoying default autoplay feature on Site-Which-Must-Not-Be-Named I made a custom JavaScript for Opera 12.17 (Presto):

setInterval(function(){
    var ap = document.getElementById('autoplay-checkbox');
    if ((ap) && (ap.checked === true)) ap.click();
},
500);

setInterval is here because I do not want to deal with window.load and similar handlers and I am not sure about the moment when the checkbox is being created and initialized.

The script worked for a very long period of time, but now, after I turned Opera cookies off for Site-Which-Must-Not-Be-Named, getElementById returns null according to console.log. It simply cannot find the checkbox, although when executing

var ap = document.getElementById('autoplay-checkbox');
ap.click();

in DragonFly console, it works well. I turned cookies on, and again - JS cannot find the checkbox.

What is happening?

Update

I am completely lost in doubt: the script works on some content pages, especially when loaded by direct links, but doesn't work on other pages (with equal layout).

Paul
  • 25,812
  • 38
  • 124
  • 247
  • The "site which must not be named" - is this a well-known domain or your own? I feel that a large part of this question depends on whether that site is removing the box from the document or not. – Ben Apr 07 '15 at 19:41
  • and have you tried window.onload ? – webduvet Apr 07 '15 at 19:41
  • That box may be in an iframe, might be removed from the DOM, might have its ID updated post-load, a lot of things could be happening. Need more info. – Ben Apr 07 '15 at 19:41
  • 2
    @Steve: a well-known one. I am afraid that if they find my "hack", they could invent something smarter. – Paul Apr 07 '15 at 19:42
  • @webduvet: `and have you tried window.onload?` Of course! – Paul Apr 07 '15 at 19:43
  • `might have its ID updated post-load`. setInterval should handle this. – Paul Apr 07 '15 at 19:44
  • These commands are working in Chrome. Have you tried increasing the interval, just for the sake of extra dummy testing? – Bruno Toffolo Apr 07 '15 at 19:45
  • 3
    PS: Upvoted for *Site-Which-Must-Not-Be-Named* – Bruno Toffolo Apr 07 '15 at 19:45
  • You know that `(ap.checked === true)` is the same as `ap.checked`, right? – blex Apr 07 '15 at 19:46
  • @Bruno Toffolo: They worked in Opera 30 minutes ago and work now when copy-pasted into console. P.S. The custom script is being loaded and executed. – Paul Apr 07 '15 at 19:50
  • In the console: Do you see the id? Is there an iframe in play? – epascarello Apr 07 '15 at 19:53

0 Answers0