Skip to content

Instantly share code, notes, and snippets.

@jnv
Forked from paulirish/utmstrip.user.js
Last active September 5, 2015 20:55
Show Gist options
  • Save jnv/5fae44f2aba6dbc6e10e to your computer and use it in GitHub Desktop.
Save jnv/5fae44f2aba6dbc6e10e to your computer and use it in GitHub Desktop.
UTM parameters stripper – modified for Scriptish regex matching to not run on every page. https://greasyfork.org/cs/scripts/4056-utm-param-stripper
// ==UserScript==
// @name UTM param stripper
// @author Paul Irish
// @namespace http://github.com/paulirish
// @version 1.1.2
// @description Drop the UTM params from a URL when the page loads.
// @extra Cuz you know they're all ugly n shit.
// @include /^https?:\/\/.*[\?#&]utm_.*/
// @grant none
// ==/UserScript==
// Install instruction!!!!
// Click `raw` in the top right on this gist!
if (/utm_/.test(location.search) && window.history.replaceState){
// thx @cowboy for the revised hash param magic.
var oldUrl = location.href;
var newUrl = oldUrl.replace(/\?([^#]*)/, function(_, search) {
search = search.split('&').map(function(v) {
return !/^utm_/.test(v) && v;
}).filter(Boolean).join('&'); // omg filter(Boolean) so dope.
return search ? '?' + search : '';
});
if ( newUrl != oldUrl ) {
window.history.replaceState({},'', newUrl);
}
}
// also..
// drop this into your own site, in case people link to you with
// email newsletters or your rss feed's feedburner tracking or whatever.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment