Skip to content

Instantly share code, notes, and snippets.

@cho45
Created August 7, 2008 14:55
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 cho45/4419 to your computer and use it in GitHub Desktop.
Save cho45/4419 to your computer and use it in GitHub Desktop.
ダイアリの編集API適当にたたく
var url = "http://cho45.g.hatena.ne.jp/cho45/";
var s = {};
next(function getRkm () {
return xhttp.get(url).
next(function (r) {
s.rkm = r.responseText.replace(/^[\S\s]*Hatena\.rkm\s*=\s*(?:'([^']+)'|"([^"]+)")[\S\s]*$/, function (_, v1, v2) {
return v1 || v2;
});
});
}).
next(function postDiary () {
log(s.rkm);
return xhttp.post(url, toData({
entry_key : "new",
rkm : s.rkm,
title : "[test] xhr",
body : "test"
}));
function toData (q) {
var ret = [];
for (var k in q) if (q.hasOwnProperty(k)) {
ret.push(encodeURIComponent(k) + "=" + encodeURIComponent(q[k]));
}
return ret.join("&");
}
}).
error(function (e) {
alert(e);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment