Is there a way to stop a JS process through injected JS?

129 Views Asked by At

There's a website I need to check at constant intervals but it has certain JS functions programmed into it that are more aesthetic than anything else, and the result is that it eats up my CPU for no good reason, not to mention that it adds 1-2 seconds of time for the DOM to be ready, when I need it to load as quickly as possible.

For instance, the website displays several elements on it, each in its own wrapper. Each element has a title, which may be long or short. So instead of just letting the title run on and be cut off by the border (as the overflow is hidden as per the original CSS) it parses all the titles and then trims them, adding an ellipsis at the end. Now, this is purely aesthetic, of course, as you still have no access to the part of the title that's cut of, so it's the same if you just let it be cut off "behind" the hidden overflow. On the other hand, having to take care of each title element (sometimes there may even be 100 elements on screen at a time) uses up a lot of time and resources.

There are several other instances such as this one. And my question is: is there any way I can inject some JS on my side that overrides or cancels such functions as the one that affects the titles as I've described?

P.S. The website in question uses also jQuery. I don't know if that detail makes any difference.

1

There are 1 best solutions below

0
On

You can't "stop a JS process" per-se (your injected javascript will be running in the same process), but you might be able to interfere with it.

Find a function which does the thing you want to stop, and just overwrite it with an empty function:

some.object.in.the.other.code.doSomething = function() {}

Note that you will need to ensure that your code injection occurs before the other script is executed. If this is not feasible, you will have to find some function further up in the call stack which will be executed after your injected script.