Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @name XMLRPC poster
// @namespace http://efcl.info/
// @include http://*
// ==/UserScript==
/* 投稿先のメタ情報 */
var metaBlog ={
"endPoint": "endPoint",
"blogid" : "blogid",
"username" : "username",//空だとblogidを使用
"password" : "password"
}
var XMLRPC = (function() { this.initialize.apply(this, arguments); });
XMLRPC.prototype = {
/*
* @arg
{
"endPoint": "endPoint",
"blogid" : "blogid",
"username" : "username",//空だとblogidを使用
"password" : "password"
}
*/
initialize : function(arg) { //引数は{}オブジェクト
this.endPoint = arg.endPoint;
this.blogid = arg.blogid;
this.username = (arg.username) ? arg.username : arg.blogid;
this.password = arg.password;
},
/* *
* @title 記事タイトル
* @desc 記事内容
* @tags タグ(カンマ区切り)
* @callback 更新成功時のコールバック関数
*/
post : function (title, desc, tags, callback){
var postURI = this.endPoint;
this.tags = (tags.length == 0) ? "" : tags.join(",");
var XMLbody = '<?xml version="1.0"?>\n';
XMLbody += this.template(title, desc , this.tags);
console.info(XMLbody);
GM_xmlhttpRequest({
method : "POST",
headers : {
'Content-type' : 'text/xml'
},
url : postURI,
data : this.template(title, desc , tags),
onload : callback,
})
},
template : function (title, desc , tags){
var repuest = <methodCall>
<methodName>metaWeblog.newPost</methodName>
<params>
<param>
<value>
<string>{this.blogid}</string>
</value>
</param>
<param>
<value>
<string>{this.username}</string>
</value>
</param>
<param>
<value>
<string>{this.password}</string>
</value>
</param>
<param>
<value>
<struct>
<member>
<name>title</name>
<value>
<string>{title}</string>
</value>
</member>
<member>
<name>description</name>
<value>
<string>{desc}</string>
</value>
</member>
<member>
<name>mt_keywords</name>
<value>
<string>{tags}</string>
</value>
</member>
<member>
<name>mt_allow_comments</name>
<value>
<boolean>1</boolean>
</value>
</member>
</struct>
</value>
</param>
<param>
<value>
<boolean>1</boolean>
</value>
</param>
</params>
</methodCall>;
return repuest.toString();
}
}
var t = new XMLRPC(metaBlog);
t.post(
"title",
"description",
["tag1","tag2"],
function(res){//callback
console.log(res);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.