Skip to content

Instantly share code, notes, and snippets.

@javascripter
Created December 14, 2008 00:36
Show Gist options
  • Save javascripter/35587 to your computer and use it in GitHub Desktop.
Save javascripter/35587 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name FastLDR
// @namespace http://d.hatena.ne.jp/javascripter/
// @include http://fastladder.com/reader/
// ==/UserScript==
var native_post = unsafeWindow.API.prototype.post;
var api_key = null;
GM_xmlhttpRequest({
method: "GET",
url: "http://reader.livedoor.com/reader/",
onload: function (res) {
var m = res.responseText.match(/^var ApiKey = "(.*)";/m);
if (m) {
api_key = m[1];
} else {
unsafeWindow.message("API key not found.(Please login to LDR)");
}
}
});
unsafeWindow.API.prototype.post = function(param, onload){
if (/^\/api\/config\//.test(this.ap)) {
return native_post.apply(this, arguments);
}
var onload = onload || this.onload;
var oncomplete = this.onComplete;
if (typeof onload != "function") {
onload = function() {};
}
param.ApiKey = api_key;
setTimeout(GM_xmlhttpRequest, 0, {
method: "post",
url: "http://reader.livedoor.com/" + this.ap,
data: unsafeWindow.Object.toQuery(param),
headers: { "Content-Type" : "application/x-www-form-urlencoded" },
onload: function(res) {
oncomplete();
unsafeWindow.API.last_response = res.responseText;
var json = unsafeWindow.JSON.parse(res.responseText);
if (json) {
onload(json);
} else {
unsafeWindow.message("can't load data");
unsafeWindow.show_error();
}
}
});
this.onCreate();
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment