読者です 読者をやめる 読者になる 読者になる

現在のページのはてブ数を右上に表示するgreasemonkey

// ==UserScript==
// @name           hatebu_num
// @namespace      http://d.hatena.ne.jp/toton/
// @description    Show Hatena Bookmark's count.
// @include        http://*
// @version        0.1
// ==/UserScript==

(function() {
	var f = function(){
		try{
			var w = typeof unsafeWindow != 'undefined' ? unsafeWindow : window;
			if (self.location.href!=top.location.href) return;
			if(null == location.href)return;
			var uri=top.location.href;
			if(-1 != uri.indexOf('http://192.168.'))return;
			if(-1 != uri.indexOf('http://localhost'))return;
			if(-1 != uri.indexOf('http://172.16.'))return;
			if(document.contentType == "text/plain")return;
			//GM_log(" hatebu num count start:" + uri);
		}catch(e){
			//GM_log("ex:"+ e);
			return;
		}

		var script= document.createElement('script');
		script.type= 'application/javascript';
		script.charset= 'UTF-8';
		script.src= 'http://b.hatena.ne.jp/entry/json/?url='+escape(uri)+'&callback=showBM';
		document.getElementsByTagName('head')[0].appendChild(script);
		w.showBM = function(item){
			if(null == item)return;
			if(item.count!='0'){
				//GM_log(" hatebu num count :" + item.count);
				var kil_link = document.createElement('div');
				kil_link.setAttribute('id', 'kill');
				kil_link.setAttribute('style', "position:absolute; top:20px; right:5px;");
				text="<a href='http://b.hatena.ne.jp/entry/"
					+item.url.replace('#','%23')+"' target='_blank' style='color:red;background-color:#ffcccc;font-weight:bold;font-size:80%;font-family:sans-serif;'>"
					+item.count+" user"+(parseInt(item.count)>1 ? 's' : '')+"</a> ";
				text+="<a href='javascript:(function(){document.getElementById(\"kill\").style.display=\"none\";document.getElementById(\"hatenabm\").style.display=\"none\";})()'"
					+" style='text-decoration:none;color:white;background-color:indianred;font-weight:bold;font-size:small;"
					+"border-style:solid;border-width:1px;border-color:crimson;font-family:sans-serif;'>X</a>";
				kil_link.innerHTML=text;
				document.body.appendChild(kil_link);
			}
		};
	};
	setTimeout(f,1000);
})();