admin管理员组文章数量:1332383
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: ".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! =)
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./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! =)
Share Improve this question asked Mar 9, 2013 at 16:28 Victor BuendíaVictor Buendía 47111 silver badges21 bronze badges1 Answer
Reset to default 6I developed a simple API that does exactly what you want.
Includes : Persist BETA
Pastebin has an API, but it currently doesn't support editing posts.
That is why I needed to create two different "services" specific to pastebin... PASTEBIN and PASTEBIN2
If you don't need editing, use PASTEBIN. Otherwise, use PASTEBIN2.
The first thing you will need is an Unique Developer API Key.
Then you will need an User API Key.
Here are some examples of usage of my script:
Creating a new post
Persist.write({
service : "PASTEBIN",
value : "...",
data : {
api_dev_key : "...",
api_user_key : "...",
},
onload : function (result) {
alert("http://pastebin./" + result.key);
}
});
Editing an existing post
Persist.write({
service : "PASTEBIN2",
mode : -1, // prepend
key : "..."
value : "...",
data : {
api_dev_key : "...",
api_user_key : "...",
},
onload : function (result) {
alert("Post #" + result.key + "\nNew value: " + result.value);
}
});
Reading an existing post
Persist.read({
service : "PASTEBIN",
key : "..."
data : {
api_dev_key : "...",
api_user_key : "...",
},
onload : function (result) {
alert("\nValue: " + result.value);
}
});
本文标签: greasemonkeyHow to paste text in Pastebin using JavaScriptStack Overflow
版权声明:本文标题:greasemonkey - How to paste text in Pastebin using JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742303035a2449371.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论