[b.hatena]ID コール先表示

    @@ -35,7 +35,7 @@ }; -((u.indexOf(b) === 0 && !/entry\/\d+\//.test(u)) +((u.indexOf(b) === 0 && !/http:\/\/b\.hatena\.ne\.jp\/entry\/\d+\//.test(u)) ? fetch(`${b}json/?url=${encodeURIComponent(u.split(b).join(h))}`) .then(r).then(j => Promise.resolve(j.eid), j => o) : o).then(async f => { @@ -57,4 +57,4 @@ }); -})(); +})();
  • /*
     * @title [b.hatena]ID コール先表示
     * @description ID コールされた人のコメントをコールの近くにくっつけます。メタブの場合は一段下も見ます。
     * @include http://http://b.hatena.ne.jp/entry/*
     * @license MIT License
     * @javascript_url
     */
    
    (() => {
    
    const c = {};
    const h = 'http://';
    const b = h + 'b.hatena.ne.jp/entry/';
    const q = document.querySelector('html');
    const e = q.getAttribute('data-entry-eid');
    const u = q.getAttribute('data-entry-url');
    const a = document.evaluate('//a[contains(.,"id:") and @rel="nofollow"]', document.querySelector('#bookmarks'), null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    const o = Promise.resolve(0);
    const r = p => p.json();
    const g = async (e, n, l) => {
    
    	const v = `${h}b.hatena.ne.jp/api/oembed?url=http%3A%2F%2Fb%2Ehatena%2Ene%2Ejp%2Fentry%2F${e}%2Fcomment%2F${n}&format=json`;
    
    	if (!c[v]) c[v] = await fetch(v).then(r).then(j => {
    
    		const d = document.createElement('div');
    //		if (j) d.innerHTML = `<h5><img src="${h}n.hatena.ne.jp/${n}/profile/image?type=icon&amp;size=16">${n}</h5>${j.html}`;
    		if (j) d.innerHTML = j.html;
    		return(Promise.resolve(d));
    
    	 }, j => Promise.resolve(document.createComment('')));
    
    	l.parentNode.parentNode.parentNode.appendChild(c[v].cloneNode(true));
    	return(o);
    
    };
    
    ((u.indexOf(b) === 0 && !/http:\/\/b\.hatena\.ne\.jp\/entry\/\d+\//.test(u))
     ? fetch(`${b}json/?url=${encodeURIComponent(u.split(b).join(h))}`)
      .then(r).then(j => Promise.resolve(j.eid), j => o) : o).then(async f => {
    
    	for (let i = 0; i < a.snapshotLength; i++) {
    
    		const l = a.snapshotItem(i);
    		if (!l.href.match(/^(?:http:\/\/b\.hatena\.ne\.jp\/|\/)(.+)\/$/)) continue;
    		const n = RegExp.$1;
    
    		await g(e, n, l);
    		if (f) await g(f, n, l);
    
    	}
    
    	// j.html についてくるスクリプトが読み込まれてなかった
    	const s = document.createElement('script');
    	s.src = 'https://b.st-hatena.com/js/comment-widget.js';
    	document.body.appendChild(s);
    
     });
    
    })();
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2017/02/03 08:45:15 - 2017-02-03
  2. 2017/02/03 00:19:35 - 2017-02-03
  3. 2017/02/03 00:15:30 - 2017-02-03