Tracking Hash Remover

This removes the random fragment identifiers used to track you.

  1. // ==UserScript==
  2. // @author James Edward Lewis II
  3. // @name Tracking Hash Remover
  4. // @namespace greasyfork.org
  5. // @version 0.0.1
  6. // @description This removes the random fragment identifiers used to track you.
  7. // @grant none
  8. // @include *
  9. // @license MIT
  10. // @copyright 2015+, James Edward Lewis II
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. (function trackingHashRemover(window, undefined) {
  15. 'use strict';
  16. var trackPattern = /^#?\.[a-zA-Z0-9]{8,}/, interval;
  17. function removeHash(hsh) {
  18. var subst, idx;
  19. if (typeof hsh === 'symbol') hsh = '';
  20. hsh += '';
  21. idx = hsh.indexOf('#');
  22. if (idx !== -1) {
  23. subst = hsh.slice(idx);
  24. if (trackPattern.test(subst)) return hsh.slice(0, idx);
  25. else return hsh;
  26. } else return '';
  27. }
  28. function locHashRemover() {
  29. var hsh = location.hash;
  30. if (trackPattern.test(hsh)) location.hash = '';
  31. else {
  32. clearInterval(interval);
  33. interval = null;
  34. }
  35. }
  36. function removeHashes() {
  37. var links = document.getElementsByTagName('a'),
  38. forms = document.getElementsByTagName('form'), i;
  39. interval = interval || setInterval(locHashRemover, 16);
  40. for (i in links)
  41. if (links.hasOwnProperty(i))
  42. i.hash = removeHash(i.hash);
  43. for (i in forms)
  44. if(forms.hasOwnProperty(i))
  45. i.action = removeHash(i.action);
  46. }
  47. function dclRemover() {
  48. document.removeEventListener('DOMContentLoaded', dclRemover, false);
  49. removeHashes();
  50. }
  51. function loadRemover() {
  52. window.removeEventListener('load', loadRemover, false);
  53. removeHashes();
  54. }
  55. removeHashes();
  56. document.addEventListener('readystatechange', removeHashes, false);
  57. document.addEventListener('DOMContentLoaded', dclRemover, false);
  58. window.addEventListener('load', loadRemover, false);
  59. window.addEventListener('hashchange', removeHashes, false);
  60. }(window));