You could have your script listen for a 'keyup' event, but you would
have to make sure you release the key after the DOM for the page has
finished loading, of which there is no visual indication.
Why don't you just add a button to the page to run the script? E.g.
function Main(){
GM_addStyle('.myButtonDiv {color: black; background-color: pink}');
var div = document.createElement('div');
div.setAttribute('class', 'myButtonDiv');
div.innerHTML = '<input type="button" value="click to run
MyScript">';
document.body.insertBefore(div, document.body.firstChild);
div.firstChild.addEventListener('click', runMyScript, true);
}
function runMyScript(){alert('script running');}
Main();
If you still want to go with 'keyup', you could have Main visually
alter the page so you would know when you should release the key.
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.