Skip to content

Instantly share code, notes, and snippets.

@edvakf
Created November 26, 2010 11:33
Show Gist options
  • Select an option

  • Save edvakf/716590 to your computer and use it in GitHub Desktop.

Select an option

Save edvakf/716590 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @include http://a.hatena.ne.jp/*
// ==/UserScript==
(function() {
function replaceLinks() {
Array.prototype.forEach.call(
document.querySelectorAll('a[href^="http://a.st-hatena.com/go?"]'),
function(a) {
var num, frag = '';
a.href = a.href
.replace('http://a.st-hatena.com/go?', '')
.replace(/\d{14}$/, function(n) {num = n; return ''})
.replace(/#.*/, function(f) {frag = f; return ''});
if (frag) {
a.href += (a.href.indexOf('?') >= 0 ? '&' : '?') + num + frag;
} else {
a.href += '#' + num;
}
}
);
}
var loaded = false;
window.addEventListener('DOMContentLoaded', function(){loaded = true;}, false);
var timer = setInterval(function() {
replaceLinks();
if (loaded) clearInterval(timer);
}, 10);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment