Skip to content

Instantly share code, notes, and snippets.

@mallowlabs
Created June 14, 2013 18:46
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 mallowlabs/5784248 to your computer and use it in GitHub Desktop.
Save mallowlabs/5784248 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name GR+?B for Opera
// @author mallowlabs
// @version 0.0.1
// @namespace http://mallowlabs.s206.xrea.com/
// @published 2007-01-16
// @license public domain
// @description show ?B button and count in Google Reader for Opera
// @include http://www.google.com/reader/view/*
// ==/UserScript==
// original author is id:nozom
// see http://d.hatena.ne.jp/nozom/20061017/1161103922
(function() {
var busy = false;
function createBookmarkIcon(link) {
var img = document.createElement('img');
img.setAttribute('src', "http://d.hatena.ne.jp/images/b_entry.gif");
img.setAttribute('style', 'vertical-align: middle;');
var img2 = document.createElement('img');
img2.setAttribute('src', "http://b.hatena.ne.jp/entry/image/large/" + link);
img2.setAttribute('style', 'vertical-align: bottom;margin-left: 2px;');
var a = document.createElement('a');
a.setAttribute('href', "http://b.hatena.ne.jp/entry/" + link);
a.setAttribute('target', "_blank" + link);
a.appendChild(img);
a.appendChild(img2);
var node = document.createElement('span');
node.setAttribute('class', 'hatena-bookmark-icon');
node.appendChild(a);
return node;
}
function timerHandler() {
if (busy){ return; }
busy = true;
var entryURLs = document.evaluate('//h2[@class="entry-title"]/a/@href', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if (entryURLs.snapshotLength > 0) {
var entryActions = document.evaluate('//div[@class="entry-actions"]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < entryActions.snapshotLength; i++) {
var entryNode = entryActions.snapshotItem(i);
// avoid duplication
var hatenaNodes = document.evaluate('span[@class="hatena-bookmark-icon"]', entryNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if (hatenaNodes.snapshotLength === 0) {
entryNode.appendChild(createBookmarkIcon(entryURLs.snapshotItem(i).textContent));
}
}
}
busy = false;
}
// be careful not to be too busy
setInterval(timerHandler, 3000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment