Reddit Flair Linkifier

Turns the text in various subreddits' flair into links

当前为 2018-04-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Reddit Flair Linkifier
  3. // @namespace https://greasyfork.org/users/649
  4. // @version 2.0.1
  5. // @description Turns the text in various subreddits' flair into links
  6. // @author Adrien Pyke
  7. // @match *://*.reddit.com/*
  8. // @require https://cdn.rawgit.com/fuzetsu/userscripts/477063e939b9658b64d2f91878da20a7f831d98b/wait-for-elements/wait-for-elements.js
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (() => {
  13. 'use strict';
  14.  
  15. waitForElems({
  16. sel: [
  17. // old reddit
  18. 'span.flair',
  19.  
  20. // card template
  21. '.Post > div:nth-of-type(2) > div:nth-of-type(1) > div > div:nth-of-type(1) > div:nth-of-type(2) > span',
  22. // classic template
  23. '.Post > div:nth-of-type(2) > div > div:nth-of-type(2) > div:nth-of-type(2) > div:nth-of-type(1) > div:nth-of-type(2) > span',
  24. // compact template
  25. '.Post > div > div:nth-of-type(2) > div > div:nth-of-type(2) > div:nth-of-type(2) > div:nth-of-type(2) > span',
  26.  
  27. // comments
  28. '.Comment > div:nth-of-type(2) > div:nth-of-type(1) > div:nth-of-type(2) > span',
  29.  
  30. // moderators
  31. '.cIMsMe > div > span',
  32.  
  33. // user flair preview
  34. '.QAshv > div > span',
  35.  
  36. // flair edit
  37. '.fhMwuu > div > span'
  38. ].join(','),
  39. onmatch(flair) {
  40. flair.innerHTML = flair.textContent.split(' ').map(segment => {
  41. if (segment.match(/^https?:\/\//)) {
  42. return `<a href="${segment}" target="_blank" rel="noopener noreferrer">${segment}</a>`;
  43. } else {
  44. return segment;
  45. }
  46. }).join(' ');
  47. }
  48. });
  49. })();