replace javascript code on the fly

288 views
Skip to first unread message

Console

unread,
Jul 12, 2012, 6:15:15 PM7/12/12
to greasemon...@googlegroups.com
I want to immediately change this javascript value on the fly before it redirects me to the page with grease monkey. I am a novice on grease monkey and spent quiet of a few hours reading and experimenting with no luck, if anyone can give me a helping hand on this I would appreciate it. This is the code I want to replace:

" <input id="quantity_1" name="quantity_1" type="hidden" value="20.00" /> "

to

" " <input id="quantity_1" name="quantity_1" type="hidden" value="25.00" /> "

If any more info is needed let me know, thank you in advance.

Hans Henrik Bergan

unread,
Jul 20, 2012, 2:54:34 PM7/20/12
to greasemon...@googlegroups.com
// @run-at document-start
function f(){
try{
document.getElementById('quantity_1').value="25.00";
}catch(e){setTimeout(f,5);}
}
f();


will use some cpu (until it has done it's task), and its quite hackish, but i guess i think it should work

Brian L. Matthews

unread,
Jul 20, 2012, 4:40:57 PM7/20/12
to greasemon...@googlegroups.com
So if the page changes in the future to not have a quantity_1 element, greasemonkey will run f every 5 milliseconds... forever. Yeah, f is small and quick, but even small and quick at 200 times per second, doing something that will never succeed, seems bad.

Brian
--
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/greasemonkey-users/-/6tZm8EInLGcJ.
To post to this group, send email to greasemon...@googlegroups.com.
To unsubscribe from this group, send email to greasemonkey-us...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en.

Message has been deleted

Hans Henrik Bergan

unread,
Jul 21, 2012, 8:10:35 PM7/21/12
to greasemon...@googlegroups.com

hello critic :p
remember that it must run fast - he expects to be redirected nearly asap.
how about this code then?
// @run-at document-start
(function f(){
var e=document.getElementById('
quantity_1');
if(e!==null)
{
e.value="25.0";return;
}
if(document.readyState=='
complete'){return;}
setTimeout(f,200);
})();


On Friday, 20 July 2012 22:40:57 UTC+2, blm wrote:
So if the page changes in the future to not have a quantity_1 element, greasemonkey will run f every 5 milliseconds... forever. Yeah, f is small and quick, but even small and quick at 200 times per second, doing something that will never succeed, seems bad.

Brian

On 7/20/12 11:54 AM, Hans Henrik Bergan wrote:
// @run-at document-start
function f(){
try{
document.getElementById('quantity_1').value="25.00";
}catch(e){setTimeout(f,5);}
}
f();


will use some cpu (until it has done it's task), and its quite hackish, but i guess i think it should work
On Friday, 13 July 2012 00:15:15 UTC+2, Console wrote:
I want to immediately change this javascript value on the fly before it redirects me to the page with grease monkey. I am a novice on grease monkey and spent quiet of a few hours reading and experimenting with no luck, if anyone can give me a helping hand on this I would appreciate it. This is the code I want to replace:

" <input id="quantity_1" name="quantity_1" type="hidden" value="20.00" /> "

to

" " <input id="quantity_1" name="quantity_1" type="hidden" value="25.00" /> "

If any more info is needed let me know, thank you in advance.
--
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/greasemonkey-users/-/6tZm8EInLGcJ.
To post to this group, send email to greasemonkey-users@googlegroups.com.
To unsubscribe from this group, send email to greasemonkey-users+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages