[Greasemonkey] Calling a page-defined function

Joe la Poutre jsixpack at gmail.com
Mon Aug 14 14:50:30 EDT 2006


Cool (I was wondering if the click-receiver must be of a certain type,
but that would be rather weird, as every element is valid to add an
inline onclick attribute to).

On 8/14/06, Gary Tyler <pile0nades at gmail.com> wrote:
> Nevermind I got it, I forgot the // at the start of the xpath expression
>
> On 8/14/06, Gary Tyler <pile0nades at gmail.com> wrote:
> >
> > // ==UserScript==
> > // @name           Fix DaV5 full view
> > // @namespace      http://pile0nades.wordpress.com/
> > // @description    Makes the image full view when on pages with /view/ in
> > the address
> > // @include        http://*.deviantart.com/view/*
> > // @include        http://deviantart.com/view/*
> >
> > // ==/UserScript==
> >
> > (function() {
> >
> >   var deviation = get("span[@id='zoomed-out']/a").snapshotItem(0);
> >   //alert(deviation.nodeName);
> >
> >
> >   var evt = document.createEvent("MouseEvents");
> >   evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false,
> > false, false, false, 0, null);
> >   deviation.dispatchEvent(evt);
> >
> >
> >   // xpath function
> >   function get(query) {
> >     return document.evaluate(
> >       query,
> >       document,
> >       null,
> >       XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
> >       null
> >     );
> >   }
> >
> > })();
> >
> > This is my whole script. I get Error: deviation.dispatchEvent is not a
> > function
> >
> >
> > On 8/14/06, Joe la Poutre <jsixpack at gmail.com> wrote:
> > >
> > > On 8/14/06, Gary Tyler < pile0nades at gmail.com> wrote:
> > > [...]
> > >
> > > > I also tried to fire the onclick event that zooms in, but I can't find
> > > the
> > > > method to fire it.
> > > >
> > > >   var deviation = get("span[@id='zoomed-out']/a");
> > > >   deviation.click();
> > > >
> > > > This does not work. How do you fire an element's onclick event? Or,
> > > get to
> > > > Deviation.zoomIn() without using unsafeWindow?
> > >
> > > You can dispatch a click event in the following way:
> > >
> > >         var clickElement = document.getElementById('someId);
> > >
> > >         var evt = document.createEvent("MouseEvents");
> > >         evt.initMouseEvent("click", true, true, window,
> > >                         0, 0, 0, 0, 0, false, false, false, false, 0,
> > > null);
> > >
> > >         clickElement.dispatchEvent(evt);
> > >
> > > HTH!
> > > _______________________________________________
> > > Greasemonkey mailing list
> > > Greasemonkey at mozdev.org
> > > http://mozdev.org/mailman/listinfo/greasemonkey
> > >
> >
> >
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list