Created
May 19, 2010 19:32
-
-
Save satyr/406743 to your computer and use it in GitHub Desktop.
Google Reader Hatebu Comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Google Reader Hatebu Comments | |
// @namespace http://twitter.com/m_satyr | |
// @description Auto-appends Hatebu comments to each Google Reader entry. | |
// @include http*://www.google.*/reader/view/* | |
// @license MIT | |
// ==/UserScript== | |
const HB = 'http://b.hatena.ne.jp/', HBE = HB + 'entry/'; | |
GM_addStyle(<![CDATA[ | |
.hatebu-count {position:absolute; bottom:0; right:0} | |
${margin:0; padding:0; clear:both} | |
$img, .hatebu-count > img {vertical-align:middle; border:none} | |
$.user-tag, $.title {font-size:92%; text-decoration:none} | |
$.timestamp, $.count {font-size:84%} | |
$> .related {margin-left:1.5em} | |
]]>.trim().replace(/\$/g, '.hatebu-comments ')); | |
setInterval(function watch(){ | |
Array.forEach( | |
document.body.querySelectorAll('.entry:not([data-grhc-done])'), | |
fetch, {__proto__: null}); | |
}, 2e3); | |
function fetch(entry){ | |
entry.setAttribute('data-grhc-done', 1); | |
var {href} = entry.querySelector('.entry-title-link, .entry-original') || 0; | |
if(!href || href in this) return; | |
this[href] = 1; | |
href = href.replace(/#/g, '%23'); | |
var a = document.createElement('a'); | |
a.className = 'hatebu-count'; | |
a.href = HBE + href.replace(/^http:\/+/, ''); | |
a.appendChild(new Image).src = HBE +'image/'+ href; | |
entry.querySelector('.entry-main').appendChild(a); | |
GM_xmlhttpRequest({ | |
url: HBE +'json/?url='+ encodeURIComponent(href), | |
method: 'GET', | |
onload: function onload(xhr){ | |
if(xhr.status != 200) return GM_log( | |
'\nFailed to fetch comments for <'+ href +'>.\n'+ | |
xhr.status +' '+ xhr.statusText); | |
var o = JSON.parse(xhr.responseText); | |
if(!o) return; | |
var {eid, title} = o, ls = '', i = 0; | |
for each(let {user, tags, comment, timestamp} in o.bookmarks){ | |
ls += let(uu = HB + user +'/') String.concat( | |
'<li class="user-', user, tags.length ? '' : ' notags', | |
comment && !~title.indexOf(comment) ? (++i, '') : ' nocomment', | |
'"><a class="user" href="', uu, | |
'"><img class="profile-image" src="http://www.st-hatena.com/users/', | |
user.slice(0, 2), '/', user, '/profile_s.gif"/></a> ', | |
'<a class="username" href="', | |
uu, timestamp.slice(0, 4), timestamp.slice(5, 7), | |
'#bookmark-', eid, '">', user, '</a> <span class="tags">', | |
[<a class="user-tag" href={uu + t +'/'}>{t}</a>.toXMLString() | |
for each(t in tags)].join(' '), '</span> ', | |
<span class="comment">{comment}</span>.toXMLString(), | |
' <span class="timestamp">', timestamp, '</span></li>'); | |
if(i >= 99) break; | |
} | |
if(o.count > 9 && 'related' in o) ls += [ | |
<li class="related"><a class="title" href={r.url}><img class="favicon" | |
src={'http://favicon.hatena.ne.jp/?url='+ encodeURIComponent(r.url)} | |
/>{r.title}</a> <a class="count" href={r.entry_url} | |
>{r.count +' users'}</a></li> | |
for each(r in o.related)].join(''); | |
var ul = document.createElement('ul'); | |
ul.className = 'hatebu-comments'; | |
ul.innerHTML = ls; | |
(entry.querySelector('.entry-body') || entry).appendChild(ul); | |
}, | |
}); | |
} |
machibuse さんの http://gist.github.com/407442 の方のものだとリスト表示で無事見られました。
差分とって見てみます。お騒がせしました。
リスト表示だと表示されないのですが
http://gist.github.com/406743/f739bd42a6ab832a93071add98b722ca8d234357
普段 Expanded しか使わないので想定外でした。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
これは全文表示でしょうか?リスト表示だと表示されないのですが、いい対処法ないものでしょうか?