Created
May 29, 2014 16:43
-
-
Save mitry/e2a7f31e82549f60df69 to your computer and use it in GitHub Desktop.
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 Linkifier | |
| // @version 1.06 | |
| // @date 2008-10-10 | |
| // @author Mike Samokhvalov <[email protected]> | |
| // @download http://www.puzzleclub.ru/files/linkifier.js | |
| // ==/UserScript== | |
| // By motive of Greasemonkey user script "Linkifier": | |
| // http://userscripts.org/scripts/show/1024 | |
| (function(){ | |
| /////////////////////////////////////////////////////////////////// | |
| // SETTINGS | |
| var anchorAttribute = 'ujs_linkifier'; | |
| // Anchor style. Examples: | |
| // 'text-decoration: overline !important;' | |
| // 'border-width: 1px 0 !important; border-style: dotted !important;' | |
| // 'border-width: 1px 0 !important; border-style: dashed !important;' | |
| var anchorStyle = ''; | |
| // END OF SETTINGS | |
| /////////////////////////////////////////////////////////////////// | |
| /////////////////////////////////////////////////////////////////// | |
| // DO NOT EDIT | |
| // Modified regular expression from http://regexlib.com/ | |
| var uriRe = /\b(?:(?:(?:file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp|irc):\/\/(?:[^:@\s\.\,\/\\]+(?::[^:@\s\.\,\/\\]+)?@)?)|(?:www\.|ftp\.|irc\.))(?:(?:[\w\.-]+\.[a-zA-Z]{2,6})|(?:[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(?:\:\d+)?(?:\/(?:[\w\-\.\?\!\,\'\/\\\+&%\$#\=~:;\[\]\(\)]+[\w\-\/\\\+&%\$#\=~]+)?)?/gi; | |
| var linkify = function(obj) { | |
| if(!obj) return; | |
| if(obj.tagName.match(/^(a|head|meta|title|applet|object|param|embed|script|style|frameset|frame|iframe|textarea|input|button|select|option|img|map)$/i)) | |
| return; | |
| if(obj.tagName == 'PRE' || obj.tagName == 'CODE') { | |
| obj.innerHTML = obj.innerHTML.replace(/(?:\r\n|\n|\r)/g, function(s){ return '\r\n'; }); | |
| } | |
| var cn = obj.childNodes; | |
| for(var i = cn.length - 1; i >= 0; i--) { | |
| if(cn[i].nodeType == 1) { | |
| linkify(cn[i]); | |
| } else if(cn[i].nodeType == 3 && cn[i].nodeValue.match(uriRe)) { | |
| var v = cn[i].nodeValue.replace(/&/g, '&'); | |
| v = v.replace(/</g, '<'); | |
| v = v.replace(/>/g, '>'); | |
| v = v.replace(uriRe, function(s){ | |
| var url = s; | |
| if(url.indexOf('www.') == 0) | |
| url = 'http://' + url; | |
| else if(url.indexOf('ftp.') == 0) | |
| url = 'ftp://' + url; | |
| else if(url.indexOf('irc.') == 0) | |
| url = 'irc://' + url; | |
| return '<a href="' + url + '" ' + anchorAttribute + '="1">' + s + '</a>'; | |
| }); | |
| var s = document.createElement('span'); | |
| document.documentElement.appendChild(s); | |
| cn[i].parentNode.replaceChild(s, cn[i]); | |
| s.outerHTML = v; | |
| } | |
| } | |
| }; | |
| var addStyle = function(css) { | |
| if(!document || !document.documentElement) return; | |
| var s = document.createElement('style'); | |
| s.setAttribute('type', 'text/css'); | |
| s.setAttribute('style', 'display:none !important;'); | |
| s.appendChild(document.createTextNode(css)); | |
| document.documentElement.appendChild(s); | |
| }; | |
| if(anchorStyle) | |
| addStyle('a[' + anchorAttribute + '] {' + anchorStyle + '}'); | |
| linkify(document.body); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment