vankuzu
Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Код: // ==UserScript== // @name Linkify // @version 1.05 // @date 2009-12-21 // @author Sergey Voronov // @exclude *odnoklassniki.ru/* // ==/UserScript== // /////////////////////////////////////////////////////////////////// // SETTINGS var anchorAttribute = /*@anchorAttribute@string@*/'linkified'/*@*/; // 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;' // 'font-style: italic; background-color: #fffbb9; color: #008000; border-top: thin dashed #008000; border-bottom: thin dashed #008000;' //var anchorStyle = /*@anchorStyle@string@*/'font-style: italic; background-color: #fffbb9; color: #008000; border-top: thin dashed #008000; border-bottom: thin dashed #008000;'/*@*/; var anchorStyle = /*@anchorStyle@string@*/'color: #ff4f00'/*@*/; // END OF SETTINGS /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// // DO NOT EDIT // Enable the script if we're not displaying svg files if (!window.location.href.match(/\.(svg)$/i) ) { document.addEventListener('DOMContentLoaded',function() { if(!(document.documentElement instanceof HTMLHtmlElement)) return; //RegExp is splitted in parts to simplify modification //after connecting toogether it is // \b(?_?[hx]..ps?:\/\/)|(_?f.p:\/\/)|(mailto|(www\d*\.)|(ftp\d*\.)|(magnet)[^\^\[\]{}|\\\'"<>`\s]*[^!@\^()\[\]{}|\\:;\'",.?<>`\s] //You can try to write better, but remember about Backreferences (used in GetLinkHREF to determining kind of link) // var sProtocol = '(_?[hx]..ps?:\/\/)|(_?f.p:\/\/)|(mailto|(www\\d*\\.)|(ftp\\d*\\.)|(magnet'; var sProtocol = '(_?[hx]..ps?:\/\/)|(_?f.p:\/\/)|(mailto|(irc:\/\/)|(\\S*\\S*@?irc\\.)|(news:\/\/)|(nntp:\/\/)|(telnet:\/\/)|(file:\/\/)|(\\S*\\S*@?www\\d*\\.)|(\\S*\\S*@?ftp\\d*\\.)|(\\S*\\.(com|net|org|ru|us)\/)|(magnet|(opera'; // var sURLPathChars = '[^\\^\\[\\]{}|\\\\\'"<>`\\s]'; var sURLPathChars = '[^\\^\\[\\]{}\\\\\'"<>`\\s]'; var sEndChars = '[^!@\\^()\\[\\]{}|\\\\:;\'",.?<>`\\s]'; var sURLPath = sURLPathChars + '*' + sEndChars; var sRegExpHTTP = '\\b(?:' + sProtocol + ')' + sURLPath; var rRegExpHTTP = RegExp(sRegExpHTTP, 'i'); var GetLinkHREF= function(aMatch) { if (aMatch[1]) return aMatch[0].replace(/^_?[hx]..p/i,'http'); if (aMatch[2]) return aMatch[0].replace(/^_?f.p/i,'ftp'); // if (aMatch[3]) //email if (aMatch[10]) return 'http://' + aMatch[0]; if (aMatch[11]) return 'ftp://' + aMatch[0]; // if (aMatch[13]) //magnet if (aMatch[5]) return 'irc://' + aMatch[0]; if (aMatch[12]) return 'http://' + aMatch[0]; return aMatch[0]; }; if(anchorStyle) { if(!document || !document.documentElement) return; var anchorCSS = document.createElement('style'); anchorCSS.setAttribute('type', 'text/css'); anchorCSS.appendChild(document.createTextNode('a.' + anchorAttribute + ' {' + anchorStyle + '}')); document.documentElement.appendChild(anchorCSS); } var foundText, matchedText, matchedHref, newLinkElement = document.createElement('a'); //Add class for CSS styling newLinkElement.setAttribute('class',anchorAttribute); var //Excluding non-text tags excElems = ['head','applet','object','embed','param','script','style','frameset','frame','iframe','textarea','input','option','select','a','img','map'], //Get all text elements textNodes = document.selectNodes('//*[not(ancestor-or-self::*[local-name()="'+excElems.join('" or local-name()="')+'"])]/text()'); for( var i = 0, textNode, disp; textNode = textNodes[i]; i++ ) { //Find something looks like URL while( foundText = rRegExpHTTP.exec(textNode.data) ) { //Remember founded text matchedText = foundText[0]; //Parse it into URL matchedHref = GetLinkHREF(foundText); textNode = textNode.splitText(foundText.index); textNode.deleteData(0,((newLinkElement = newLinkElement.cloneNode(false)).text = matchedText).length); newLinkElement.setAttribute('href',matchedHref); textNode.parentNode.insertBefore(newLinkElement,textNode); } } },false); } | | Всего записей: 290 | Зарегистр. 01-09-2008 | Отправлено: 11:38 03-03-2017 | Исправлено: vankuzu, 11:41 03-03-2017 |
|