Advertisement
BigBisous

UTM Stripper

Dec 13th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        UTM Stripper
  3. // @namespace   lehollandaisvolant.net
  4. // @description Remove UTM_ url parametes.
  5. // @include     *utm_source=*
  6. // @include     *utm_medium=*
  7. // @include     *utm_term=*
  8. // @include     *utm_content=*
  9. // @include     *utm_campaign=*
  10. // @version     1
  11. // ==/UserScript==
  12. (function () {
  13.   var sp = window.location.search.replace(/^\?/, '').split('&'),
  14.   sk = [
  15.   ];
  16.   for (var i = 0; i < sp.length; i++) {
  17.     if (!/^(?:utm_source|utm_medium|utm_term|utm_content|utm_campaign)$/i.test(sp[i].split('=') [0])) {
  18.       sk.push(sp[i]);
  19.     }
  20.   }
  21.   var newurl = window.location.protocol + '//' + window.location.host
  22.   + window.location.pathname + (sk.length ? '?' + sk.join('&')  : '')
  23.   + window.location.hash;
  24.   if (newurl != window.location.href) {
  25.     (!!(window.history && window.history.pushState)
  26.     ? window.history.pushState(null, null, newurl)
  27.     : window.location.replace(newurl)
  28.     );
  29.   }
  30. }) ();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement