Skip to content

Instantly share code, notes, and snippets.

Created December 13, 2008 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/35464 to your computer and use it in GitHub Desktop.
Save anonymous/35464 to your computer and use it in GitHub Desktop.
undefined
// ==UserScript==
// @name Hateda Poster
// @namespace http://web.zgo.jp/
// @description はてなダイアリーポスト機構
// @include *
// ==/UserScript==
var v = GM_getValue("W-SSE");
function Requester(user, pass){
this.user = user;
this.pass = pass;
}
Requester.prototype = {
post : function (tag, title, comment, callback){
var postURI = "http://d.hatena.ne.jp/"+this.user+"/atom/blog";
tag = (tag.length == 0) ? "" : "["+tag.join("][")+"]";
comment = (comment.length == 0) ? "" : comment;
GM_xmlhttpRequest({
method : "POST",
url : postURI,
data : this.template(tag, title, comment),
onload : callback,
headers : {
"Content-Type" : "application/atom+xml; charset=UTF-8",
"Accept" : "application/x.atom+xml, application/xml, text/xml, */*",
"X-WSSE" : this.wsseHeader(this.user, this.pass)
}
})
},
template : function (tag, title, comment){
var repuest = <entry xmlns="http://purl.org/atom/ns#">
<title>{tag}{title}</title>
<content type="text/plain">
{comment}
</content>
</entry>;
//GM_log(repuest);
return repuest.toString();
},
include : function (_win){
_win.eval(v);
this.wsseHeader = _win.wsseHeader;
return this;
}
}
if(typeof v == "undefined"){
GM_xmlhttpRequest({
method : "GET",
url : "http://reader.livedoor.com/js/wsse.js",
onload : function (response){
GM_setValue("W-SSE", response.responseText);
}
})
} else {
window.Hateda = Requester;
}
//.user.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment