Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
javascript:(function TextURLLinker() {
var TAG = 'a';
var STYLE = 'color:#13819f;display:inline !important;';
if (document.contentType && !/html/i.test(document.contentType))
return;
var fn = function(doc) {
$XA('descendant::text()[contains(self::text(),"ttp") and not(ancestor::a) and not(ancestor::textarea) and not(ancestor::script) and not(ancestor::style)]', doc)(function(txt) {
var df, text = txt.nodeValue.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'),
parent = txt.parentNode, range = document.createRange(),
newText = text.replace(/h?(ttps?:\/\/[^\s\])'")」】]+)/g, function($0, $1) {
var url = 'data:text/html;charset=utf-8,&lt;script&gt;location.href=&quot;h'+ $1 +'&quot;;&lt;/script&gt;';
return '<' + TAG + ' href="' + url + '" ini="1" style="' + STYLE + '">' + $0 + '</' + TAG + '>';
});
range.selectNode(txt);
df = range.createContextualFragment(newText);
parent.replaceChild(df, txt);
range.detach();
});
};
fn(document.body);
if (window.AutoPagerize) AutoPagerize.addFilter(function(docs) {docs.forEach(fn);});
function $XA(exp, context, resolver) {
context || (context = document);
var XPE = new XPathEvaluator();
var Doc = context.ownerDocument || context, expr = XPE.createExpression(exp, resolver ? resolver :
Doc.documentElement.namespaceURI ? function(prefix) {
return document.createNSResolver(Doc.documentElement).lookupNamespaceURI(prefix) ||
context.namespaceURI || document.documentElement.namespaceURI || "";
} : null);
var result = expr.evaluate(context, XPathResult.ANY_TYPE, null);
switch (result.resultType) {
case XPathResult.STRING_TYPE : return function(fnc,thisObject) {fnc.call(thisObject,result.stringValue);};
case XPathResult.NUMBER_TYPE : return function(fnc,thisObject) {fnc.call(thisObject,result.numberValue);};
case XPathResult.BOOLEAN_TYPE: return function(fnc,thisObject) {fnc.call(thisObject,result.booleanValue);};
case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
result = expr.evaluate(context, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, result);
return function(fnc, thisObject) {
for (var i = 0, len = result.snapshotLength; i < len; i++) {
fnc.call(thisObject, result.snapshotItem(i));
}
};
}
return null;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.