views:

29

answers:

2

Hi! I want to stop the execution of one single line from a site, so that the whole page is read by the browser except that single line. Or the browser may simply skip the execution of that javascript function.

OR

Is there way i can tweak the javascript somehow so that the random number generating function in javascript do not generate random number, but the numbers i want...

I dont have access to the site on which the script is hosted so all this needs to be done client side.

A: 

You can use what is called a bookmarklet.

Build the js file you want to run on the other site: your.js

Make an HTML page with the following code:

<html>
<body>
  <a href="javascript:(function(){var s=document.createElement('SCRIPT');s.src='/url/to/your.js?'+(Math.random());document.getElementsByTagName('head')[0].appendChild(s);})()">
    Drag'n Drop this to your bookmarks
  </a>
</body>
</html>

Replace /url/to/your.js with the path of your js file.

Load that small page in your browser and drag'n drop the link to your bookmark bar.

Go to the web site you want to hack, and click the bookmark you just created.
This will load your.js in the page and run the code.

Note: the ?'+(Math.random()) part is to avoid your js being cached, this is not mandatory but it is helpful when you develop your.js

Mic
A: 

The answer depends on details which were not provided (The exact page and line of code would be best), but here's how you do it in general:

  1. If the offending JS code does not fire right away (Fires after DOMContentLoaded), then you can use Greasemonkey to replace the offending code.   EG:

    var scriptNode          = document.createElement ("script");
    scriptNode.textContent  = "Your JS code here";
    document.head.appendChild (scriptNode);
    

    Done.

  2. If the JS code fires immediately, then it gets more complicated.
    First, grab a copy of the script and make the desired change to it. Save this locally.

  3. Is the offending script in a file or is it in the main page HTML (<script src="Some File> versus <script>Mess O' Code</script>)?

  4. If the script is in a file, install Adblock Plus and use it to block loading of that script. Then use Greasemonkey to add your modified code to the page. EG:

    var scriptNode          = document.createElement ("script");
    scriptNode.setAttribute ("src", "Point to your modified JS file here.");
    document.head.appendChild (scriptNode);
    
  5. If the script is in the main HTML page, then install either NoScript (best) or YesScript and use it to block JavaScript from that site.
    This means that you will then need to use Greasemonkey to replace all scripts, from that site, that you do want to run.

Brock Adams