Thanks for all of the suggestions. I'll play with these ideas and see
if I can get any to work for my needs.

On Jan 9, 5:58 am, esquifit <[email protected]> wrote:
> There are many options depending on whether your script can run
> *after* the page has loaded, or if it has necessarily to run right
> before the load event (that is, right after the DOMContentLoad event).
>
> In the first case ('late invocation possible') you can just use a
> bookmarklet if your script doesn't make use of any GM_ API function.
> If it does, you can register the function to run as a GM menu
> command(see[1]) and call it whenever you want.
>
> In the second case ('script must run during or right before load
> event'), the suggestions of Rod apply.  Particularly the '#' hack
> seems more useful than depending on a given key being pressed during
> load, since you'll never have full control of the latter and it is
> somewhat uncomfortable.
>
> You can even combine the suggestions above and make a bookmarklet/GM
> menu command to modify all eventual links to current page by adding
> the '#' part that will trigger/disable the script if the link is
> navigated to.  In this way you avoid running a links-scrapping script
> on all pages with the associated lost of performance.
>
> [1]http://wiki.greasespot.net/GM_registerMenuCommand
>
> On Fri, Jan 8, 2010 at 9:41 PM, RodMcguire <[email protected]> wrote:
> > Whoops. Premature posting above
>
> > Another approach is to run a script on all pages that contain links to
> > the pages your script runs on, and it alters the links when say shift
> > is pressed and restores them when shift is released. Say your script
> > runs on urls like 'http://example.com/foo33.htm'. The script alters
> > this link to 'http://example.com/foo33.htm#runMyFunkyScript'when the
> > shift key is depressed.
>
> > Then put the following test at the top of your original script.
> >  if (document.location.hash != '#runMyFunkyScript') return;
>
> > Here is how to alter the links. In the below example you will want to
> > taylor the XPath inside the document.evaluate to select only links
> > your script runs on.
>
> > function doDown(e){
> >  if (e.keyCode != 16) return; // not shift key
> >  for (var i = 0; i < aSnap.snapshotLength ; i++)
> >  aSnap.snapshotItem(i).hash = '#runMyFunkyScript';
> > }
> > function doUp(e){
> >  if (e.keyCode != 16) return;
> >  for (var i = 0; i < aSnap.snapshotLength ; i++)
> >  aSnap.snapshotItem(i).hash = '';
> > }
> > window.addEventListener('keydown', doDown, true);
> > window.addEventListener('keyup', doUp, true);
> > aSnap = document.evaluate(
> >  "//a[starts-with(@href, '/group/greasemonkey')]",
> >  document.body, null,
> >  XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
>
> > On Jan 7, 5:45 pm, ddistelhorst <[email protected]> wrote:
> >> I have a GM script that works great for a given web page. However,
> >> there are sometimes that I want the script to run and other times that
> >> I don't want it to run. I don't like to enable/disable GM all time
> >> since I use GM on other web pages all the time.
>
> >> What I would like to do is to only execute the script if I'm pressing
> >> a certain key (maybe the left shift key) when the web page loads. That
> >> way I could control whether the script executes or not based on the
> >> keypress and then I don't need to enable/disable GM all the time.
>
> >> How would I modify my script to only execute if a certain key is
> >> pressed during the web page load?
-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en.


Reply via email to