Hatena::Let のはてブ数

  • /*
     * @title Hatena::Let のはてブ数
     * @description 一覧ページのパーマリンク部分にはてブ数 (* users) を付けていきます。
     * @include http://let.hatelabo.jp/*
     * @license MIT License
     * @javascript_url
     */
    
    (function () {
    
    	if (typeof(window.$o_o$) != 'function') window.$o_o$ = counts => {
    
    		for (let url in counts) {
    
    			const users = counts[url];
    			if (!users) continue;
    
    			const a = document.createElement("a");
    			a.setAttribute("href", "http://b.hatena.ne.jp/entry/" + url.substr(7));
    			a.style.cssText = 'font-weight: bold; font-size: 80%; ' + ((users < 10) ? 'color: #FF6766; background-color: #FFEEEE;' : 'color: #FF0606; background-color: #FFCBCB;');
    			a.appendChild(document.createTextNode(users + ' ' + ((users == 1) ? 'user' : 'users')));
    			const p = document.querySelector('a[href="' + url.replace(/^.+let\.hatelabo\.jp\//, '/') + '"]');
    			p.parentNode.insertBefore(a, p.nextSibling);
    			p.parentNode.insertBefore(document.createTextNode(' '), p.nextSibling);
    
    		};
    		
    	};
    
    	// 参考 http://let.hatelabo.jp/a-kuma3/let/hJmf1-2Uhdgq
    	Ten.JSONP('http://api.b.st-hatena.com/entry.counts?callback=$o_o$&' +
    	 Array.prototype.slice.call(document.querySelectorAll('a.code-path'))
    	 .map(function(a) { return 'url=' + a.href; }).join('&'), $o_o$);
    
    })();
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2017/01/01 13:46:17 - 2017-01-01
  2. 2017/01/01 13:32:32 - 2017-01-01