Skip to content

Instantly share code, notes, and snippets.

@os0x
Forked from hotchpotch/gist:49917
Created January 21, 2009 15:03
Show Gist options
  • Save os0x/49992 to your computer and use it in GitHub Desktop.
Save os0x/49992 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name with hatebu search
// @namespace http://b.hatena.ne.jp/
// @description google 検索の画面で、はてブ検索へのナビゲーションを出します
// @include http://www.google.co.jp/search*
// @include http://www.google.com/search*
// ==/UserScript==
(function () {
var tr = $X('//tr[td/input[@name="q"]]');
if (tr.length) {
var q = document.getElementsByName('q')[0];
var td = document.createElement('td');
var a = document.createElement('a');
var ACTION = a.href = 'http://b.hatena.ne.jp/search';
var img = document.createElement('img');
img.src = 'http://b.hatena.ne.jp/images/search-mini.png';
img.title = img.alt = 'はてなで検索';
img.style.border = 'none';
a.appendChild(img);
td.appendChild(a);
a.addEventListener('click', function() {
a.href = ACTION + '?q=' + q.value;
}, false);
tr[0].appendChild(td);
}
// very simple version of $X
// $X(exp);
// $X(exp, context);
// $X(exp, context, resolver);
// @source http://gist.github.com/29681.txt
function $X (exp, context, resolver) {
context || (context = document);
var Doc = context.ownerDocument || context;
var result = Doc.evaluate(exp, context, resolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0, len = result.snapshotLength, res = []; i < len; i++) {
res.push(result.snapshotItem(i));
}
return res;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment