Guest User

Link Reddit Flair - www ==> http://www

a guest
Jul 4th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Link Reddit Flair
  2. // Author: Ictinus
  3. // Released and updated: 16 September 2011, turn reddit flair text to links (if they start with http).
  4. // ==UserScript==
  5. // @name            Link Reddit Flair
  6. // @version         1.05
  7. // @namespace       http://ictinus.com/lrf/
  8. // @description     Turn reddit flair text to links if appropriate.
  9. // @match   http://*.reddit.com/*
  10. // @match   https://*.reddit.com/*
  11. // ==/UserScript==
  12.  
  13. // Updated: 21 Oct 2011, v1.02, added https support and removed scary "Requires your data on all websites" permission requirements.
  14. // Updated: 06 Nov 2011, v1.03, change link to display the users name and site name eg. "auser's goodread" (for www.goodread.com).
  15. //                      add support for flair format of "link description:http://www.goodread.com/" which will display as "link descrption".
  16. //                      v1.04, bug fix.
  17. // Updated: 17 Nov 2011, v1.05, improved linking
  18.  
  19. var linkRedditFlair = {
  20.     version : 1.05,
  21.     changeFlairText: function () {
  22.         var theFlairs = document.getElementsByClassName("flair");
  23.         for (var iFlair = 0, iFlairTotal = theFlairs.length; iFlair < iFlairTotal; iFlair++) {
  24.             lnkText = theFlairs[iFlair].innerHTML;
  25.             if (lnkText.substring(0, 4) == 'www.') { lnkText = 'http://' + theFlairs[iFlair].innerHTML; }
  26.             try {
  27.                 if (lnkText.substring(0, 7) == 'http://') {
  28.                     var arrLnk = lnkText.split("/");
  29.                     var arrSite = arrLnk[2].split('.');
  30.                     if (typeof(arrSite[1]) == 'undefined' || arrSite.length < 3) {throw "error";};
  31.                     var strUser = theFlairs[iFlair].previousElementSibling.innerHTML;
  32.                     theFlairs[iFlair].innerHTML = '<a href="' + lnkText + '">' + strUser + "'s " + arrSite[1] + '</a>';
  33.                 } else if (lnkText.split(":http").length > 1) {
  34.                     var strLinkDesc = lnkText.split(":http")[0];
  35.                     var strLink = lnkText.substring(strLinkDesc.length + 1, lnkText.length);
  36.                     theFlairs[iFlair].innerHTML = '<a href="' + strLink + '">' + strLinkDesc + '</a>';
  37.                 }
  38.             } catch(e) {
  39.                 if (lnkText.substring(0, 7) == 'http://') {
  40.                     theFlairs[iFlair].innerHTML = '<a href="' + lnkText + '">' + lnkText.substring(7,lnkText.length) + '</a>';
  41.                 }
  42.             }
  43.         }
  44.     },
  45.     init: function() {
  46.         this.changeFlairText();
  47.     }
  48. }
  49. document.addEventListener('load',linkRedditFlair.init(),true);
Add Comment
Please, Sign In to add comment