[Greasemonkey] Changing <SCRIPT> elements on a page.

Jason Petry jpetry at gstisecurity.com
Mon Dec 19 14:27:40 EST 2005


I'm trying to figure out why the relatively simple test case below  doesn't work like I would like. When I run this, the script element  still runs, and the alert box shows. After clicking ok in the  messagebox, the replacement text is inserted, but the script has  already run. Is it possible to subvert this with greasemonkey, so that  the alert is never displayed? 
  
  
  Sample HTML page:
  -------------------------------------------------------------
  <html> <head><title>Test Page</title></head>
  
  <body>
  <h1>This is a test page</h1>
  <script>
  alert("Test");
  </script>
  </body> </html>
  -------------------------------------------------------------
  
  Sample user script:
  -------------------------------------------------------------
  var s, newText;
  s = document.getElementsByTagName('script');
  for (var i = 0; i < s.length; i++) {
      newText = document.createElement('p');
      newText.innerHTML = 'Test Replacement';
      s[i].parentNode.replaceChild(newText,s[i]);
  }
  -------------------------------------------------------------
  


More information about the Greasemonkey mailing list