I'm using Tampermonkey (the same as Greasemonkey, but for Chrome) to make a script. The idea is to paste the text I write into Pastebin. The text was written in other website. I saw I can do it using GM_xmlhttpRequest, but it doesn't work. This is my code:
var charac = new Array(50);
var i =0
function callkeydownhandler(evnt) {
var ev = (evnt) ? evnt : event;
var code=(ev.which) ? ev.which : event.keyCode;
charac[i]= code;
i++;
}
if (window.document.addEventListener) {
window.document.addEventListener("keydown", callkeydownhandler, false);
} else {
window.document.attachEvent("onkeydown", callkeydownhandler);
}
GM_xmlhttpRequest({
method: "POST",
url: "http://pastebin.com/post.php",
data: "user=mysuser&password=mypassword", //as you can imagine I use my credentials
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
onload: function(response) {
alert("posted");
document.getElementById("paste_code").value+=charac[i];
document.getElementById("submit").click();
}
});
I'm sure the two last lines are not working properly, but I don't know why. The first function works perfect.
What am I doing bad? How can I fix it?
Thank you! =)