Created
July 30, 2008 06:53
-
-
Save kei-s/3241 to your computer and use it in GitHub Desktop.
ShowTwitterIconOnTumblerBySTOT
This file contains 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 ShowTwitterIconOnTumblerBySTOT | |
// @namespace http://libelabo.jp/ | |
// @description Show twitter icon in conversation posted by ShareTwitterOnTumblr | |
// @author kei-s | |
// @include http://*.tumblr.com/* | |
// ==/UserScript== | |
(function(){ | |
var WIDTH = "30"; | |
var HEIGHT = "30"; | |
function insertIcon(root){ | |
$x('.//div[contains(concat(" ",normalize-space(@class)," "), " conversation " )]/ul/li/span[following-sibling::node()[1][contains(.,"[http://twitter.com/")]]',root).forEach( function(span){ | |
if( span.textContent.match(/^(.[^:]+):$/) ) { | |
var user = RegExp.$1; | |
var img = document.createElement('img'); | |
img.src = "http://usericons.relucks.org/twitter/" + user; | |
img.width = WIDTH; | |
img.height = HEIGHT; | |
span.parentNode.insertBefore(img,span); | |
} | |
}); | |
} | |
insertIcon(document); | |
if(window.AutoPagerize && window.AutoPagerize.addFilter) { | |
window.AutoPagerize.addFilter( | |
function(docs) { | |
if(!docs) return; | |
docs.forEach(function(doc){if(!doc) return; insertIcon(doc)}); | |
} | |
); | |
} | |
function $x (exp, context) { | |
var type, namespace={}; | |
// console.log(String(exp)); | |
if(typeof context == "function"){ | |
type = context; | |
context = null; | |
}else if(typeof context != "undefined" && !context['nodeType']){ | |
type = context['type']; | |
namespace = context['namespace'] || context['ns']; | |
context = context['context']; | |
} | |
if (!context) context = document; | |
var exp = (context.ownerDocument || context).createExpression(exp, function (prefix) { | |
return namespace[prefix] || document.createNSResolver((context.ownerDocument == null ? context | |
: context.ownerDocument).documentElement) | |
.lookupNamespaceURI(prefix) || document.documentElement.namespaceURI; | |
}); | |
switch (type) { | |
case String: | |
return exp.evaluate( | |
context, | |
XPathResult.STRING_TYPE, | |
null | |
).stringValue; | |
case Number: | |
return exp.evaluate( | |
context, | |
XPathResult.NUMBER_TYPE, | |
null | |
).numberValue; | |
case Boolean: | |
return exp.evaluate( | |
context, | |
XPathResult.BOOLEAN_TYPE, | |
null | |
).booleanValue; | |
case Array: | |
var result = exp.evaluate( | |
context, | |
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, | |
null | |
); | |
var ret = []; | |
for (var i = 0, len = result.snapshotLength; i < len; ret.push(result.snapshotItem(i++))); | |
return ret; | |
case undefined: | |
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; | |
default: | |
throw(TypeError("$X: specified type is not valid type.")); | |
} | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment