Linkify ting (exclude emails)

Turn plain text links into real clikable links. Attempts to catch links like google.com

  1. // ==UserScript==
  2. // @name Linkify ting (exclude emails)
  3. // @namespace http://ergosum.frac.dk/user/
  4. // @description Turn plain text links into real clikable links. Attempts to catch links like google.com
  5. // @include http://*
  6. // @include https://*
  7. // @include file:///*
  8. // @exclude http://*.google.*/*
  9. // @exclude https://*.google.*/*
  10. // @exclude http://twitter.com/*
  11. // @exclude https://twitter.com/*
  12. // @exclude http://*.facebook.com/*
  13. // @exclude https://*.facebook.com/*
  14. // @exclude http://*.youtube.com/*
  15. // @exclude https://*.youtube.com/*
  16. // @exclude http://youtube.com/*
  17. // @exclude https://youtube.com/*
  18. // @exclude http://addons.mozilla.org/*
  19. // @exclude https://addons.mozilla.org/*
  20. // @copyright JoeSimmons, Anthony Lieuallen, Adam
  21. // @version 1.0.2
  22. // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
  23. // @grant GM_addStyle
  24. // ==/UserScript==
  25.  
  26. // -----------------------------------------------------------------------------
  27. // Loosely based on the Linkify script located at: |
  28. // http://downloads.mozdev.org/greasemonkey/linkify.user.js |
  29. // |
  30. // Originally written by Anthony Lieuallen of http://www.arantius.com/ |
  31. // Licensed for unlimited modification and redistribution as long as |
  32. // this notice is kept intact. |
  33. // |
  34. // If possible, please contact me regarding new features, bugfixes |
  35. // or changes that I could integrate into the existing code instead of |
  36. // creating a different script. Thank you |
  37. // -----------------------------------------------------------------------------
  38.  
  39.  
  40.  
  41. (function(){
  42. var regex = /\b(?![\@\s]+)((https?|nntp|news|telnet|irc|ftp):\/\/)?(([-.A-Za-z0-9]+:)?[\#-.A-Za-z0-9]+@)?((([\w-]+(?!@)\.)?([\w-]+\.)+(ru|am|dk|com|net|org|se|no|nl|us|uk|de|it|nu|edu|info|co|in|to|fr|gov|biz|tv|mil|hu|eu|mobi|az|me|cc|cx|pk|ge|so|pl|ir|be|nz|re|ch|st|la|sk|cz|es|io|au|at|fm|ws)(\.(nr|in|uk))?)|(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|(about:\w+))(\/[^\s]*)?\b/gi, space_regex=/ /g, http_regex=/^((https?|nntp|news|telnet|irc|ftp)\:\/\/)|(about:\w+)/i, txt=/\.txt$/i;
  43.  
  44. var black_tags = ["a", "script", "style", "textarea", "title", "option", "pre"+(txt.test(location.href)?"allowTxt":""), "code"];
  45. var path = ".//text()[not(parent::" + black_tags.join(" or parent::") +")]";
  46.  
  47. textNodes = document.evaluate(path, document.body, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  48.  
  49. for (var i=0,item; (item=textNodes.snapshotItem(i)); i++){
  50. var itemText = item.nodeValue;
  51. if (regex.test(itemText)){
  52. var span=document.createElement("span");
  53. var lastLastIndex = 0;
  54. regex.lastIndex = 0;
  55. for (var myArray = null; myArray = regex.exec(itemText); ){
  56. var link = myArray[0];
  57. span.appendChild(document.createTextNode(itemText.substring(lastLastIndex, myArray.index)));
  58. var href = link.replace(space_regex,""),
  59. text = (link.indexOf(" ")==0)?link.substring(1):link;
  60. if (!http_regex.test(href)) href="http://"+href;
  61. var a = document.createElement("a");
  62. a.setAttribute("href", href.toLowerCase());
  63. a.setAttribute("target", "newWin"); // open in a new window/tab
  64. a.appendChild(document.createTextNode(text.substring(0,1).toUpperCase()+text.substring(1)));
  65. if ((link.indexOf(" ")==0)) span.appendChild(document.createTextNode(" "));
  66. span.appendChild(a);
  67. lastLastIndex = regex.lastIndex;
  68. }
  69. span.appendChild(document.createTextNode(itemText.substring(lastLastIndex)));
  70. item.parentNode.replaceChild(span, item);
  71. }
  72. }
  73. })();