Reddit: Direct Links

Removes redirect on outbound links.

  1. // ==UserScript==
  2. // @name Reddit: Direct Links
  3. // @namespace https://reddit.com/
  4. // @description Removes redirect on outbound links.
  5. // @version 7
  6. // @match *://*.reddit.com/*
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10.  
  11. // March 16: 2016: (Source Code) https://www.reddit.com/r/privacy/comments/4aqdg0/reddit_started_tracking_the_links_we_click_heres/
  12. // July 6, 2016: https://www.reddit.com/r/changelog/comments/4rl5to/outbound_clicks_rollout_complete/
  13. // July 7: 2016: https://www.reddit.com/r/technology/comments/4rpkt8/reddit_now_tracks_all_outbound_link_clicks_by/
  14.  
  15. // Note that the second version of the origional script doesn't work, as it will send you to https://www.reddit.com/undefined since the javascript event listeners are still attached.
  16. // We fix this by replacing the link with a new element.
  17.  
  18. var el = function(html) {
  19. var e = document.createElement('div');
  20. e.innerHTML = html;
  21. return e.removeChild(e.firstChild);
  22. };
  23.  
  24. var copyAttr= function(a, b, attr) {
  25. var val = a.getAttribute(attr);
  26. if (val) {
  27. b.setAttribute(attr, val);
  28. }
  29. }
  30.  
  31. function main() {
  32. for(var a of document.getElementsByTagName('a')) {
  33. if (a.hasAttribute('data-href-url')) {
  34. var actualFuckingUrl = a.getAttribute('data-href-url');
  35. //a.setAttribute('href', actualFuckingUrl);
  36. //a.removeAttribute('data-href-url');
  37. //a.removeAttribute('data-outbound-url');
  38. //a.removeAttribute('data-outbound-expiration');
  39. a.classList.remove('outbound');
  40.  
  41. var b = el('<a />');
  42. b.href = actualFuckingUrl;
  43. b.classList = a.classList;
  44. copyAttr(a, b, 'title');
  45. copyAttr(a, b, 'tabindex');
  46. b.innerHTML = a.innerHTML;
  47. b.setAttribute('rel', 'noreferrer');
  48.  
  49. a.parentNode.insertBefore(b, a);
  50. a.remove();
  51. }
  52. }
  53. }
  54.  
  55. main();
  56. setInterval(main, 3000);