Greasy Fork is available in English.

Disable Disqus URL Tracking

Remove the http[s]://disq.us/url?url= Disqus added in 2016-12

  1. // ==UserScript==
  2. // @name Disable Disqus URL Tracking
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description Remove the http[s]://disq.us/url?url= Disqus added in 2016-12
  6. // @author Luke Breuer
  7. // @match *://disqus.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // not using jquery because:
  15. // https://statuscode.ch/2017/03/CSP-unsafe-eval-and-jquery/
  16. // but we can apparently trust that Disqus included it
  17.  
  18. function post_count() {
  19. return $("#conversation li.post").length;
  20. //return document.evaluate("count(//*[@id='conversation']//li[@class='post'])", document, null, XPathResult.NUMBER_TYPE, null).numberValue;
  21. }
  22.  
  23. function fix_urls() {
  24. // As of 2016-12-20, Disqus uses http tracking for http links, and https tracking for https links
  25. var urls = $("a[href^='http://disq.us/url?url='], a[href^='https://disq.us/url?url=']");
  26. //console.log("Offending URL count: " + urls.length);
  27. //console.log(post_count());
  28.  
  29. urls.each(function() {
  30. var new_url = /^https?:\/\/disq.us\/url\?url=(https?:.*?)(:.+)?(&.+)?$/i.exec(decodeURIComponent(this.href))[1];
  31. //console.log(decodeURIComponent(this.href));
  32. //console.log(new_url);
  33. this.href = new_url;
  34. });
  35. }
  36.  
  37. function wait_for_min_posts(min, max_tries, f) {
  38. var try_wait = 200; // ms
  39. var tid = setInterval(function() {
  40. if (post_count() >= min) {
  41. clearInterval(tid);
  42. f();
  43. }
  44. if (--max_tries <= 0)
  45. clearInterval(tid);
  46. }, try_wait);
  47. }
  48.  
  49. //console.log("UserScript entered");
  50.  
  51. var lastCount = 0;
  52. var iteration = 0;
  53. setInterval(function() {
  54. var count = post_count();
  55. iteration++;
  56. if (count != lastCount) {
  57. console.log(iteration, count);
  58. lastCount = count;
  59. }
  60. }, 50);
  61.  
  62. wait_for_min_posts(1, 200, function() {
  63. fix_urls();
  64. // catch additional comments loaded from navigation to specific comment (#comment-)
  65. wait_for_min_posts(post_count() + 1, 100, function() { fix_urls(); });
  66.  
  67. $('#posts > div.load-more > a').click(function() {
  68. wait_for_min_posts(post_count() + 1, 100, function() { fix_urls(); });
  69. });
  70. });
  71. })();