Changeset 22979
- Timestamp:
- 11/08/08 08:41:58 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/userscripts/text_url_linker.user.js
r22977 r22979 9 9 var TAG = 'a'; 10 10 var fn = function(doc) { 11 $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) {11 $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) { 12 12 var df, text = txt.nodeValue.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'), 13 13 parent = txt.parentNode, range = document.createRange(), 14 newText = text.replace(/ (?:h)?(ttps?:\/\/[^\s\t\n\r\])'")」】]+)/g, function($0, $1) {14 newText = text.replace(/h?(ttps?:\/\/[^\s\])'")」】]+)/g, function($0, $1) { 15 15 return '<'+TAG+' href="h'+$1+'" ini="1" style="text-decoration:underline overline;display:inline !important;">'+$0+'</'+TAG+'>'; 16 16 }); … … 20 20 range.detach(); 21 21 if (BLOCK_REFERRER) { 22 Array.prototype.forEach.call(parent.getElementsByTagName(TAG), function(nota) {22 Array.prototype.forEach.call(parent.getElementsByTagName(TAG), function(nota) { 23 23 if (nota.getAttribute('ini')==1) { 24 24 nota.addEventListener('click', function(e) { 25 25 openInTab(nota.getAttribute('href')); 26 26 e.preventDefault(); 27 }, false);27 }, false); 28 28 nota.removeAttribute('ini'); 29 29 } … … 33 33 }; 34 34 fn(document.body); 35 if (window.AutoPagerize) AutoPagerize.addFilter(function(docs) {docs.forEach(fn);});35 if (window.AutoPagerize) AutoPagerize.addFilter(function(docs) {docs.forEach(fn);}); 36 36 37 37 function openInTab(url) { 38 38 if (window.opera || window.getMatchedCSSRules) { 39 window.open('data:text/html,<script >location.replace("' + url + '");</script>');39 window.open('data:text/html,<script type="text/javascript">location.replace("' + url + '");</script>'); 40 40 } else if (typeof GM_openInTab == 'function') { 41 41 GM_openInTab(url); … … 48 48 var XPE = new XPathEvaluator(); 49 49 var Doc = context.ownerDocument || context, expr = XPE.createExpression(exp, resolver ? resolver : 50 Doc.documentElement.namespaceURI ? function (prefix) {50 Doc.documentElement.namespaceURI ? function(prefix) { 51 51 return document.createNSResolver(Doc.documentElement).lookupNamespaceURI(prefix) || 52 52 context.namespaceURI || document.documentElement.namespaceURI || ""; … … 54 54 var result = expr.evaluate(context, XPathResult.ANY_TYPE, null); 55 55 switch (result.resultType) { 56 case XPathResult.STRING_TYPE : return function(fnc,thisObject) {fnc.call(thisObject,result.stringValue);};57 case XPathResult.NUMBER_TYPE : return function(fnc,thisObject) {fnc.call(thisObject,result.numberValue);};58 case XPathResult.BOOLEAN_TYPE: return function(fnc,thisObject) {fnc.call(thisObject,result.booleanValue);};56 case XPathResult.STRING_TYPE : return function(fnc,thisObject) {fnc.call(thisObject,result.stringValue);}; 57 case XPathResult.NUMBER_TYPE : return function(fnc,thisObject) {fnc.call(thisObject,result.numberValue);}; 58 case XPathResult.BOOLEAN_TYPE: return function(fnc,thisObject) {fnc.call(thisObject,result.booleanValue);}; 59 59 case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: 60 60 result = expr.evaluate(context, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, result); 61 return function(fnc, thisObject){62 for (var i = 0, len = result.snapshotLength; i < len ; i++) {61 return function(fnc, thisObject) { 62 for (var i = 0, len = result.snapshotLength; i < len; i++) { 63 63 fnc.call(thisObject, result.snapshotItem(i)); 64 64 } 65 } 65 }; 66 66 } 67 67 return null;
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)