Eventbrite - remove tracking url

Remove the tracking parameter in links

  1. // ==UserScript==
  2. // @name Eventbrite - remove tracking url
  3. // @namespace https://github.com/Procyon-b
  4. // @version 0.1
  5. // @description Remove the tracking parameter in links
  6. // @author Achernar
  7. // @match https://www.eventbrite.com/*
  8. // @match https://www.eventbrite.co.uk/*
  9. // @match https://www.eventbrite.fr/*
  10. // @match https://www.eventbrite.se/*
  11. // @run-at document-start
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. "use strict";
  17. var t;
  18.  
  19. function fix(u) {
  20. return u.replace('?', '?&').replace(/&aff=[^&#]*/g, '').replace('?&', '?').replace(/\?$/, '');
  21. }
  22.  
  23. if (t=location.search) {
  24. let s=fix(t);
  25. if (s!=t) history.replaceState(null, null, (s || location.pathname)+location.hash);
  26. }
  27.  
  28. function fixL(L) {
  29. let i=0, a, j=0;
  30. for (;a=L[j];j++) {
  31. if (a.LnkFixed || !a.href) continue;
  32. if (a.protocol && a.protocol.startsWith('http') && a.host.includes('eventbrite.') && a.search) {
  33. let s=fix(a.search);
  34. if (a.search != s) a.search=s;
  35. }
  36. a.LnkFixed=1;
  37. }
  38. }
  39.  
  40. function init() {
  41. new MutationObserver(function(mutL){
  42. for (let m of mutL) {
  43. if (m.addedNodes) {
  44. let e=m.target.querySelectorAll(':scope a');
  45. if (e.length) fixL(e);
  46. }
  47. }
  48. }).observe(document, {childList:true, subtree:true});
  49.  
  50. fixL(document.links);
  51. }
  52.  
  53. window.addEventListener('load', function(){fixL(document.links)});
  54. if (document.readyState != 'loading') init();
  55. else document.addEventListener('DOMContentLoaded', init);
  56.  
  57. })();