Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created January 17, 2010 01:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitode909/279123 to your computer and use it in GitHub Desktop.
Save hitode909/279123 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name check-userjs
// @namespace http://www.hatena.ne.jp/hitode909
// @include http://*
// @include https://*
// ==/UserScript==
var anchors = document.querySelectorAll('a[href$=".js"]');
for (var i = 0, len = anchors.length; i < len; i++) {
if (anchors[i].href.match(/\.user(?:-\d+)?\.js$/)) {
check(anchors[i]);
}
}
function check(anchor) {
var cache = GM_getValue(anchor.href);
if (cache == "true") {
anchor.href += '#';
}
if (cache) {
return;
}
GM_xmlhttpRequest({
method : "GET",
url : anchor.href,
onload : function (req) {
if (req.responseHeaders.match(/^Content-Type: .*html.*$/m)) {
GM_setValue(anchor.href, "true");
anchor.href += '#';
} else {
GM_setValue(anchor.href, "false");
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment