I'm new to this list, and this is my first post.
I'm trying to fix the broken-in-Firefox JavaScript code of
http://www.yjobs.co.il/ , which uses outerHTML and other MSIE-specific
horrors. I'm trying to over-ride the function "SaveSelectBoxs()" that appears
in http://www.yjobs.co.il/in.js using Greasemonkey. This affects the upper
Find ("מצא") button.
Now, as I discovered if I put its new definition in the .user.js file, like
so:
{======================
function SaveSelectBoxs() {
var sSelects = "";
var nSelected = "";
.
.
.
}
======================}
(Occupying my entire script.)
The page still misbehaves. However, if I paste the new definition into the
Firebug script evaluation editor, and evaluate it, the find button starts
working.[1]
So what I figured out was that the in.js was evaluated *after* the .user.js
one, and so over-rided it. So I'm looking for a while to delay evaluating the
function to after all the JavaScript in the page completely loads and
compiles. Someone I talked with suggested I use a JS timeout, but that seems
like a kludge.
Any help would be appreciated. I couldn't find anything specifically about it
in the Greasemonkey book.
Regards,
Shlomi Fish
[1] - There are other errors that prevent the resultant page to be used
properly, but I figured out I can resolve them afterwards in a similar
manner.
---------------------------------------------------------------------
Shlomi Fish shl...@iglu.org.il
Homepage: http://www.shlomifish.org/
I'm not an actor - I just play one on T.V.
I don't know what you mean by "the" greasemonkey book, but you probably
mean Dive Into Greasemonkey, which was once /great/, but is now out of
date and largely wrong.
Read the wiki [1] and especially the article it links to [2] by the same
author as DiG and more up to date. That article answers the vast
majority of questions asked on this list.
(Hint: execution time is not your only/primary issue. Your primary
issue is that GM scripts execute in their own scope, separate from the
page.)
[1] http://wiki.greasespot.net/Main_Page
[2] http://www.oreillynet.com/lpt/a/6257
On Monday 05 November 2007, Anthony Lieuallen wrote:
> On 11/5/2007 11:11 AM, Shlomi Fish wrote:
> > Any help would be appreciated. I couldn't find anything specifically
> > about it in the Greasemonkey book.
>
> I don't know what you mean by "the" greasemonkey book, but you probably
> mean Dive Into Greasemonkey, which was once /great/, but is now out of
> date and largely wrong.
Yes, that's what I meant. I should note that it's still featured in
http://www.greasespot.net/ , and the Wiki was not featured in a place that I
noticed there. Perhaps these things ought to be fixed.
>
> Read the wiki [1] and especially the article it links to [2] by the same
> author as DiG and more up to date. That article answers the vast
> majority of questions asked on this list.
>
Thanks. I eventually found the solution to my problem here:
http://wiki.greasespot.net/Code_snippets#Embed_a_function_in_the_current_page
What I eventually did in my .user.js was:
<<<<<<<<<<<<<<<
function SaveSelectBoxs() {
// SNIPPED
}
function embedFunction(s) {
document.body.appendChild(document.createElement('script')).innerHTML=s.toString().replace(/([\s\S]*?return;)
{2}([\s\S]*)}/,'$2');
}
embedFunction(SaveSelectBoxs);
>>>>>>>>>>>>>>>
This made it work.
I'll fully read http://www.oreillynet.com/lpt/a/6257 later.
> (Hint: execution time is not your only/primary issue. Your primary
> issue is that GM scripts execute in their own scope, separate from the
> page.)
>
OK.
Regards,
Shlomi Fish
A note - please format your message more properly. Use linebreaks between
paragraphs, etc. And use proper capitalisation.
On Tuesday 06 November 2007, chaichana nilwatchararang wrote:
> hi ! this is my first post too :)
> hope it'll help ...
It is helpful and would have helped if I hadn't read Anthony Lieuallen's
message and managed accordingly.
> greasemonkey run in a sandbox, not the same environment of the page...
> It will disappeared after everything is executed and no reference left
> to point to anything in gm script.
> so,your cannot define a function in your script because your function
> will gone after everything in your script has been executed.
> you must go with addEventListener to create a reference to your
> script ... so i can stay there in sandbox .
> =========
> for example::
> var elem=document.getElementById('a3');
> elem.addEventListener("click",SaveSelectBoxs2 , true);
> then write your own version of SaveSelectBoxs ....
That's not good enough because the function is called from other functions.
> =========
> or inject your own script in the original page
> example::
> var script = document.createElement("script");
> script.setAttribute('type','text/javascript');
> script.text="function SaveSelectBoxs(){alert('yo');}";
> document.body.appendChild(script);
That's what I eventually did, but while using .toString() and the
embedFunction() function from the snippets on the site.
Regards,
Shlomi Fish
> =========
> hope it will help ... someone correct me if i'm wrong
>
>
>
http://wiki.greasespot.net/UnsafeWindow
En/na Shlomi Fish ha escrit: