Skip to content

Instantly share code, notes, and snippets.

@satyr
Created May 19, 2010 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save satyr/406743 to your computer and use it in GitHub Desktop.
Save satyr/406743 to your computer and use it in GitHub Desktop.
Google Reader Hatebu Comments
// ==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 {float:right}
${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(){
qse(document, '.entry:not([data-grhc-done])', fetch);
}, 1e3);
function qse(node, sel, fn) Array.forEach(node.querySelectorAll(sel), fn);
function fetch(entry){
entry.setAttribute('data-grhc-done', 1);
var {href} = entry.querySelector('.entry-title-link') || 0;
if(!href) return;
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-actions').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} = o, ls = '';
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 ? '' : ' 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> <span class="timestamp">', timestamp, '</span></li>');
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').appendChild(ul);
},
});
}
@satyr
Copy link
Author

satyr commented May 20, 2010

@tobynet
Copy link

tobynet commented Jul 20, 2010

これは全文表示でしょうか?リスト表示だと表示されないのですが、いい対処法ないものでしょうか?

@tobynet
Copy link

tobynet commented Jul 20, 2010

machibuse さんの http://gist.github.com/407442 の方のものだとリスト表示で無事見られました。
差分とって見てみます。お騒がせしました。

@satyr
Copy link
Author

satyr commented Jul 20, 2010

リスト表示だと表示されないのですが

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