Created
July 24, 2008 00:19
-
-
Save hotchpotch/1952 to your computer and use it in GitHub Desktop.
add user.js link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name gist.user.js | |
// @namespace http://github.com/hotchpotch | |
// @description install greasemonkey (user.js) | |
// @include http://gist.github.com/* | |
// @include https://gist.github.com/* | |
// ==/UserScript== | |
(function() { | |
$X('id("files")//div[@class="info"]/span').forEach(function(e) { | |
var filename = e.innerHTML; | |
if (/\.user\.js$/.test(filename)) { | |
var link = $X('parent::div/following-sibling::div[@class="actions"]/a', e)[0]; | |
if (link) { | |
var el = link.cloneNode(true); | |
el.href += '?' + filename; | |
el.innerHTML = filename; | |
e.parentNode.replaceChild(el,e); | |
} | |
} | |
}); | |
function $X (exp, context) { | |
context = context || document; | |
var resolver = function (prefix) { | |
var o = document.createNSResolver(context)(prefix); | |
return o ? o : (document.contentType == "text/html") ? "" : "http://www.w3.org/1999/xhtml"; | |
} | |
var exp = document.createExpression(exp, resolver); | |
var result = exp.evaluate(context, XPathResult.ANY_TYPE, null); | |
switch (result.resultType) { | |
case XPathResult.STRING_TYPE : return result.stringValue; | |
case XPathResult.NUMBER_TYPE : return result.numberValue; | |
case XPathResult.BOOLEAN_TYPE: return result.booleanValue; | |
case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: { | |
// not ensure the order. | |
var ret = []; | |
var i = null; | |
while (i = result.iterateNext()) { | |
ret.push(i); | |
} | |
return ret; | |
} | |
} | |
return null; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment