Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Fimfiction Clickable Links
- // @description Changes broken URL text into clickable links.
- // @namespace http://www.fimfiction.net/user/Flutterpony
- // @include http*://www.fimfiction.net/*
- // @version 1.0.0
- // @grant none
- // ==/UserScript==
- var regex = /((?:h.*ps?\:\/\/)*\w+\.\w+(?:(?:(?:\.\w+)|(\.\w+\/[^\s\<]*))|(?:\/[^\s\<"]*))+)/i;
- var reHTTP = /h.*ps?\:\/\//i;
- $("div.comment_data p").each(function() {
- var text = $(this).html();
- $(this).html(text.replace(regex, function(match) {
- var url = match
- // get "s" if applicable or store empty string
- var secure = (url.match(/s(?=\:\/\/\w+\.\w+)/i) + "").replace(/null/, "");
- // start link tag and add "http(s)://" prefix
- return "<a href='http" + secure + "://" +
- // strip off any "http(s)://" prefix (for complete URL text) and add the rest
- match.replace(reHTTP, "") +
- // close link tag around original broken URL
- "' target='_blank'>" + match + "</a>";
- //return "<a href='http" + match.replace(reHTTP, match.match(/s(?=\:\/\/)/) + "://").replace(/null/,"") + "' target='_blank'>" + match + "</a>";
- }));
- });
Advertisement
Add Comment
Please, Sign In to add comment