Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mekkoo/407442 to your computer and use it in GitHub Desktop.
Save mekkoo/407442 to your computer and use it in GitHub Desktop.
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document url-prefix("http://www.google.co.jp/reader/view/"),
url-prefix("http://www.google.com/reader/view/"),
url-prefix("https://www.google.co.jp/reader/view/"),
url-prefix("https://www.google.com/reader/view/") {
div.item-body{
font-size:14px;
}
.entry .entry-body, .entry .entry-title, .entry .entry-likers{
max-width:none !important;
}
.entry .entry-main{
margin-right:25px !important;
}
.hatebu-comments{
background-color:#f5f9fe;
border:2px solid #2c6ebd;
padding:5px 10px;
}
.hatebu-comments h3{
color:#2c6ebd;
line-height:24px;
margin:0 0 5px 0;
}
.hatebu-comments h3 img{
vertical-align:middle;
}
.hatebu-comments .count {
margin-left:5px;
}
.hatebu-comments ul{
list-style-type:none;
}
.hatebu-comments ul img.profile-image{
vertical-align:top;
}
.hatebu-comments ul .twitter img{
vertical-align:middle;
margin-left:3px;
}
.hatebu-comments ul li{
padding:5px 0;
border-top:1px solid #dce0e4;
}
.hatebu-comments .timestamp{
color:#999999;
}
.hatebu-comments .username{
color:#0000DD !important;
text-decoration:none !important;
}
.hatebu-comments .user-tag{
color:#6666CC !important;
text-decoration:none !important;
}
}
// ==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==
GM_addStyle(<![CDATA[
.hatebu-comments {clear:both}
.hatebu-comments > ul {margin:0; padding:0}
]]>);
setInterval(function watch(){
qse(document, '.entry-container:not([data-grhc-done])', fetch);
}, 1e3);
function qse(node, sel, fn) Array.forEach(node.querySelectorAll(sel), fn);
function fetch(cont){
cont.setAttribute('data-grhc-done', 1);
var {href} = cont.querySelector('.entry-title-link') || 0;
if(!href) return;
href = href.replace(/#/g, '%23');
var url = 'http://b.hatena.ne.jp/entry/'+ href;
var div = document.createElement('div');
div.className = 'hatebu-comments';
div.innerHTML = <h3>Hatena Bookmark<a class="count" href={url} style="display:none"><img
onload="width === 1 || parentNode.removeAttribute('style')"
src={'http://b.hatena.ne.jp/entry/image/'+ href}/></a></h3>;
cont.querySelector('.entry-body').appendChild(div);
GM_xmlhttpRequest({
url: url.replace(/~/g, '%7E'),
method: 'GET',
onload: function onload(xhr){
if(xhr.status !== 200){
div.innerHTML = ('<em>Failed to load Hatebu Comments: '+
xhr.status +' '+ xhr.statusText);
return;
}
if(!/<ul id="bookmarked_user"[^>]*>([^]+?)<\/ul/.test(xhr.responseText)){
div.parentNode.removeChild(div);
return;
}
var ul = div.appendChild(document.createElement('ul'));
ul.innerHTML = RegExp.$1;
qse(ul, 'a[href^="/"], img[src^="/"]', function abs(lm){
var key, val = (lm.getAttribute(key = 'href') ||
lm.getAttribute(key = 'src'));
lm.setAttribute(key, 'http://b.hatena.ne.jp'+ val);
});
},
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment