ciel4

Fimfiction URL fixer

Apr 8th, 2015
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Fimfiction Clickable Links
  3. // @description Changes broken URL text into clickable links.
  4. // @namespace   http://www.fimfiction.net/user/Flutterpony
  5. // @include     http*://www.fimfiction.net/*
  6. // @version     1.0.0
  7. // @grant       none
  8. // ==/UserScript==
  9.  
  10. var regex = /((?:h.*ps?\:\/\/)*\w+\.\w+(?:(?:(?:\.\w+)|(\.\w+\/[^\s\<]*))|(?:\/[^\s\<"]*))+)/i;
  11. var reHTTP = /h.*ps?\:\/\//i;
  12.  
  13. $("div.comment_data p").each(function() {
  14.     var text = $(this).html();
  15.  
  16.     $(this).html(text.replace(regex, function(match) {
  17.         var url = match
  18.         // get "s" if applicable or store empty string
  19.         var secure = (url.match(/s(?=\:\/\/\w+\.\w+)/i) + "").replace(/null/, "");
  20.  
  21.         // start link tag and add "http(s)://" prefix
  22.         return "<a href='http" + secure + "://" +
  23.             // strip off any "http(s)://" prefix (for complete URL text) and add the rest
  24.             match.replace(reHTTP, "") +
  25.             // close link tag around original broken URL
  26.             "' target='_blank'>" + match + "</a>";
  27.  
  28.         //return "<a href='http" + match.replace(reHTTP, match.match(/s(?=\:\/\/)/) + "://").replace(/null/,"") + "' target='_blank'>" + match + "</a>";
  29.     }));
  30. });
Advertisement
Add Comment
Please, Sign In to add comment