reddit clickable linkflair

turns flairs to links that search the sub for threads with the same flair

  1. // ==UserScript==
  2. // @name reddit clickable linkflair
  3. // @namespace https://greasyfork.org/en/users/36620
  4. // @version 0.2
  5. // @description turns flairs to links that search the sub for threads with the same flair
  6. // @author scriptfairy
  7. // @match https://www.reddit.com/r/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function($) {
  12. $('<style>').text('.linkflairlabel > a, .linkflairlabel > a:visited {color:inherit;}').appendTo($('head'));
  13.  
  14. var flair, flairTitle, searchContent;
  15. var linkFlairs = $('.linkflairlabel');
  16. var sub = location.href;
  17. sub = sub.slice(0, sub.indexOf("/", sub.indexOf("/r/")+3));
  18.  
  19. for (i = 0; i < linkFlairs.length; i++) {
  20. flair = linkFlairs[i];
  21. flairTitle = $(flair).attr('title');
  22. searchContent = encodeURIComponent("flair_text:'"+flairTitle+"'").replace(/%20/g, "+");
  23. $(flair).html('<a href="'+sub+'/search?q='+searchContent+'&restrict_sr=on">'+flairTitle+'</a>');
  24. }
  25.  
  26. })(window.jQuery);