Using Javascript To Create A Keylistener Hotkey For Facebook Page "like"
I'm doing an art project for school where a user hugs an object and gets a 'liked' status on Facebook. Everything pretty much works; however, I need to set up a keyboard listener
Solution 1:
Here:
I created an HTML page with a function OtomatisLike()
in it.
<html lang="en">
<head>
<title>test - keylistener</title>
<script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function OtomatisLike() { alert('alert fired from html page') }
</script>
</head>
<body>
<button id="btnstart">click to start</button>
<script type="text/javascript">
$('#btnstart').click(function() { OtomatisLike() })
</script>
</body>
</html>
With GM disabled, you will see the alert say "alert fired from html page" when you click the button.
Then i created a greasemonkey script to change that function
// ==UserScript==
// @name TESTE 2
// @require http://code.jquery.com/jquery.min.js
// @include file://*
// ==/UserScript==
function OtomatisLike() { alert('alert fired from greasemonkey') }
unsafeWindow.OtomatisLike = OtomatisLike;
$(window).load(function(){
var isCtrl = false;
document.onkeyup=function(e) {
if(e.which == 17) isCtrl=false;
}
document.onkeydown=function(e){
if(e.which == 17) isCtrl=true;
if(e.which == 96 && isCtrl == true) {
OtomatisLike()
//alert('Keyboard shortcuts are cool!');
return false;
}
}
});
Now with GM enabled, you can click the button or press ctrl 0 to call the function OtomatisLike()
, which was replaced by the one in the script and now will alert "alert fired from greasemonkey".
Post a Comment for "Using Javascript To Create A Keylistener Hotkey For Facebook Page "like""