Changeset 22979

Show
Ignore:
Timestamp:
11/08/08 08:41:58 (5 years ago)
Author:
drry
Message:
  • fixed a regex.
  • et cetera.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/userscripts/text_url_linker.user.js

    r22977 r22979  
    99        var TAG = 'a'; 
    1010        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) { 
    1212                        var df, text = txt.nodeValue.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'), 
    1313                        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) { 
    1515                                return '<'+TAG+' href="h'+$1+'" ini="1" style="text-decoration:underline overline;display:inline !important;">'+$0+'</'+TAG+'>'; 
    1616                        }); 
     
    2020                        range.detach(); 
    2121                        if (BLOCK_REFERRER) { 
    22                                 Array.prototype.forEach.call(parent.getElementsByTagName(TAG), function(nota){ 
     22                                Array.prototype.forEach.call(parent.getElementsByTagName(TAG), function(nota) { 
    2323                                        if (nota.getAttribute('ini')==1) { 
    2424                                                nota.addEventListener('click', function(e) { 
    2525                                                        openInTab(nota.getAttribute('href')); 
    2626                                                        e.preventDefault(); 
    27                                                 },false); 
     27                                                }, false); 
    2828                                                nota.removeAttribute('ini'); 
    2929                                        } 
     
    3333        }; 
    3434        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);}); 
    3636 
    3737        function openInTab(url) { 
    3838                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>'); 
    4040                } else if (typeof GM_openInTab == 'function') { 
    4141                        GM_openInTab(url); 
     
    4848                var XPE = new XPathEvaluator(); 
    4949                var Doc = context.ownerDocument || context, expr = XPE.createExpression(exp, resolver ? resolver : 
    50                         Doc.documentElement.namespaceURI ? function (prefix) { 
     50                        Doc.documentElement.namespaceURI ? function(prefix) { 
    5151                                return document.createNSResolver(Doc.documentElement).lookupNamespaceURI(prefix) || 
    5252                                context.namespaceURI || document.documentElement.namespaceURI || ""; 
     
    5454                var result = expr.evaluate(context, XPathResult.ANY_TYPE, null); 
    5555                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);}; 
    5959                case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: 
    6060                        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++) { 
    6363                                        fnc.call(thisObject, result.snapshotItem(i)); 
    6464                                } 
    65                         } 
     65                        }; 
    6666                } 
    6767                return null;