Prevent js file from running

Asked

Viewed 233 times

0

I would like to know how to prevent or modify a file . js of a site when running in my browser. The site has the following code

<script type="text/javascript" src="scripts/play.html.js?_v=1.1.1">

This play.html.js script, causes when a video on the page loses focus, it pauses. Every time I open the window it changes the body attribute of <body class="visible"> for <body class="hidden">, I use two monitors on my pc, and would like to leave the video playing on one monitor while I move the other.

How can I change this site function ?

  • Already tried to manipulate tag element <video>?

  • 3

    @downvoters: why downvote? the question seems legitimate.

  • Yes, the page code does not contain the <video> tag everything is done via jquery. And the video is placed inside the video-container div. Only thing that really changes the page code are the body’s attribute changes.

1 answer

2


You can make a user script to change the functioning of the site, using the extension Greasemonkey (if you use Firefox) or Tampermonkey (if you use Chrome), which reverses what the play.html.js does, with something like:

var body = document.getElementsByTagName('body')[0];
var classes = body.className.split(' ');
if (classes.indexOf('hidden') >= 0){
    classes.pop('hidden');
    classes.push('visible');
    body.className = classes.join(' ');
}

You will probably need to make some modification to this script, limit to running only on the correct domain and page, but the way is this.

  • It was one of the first things I tried, I even looked at some gringo code to try to solve it, but it didn’t work. I tried to make the script as your own and the body class keeps changing. The script: http://pastebin.com/w64qpaWR

  • Hmm, it’s likely that the script on play.html.js is running after user script. Try doing with a: setInterval(function(){ /* codigo aqui dentro */ }, 3000); -- that will be checking every 3s. It is half Gambi, but should already break the branch.

  • @user3017878 got tested? it worked?

  • I tested it. That’s exactly what it was, I spent the whole afternoon yesterday cracking my head to figure it out and I wasn’t going to. Thank you very much. The only problem is that it stops every 3 seconds, there would be no way to execute my script before play.html.js?

  • @user3017878 You’re welcome! = ) So you want to actually run your script afterward of play.html.js (if you run before it will overwrite, which is what is happening). You can just try to change the setInterval for setTimeout and increase the delay (maybe 5000) to make it run after the play.html.js. I don’t know if you can guarantee that.

  • I was thinking of another solution, such as replacing . pause() with . play(). Or whenever a . pause() is executed, executing a . play(). The problem is making the script, I don’t know how to catch the event . pause and I don’t know the id of the video element.

  • You tested with the setTimeout() and it didn’t work?

  • It worked, but I wanted to see if it was possible to modify the pause function, I wanted to learn a little more about GM and javascript functions. You can make a script to exchange a . pause() for . play() or run a . play() after a . pause() ?

  • @user3017878 Look, there will depend on how this is implemented, you will have to read and understand the code of play.html.js to know. If it is very encapsulated, it can be difficult. Well, if my answer helped, you can mark it as accepted (in the V below the option to vote). =)

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.