Hey PhistucK-
Thanks for the advice. I attempted what you said, and it partially
works, but I seem to be missing something. You will have to excuse me
as I'm a bit of a javascript/extensions/web development noob. I set up
the script to load at document_start, but I couldn't quite figure out
how to inject the script to the documentElement.
I have tried several solutions that provide some level of success.
What I mean by this is that I can overwrite the Math.random() and then
execute this from the javascript console, and my function returns
correctly. But when viewing an html page that already has source in it
for Math.random() it returns the original JS library version. I am
using the document_start as you suggested as well. The following are
some things that I have tried:
****** BEGIN CODE *******
// ==UserScript==
// @name Hello World
// @namespace
http://endomorph.cs.uiuc.edu
// @description example script to alert "Hello world!" on every page
// @include *
// @require
http://endomorph.cs.uiuc.edu/injection.js
// @run_at document_start
// ==/UserScript==
/*
* This function inserts the script after the head tag
*/
// This function works as well, but it doesn't overwrite the
function early
// enough to make calls in the body to ref our function.
var sc = document.createElement('script');
sc.setAttribute('type', 'text/javascript');
sc.setAttribute('charset', 'UTF-8');
sc.src = '
http://endomorph.cs.uiuc.edu/injection.js';
document.getElementsByTagName('head')[0].appendChild(sc);
//(document.body || document.head ||
document.documentElement).appendChild(sc);
//document.documentElement.appendChild(sc);
****** END CODE *******
I tried each of the three append methods (two are commented out)
Another attempt that overwrites, but not soon enough:
****** BEGIN CODE *******
/*
* The following is testing some function load methods
* This is in fact working correctly. The problem is that it isn't
overwriting
* the function prior to its initial execution.
*/
function main () {
// ...
Math.random = function() {return .9};
//alert('test');
// ...
}
var script = document.createElement('script');
script.appendChild(document.createTextNode('('+ main +')();'));
(document.body || document.head ||
document.documentElement).appendChild(script);
****** END CODE *******
Like I said each of these methods allows me to call Math.random() from
the javascript console,which returns my function. But when loading the
following webpage:
<html>
<head>
</head>
<body>
this is a test
<script>var a=Math.random();document.write("<br>"+a);</script>
<form>
<input type='text' onchange="alert('asdfasdf');"></input>
</form>
</body>
</html>
The call to random returns the original library function.
Thanks all-
::n::
On Nov 9, 12:48 am, PhistucK <
phist...@gmail.com> wrote:
> Either -
> Math = {random = function(){return 0}};
> Math.random = function(){return 0};
>
> Seems to work.
>
> If you run the content\user script at document_start and inject the script
> to the documentElement, does it still not work?
>
> ☆*PhistucK*
>
>
>
>
>
>
>
> On Tue, Nov 9, 2010 at 00:15, ndauten <
kainos...@gmail.com> wrote:
> > Hi All-
>
> > I need to use an extension or user script to overwrite any call to
> > Math.random() on web pages out of my control. The functionality I hope
> > to induce is that on any webpage I navigate to that each call to
> > Math.random() will call my function my.math.random(). I have attempted
> > to do this by injecting a .js file (using user scripts) into the
> > header of the page, but it appears as though it may not be overwriting
> > the standard library function. If I put my script directly into a page
> > it works correctly. I have tried using anonymous functions as well,
> > but to no avail.
>
> > Thanks for the help!
>
> > ::n::
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.
> > To post to this group, send email to
chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to
> >
chromium-extensions+unsubscr...@chromium.org<
chromium-extensions%2Bunsubscr...@chromium.org>
> > .