I´m trying to add hotkeys to the web application we use at work. The solution was to apply a Greasemonkey script, but the web system uses Liferay Portal, which is made with JavaX and jspx server applets.
I DON´T KNOW HOW TO APPLY "WAITFORKEYELEMENTS" answer, my knowledge is not that advanced.
What is the problem? I need to search the label for a link, i.e. “case file history” , add a keylistener event and simulate a mouse click. Here´s an example link:
<a id="form1:commandLink1211" name="form1:commandLink1211"
onclick="submitForm('form1',1,{source:'form1:commandLink1211'});
return false;"
class="linkMenu" href="#">
Look case file history
</a>
I need it to simulate a mouse click into this link, but the getElementById returns null. The page loads “empty” and then loads the jspx module. I know greasemonkey puts the script first. I tried to use
window.onload=funcion
document.ready() //didn´t know how to add this to my code
Other solutions include using a timer, but I don´t know how to apply it.
Current greasemonkey script:
(function(){
document.addEventListener('keydown', function(e) {
// pressed alt+g
if (e.keyCode == 71 && !e.shiftKey && !e.ctrlKey && e.altKey && !e.metaKey)
{
console.log ("key pressed");
document.getElementById('form1:commandLink1211').click();
}
}, false);
})();