Can somebody please help me

Subscribe to Can somebody please help me 12 posts, 4 voices

 
rainworm Scriptwright

I'm new with greasemonkey and am trying to do some simple greasemonkey scripting.

On the site http://www.hattrick.org/Common/menu.asp
I'm trying to auto fill the username and then set focus on the password field.
I managed the first part... but the focus part gives me trouble.

For focusing I have used the following code;

object = document.getElementsByName('password');
object[0].focus();

but if you take a look at the HTML source code... there is body onload event that calls some javascript that sets focus to username field.

I tried to change the innerHTML as shown below;

html_code = document.getElementsByTagName('html');
html_code[0].innerHTML = html_code[0].innerHTML.replace('<body>','<body>');
</body>

but it didn't work..
I also tried to change the javascript sf() with the same method;

script_code = document.getElementsByTagName('script');
script_code[0].innerHTML = script_code[0].innerHTML.replace('document.login.loginname.focus();','document.login.password.focus();');

but that didn't work ither..

I'm stuck and I need help/advice/solution;) please help me.

 
Mikado Scriptwright

document.getElementsByName('loginname')[0].value = 'login';
document.getElementsByName('password')[0].focus();
document.body.setAttribute('onload', null);

 
rainworm Scriptwright

thank you for a simple solution.
I see now that I was complicating things :)

 
Descriptor Scriptwright

You just didn't understand the difference between getElementsByTagName and getElementsByName.

 
rainworm Scriptwright

I don't agree with that.. I do understand the difference between getElementsByTagName and getElementsByName.
My approach to resolving this was just different than Mikados.
I tried to change the HTML of the specific tags.. in my case html tag or script tag.
Mikado used the different approach... he changed the onload event of body.
I tried to do it hard way because I wasn't familiar with the setAttribute and Mikado shown me that the simple solutions are the best ;)

 
Descriptor Scriptwright

Then why did you expect object = document.getElementsByTagName('password'); to do anything?

 
rainworm Scriptwright

I was writting the code here without using copy/paste from an actual script and made a mistake.
Didn't even noticed it until your last post :)

 
rainworm Scriptwright

ha! I even corrected the mistake now ;)

 
Descriptor Scriptwright

Maybe I should delete my comments then :0

 
rainworm Scriptwright

You don't have to.. let it be written in the history :)

 
lazyttrick Scriptwright

hey i have some scripts for hattrick, but its been a long time i dont log in, my team is so dead i dont even wanna see it... as i may feel sad :(

nice idea your script!

 
rainworm Scriptwright

My team isn't doing well either. We were 5th in our league last season. But we won't give up and neither should you ;)