Twitterã®favoritesæ°ã表示ããGreasemonkey User Script
GETã ã¨APIå¶éã«ãªããã¨ãå¤æããã®ã§userscripts.orgããå¼ãä¸ãããã©ãã¨ããããã½ã¼ã¹ã ãè²¼ã£ã¨ãããã¤ãã®ããã«POSTã§APIå¶éã¯ç¡è¦ã§ããã®ã§ã使ããã人ã¯ããããã£ã¦ä½¿ãã°ããã¨ãããã¾ããããPOSTã§APIå¶éã¯ç¡è¦ã§ããªããªã£ãã®ã§ä½¿ããªãæ¹ãããã§ããã
// ==UserScript== // @name Twitter favorites counter // @namespace http://fuba.moaningnerds.org/ // @include http://twitter.com/* // ==/UserScript== $X('//link[@rel="alternate"]')[0].href.match(/(\d+)/); var id = RegExp.$1; GM_xmlhttpRequest({ method: "GET", url: "http://twitter.com/users/show/" + id + ".xml", onload: function(x){ if (x.responseText.match(/<favourites_count>(\d+)<\/favourites_count>/)) { var span = document.createElement('span'); span.className = 'stat_count'; span.appendChild(document.createTextNode(RegExp.$1)); var link = $X('id("favorites_tab")')[0]; link.insertBefore(span, link.childNodes[0]); } } }); // simple version of $X // $X(exp); // $X(exp, context); // @source http://gist.github.com/3242.txt function $X (exp, context) { context || (context = document); var expr = (context.ownerDocument || context).createExpression(exp, function (prefix) { return document.createNSResolver(context)(prefix) || (document.contentType == "application/xhtml+xml") ? "http://www.w3.org/1999/xhtml" : ""; }); var result = expr.evaluate(context, XPathResult.ANY_TYPE, null); switch (result.resultType) { case XPathResult.STRING_TYPE : return result.stringValue; case XPathResult.NUMBER_TYPE : return result.numberValue; case XPathResult.BOOLEAN_TYPE: return result.booleanValue; case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: // not ensure the order. var ret = [], i = null; while (i = result.iterateNext()) ret.push(i); return ret; } return null; }