// ==UserScript== // @name Hatena::Star Waste Color Star // @namespace http://lowreal.net/ // @include * // @require http://github.com/cho45/jsdeferred/raw/master/jsdeferred.userscript.js // ==/UserScript== // (function () { with (D()) { setTimeout(function () { var orig_JSONP = unsafeWindow.Ten.JSONP; var count = 0; var timer = new Deferred(); var executor = { queue : [], done : true, execute : function (fun) { var task = { fun: fun, deferred: new Deferred() }; this.queue.push(task); this._execute(); return task.deferred; }, _execute : function () { var self = this; if (!self.done) return self.done; var task = self.queue.shift(); if (!task) return self.done = true; task.fun().next(function (res) { task.deferred.call(res); self.done = true; self._execute(); }); return self.done = false; } }; unsafeWindow.Ten.JSONP = function (uri, obj, method) { if (uri.indexOf("http://s.hatena.ne.jp/star.add.json") == -1) return orig_JSONP(uri, obj, method); timer.cancel(); timer = wait(3).next(function () { count = 0; }); if (typeof(obj) == 'function' && typeof(method) == 'undefined') { obj = { callback: obj }; method = 'callback'; } var u = decodeURIComponent(uri.match(/\?uri=([^;&+]+)/)[1]); if (++count > 5) { executor.execute(function () { return addColorStar(u, "green"); }). next(function (s) { obj[method](s); }). error(function (e) { alert(e); }); } else { return orig_JSONP(uri, obj, method); } return null; }; for (var key in orig_JSONP) if (orig_JSONP.hasOwnProperty(key)) { unsafeWindow.Ten.JSONP[key] = orig_JSONP[key]; } }, 0); function toData (q) { var ret = []; for (var k in q) if (q.hasOwnProperty(k)) { ret.push(encodeURIComponent(k) + "=" + encodeURIComponent(q[k])); } return ret.join("&"); } function addColorStar(uri, color) { return next(function () { return xhttp.get("http://s.hatena.ne.jp/colorpalette?uri=" + encodeURIComponent(uri) + "&location=" + encodeURIComponent(location.href)). next(function (res) { var text = res.responseText; var token = text.match(/name="token" *value="([^"]+)"/)[1]; return token; }); }). next(function (token) { return xhttp.post("http://s.hatena.ne.jp/colorpalette", toData({ token: token, uri : uri, color: color })); }). next(function () { return xhttp.get("http://s.hatena.ne.jp/star.add.json?uri=" + encodeURIComponent(uri) + ""e=&location=" + encodeURIComponent(location.href) + "&rks=" + unsafeWindow.Hatena.Visitor.RKS). next(function (res) { return JSON.parse(res.responseText); }); }). error(function (e) { alert(e); }); } // addColorStar("http://h.hatena.ne.jp/cho45/9234093201515887789", "green"); } })();