Skip to content

Instantly share code, notes, and snippets.

@umer936
Last active July 13, 2020 15:42
Show Gist options
  • Save umer936/fb9b7ea892386f37cb4d26154533f518 to your computer and use it in GitHub Desktop.
Save umer936/fb9b7ea892386f37cb4d26154533f518 to your computer and use it in GitHub Desktop.
Javascript bookmarklet to strip tracking tags in URLs for better bookmarking
javascript: void
function() {
var url = location.search;
if (url) {
var each = url.slice(1).split("&");
console.log("Stripping query parameters:", each);
var leave = each.filter(function(url) {
return "utm_" !== url.substr(0, 4) &&
"mc_" !== url.substr(0, 3) &&
"ct" !== url.substr(0, 2) &&
"_hsenc" !== url.substr(0, 6) &&
"_hsmi" !== url.substr(0, 5) &&
"mkt_tok" !== url.substr(0, 7) &&
"mbid" !== url.substr(0, 4)
});
if (leave.length !== each.length) {
var i = leave.join("&");
i && (i = "?" + i);
var a = location.href.replace(url, i);
history.replaceState({}, document.title, a)
}
}
}();
javascript:!function(){var t=location.search;if(t){var r=t.slice(1).split("&");console.log("Stripping query parameters:",r);var s=r.filter(function(t){return"utm_"!==t.substr(0,4)&&"mc_"!==t.substr(0,3)&&"ct"!==t.substr(0,2)&&"_hsenc"!==t.substr(0,6)&&"_hsmi"!==t.substr(0,5)&&"mkt_tok"!==t.substr(0,7)&&"mbid"!==t.substr(0,4)});if(s.length!==r.length){var e=s.join("&");e&&(e="?"+e);var i=location.href.replace(t,e);history.replaceState({},document.title,i)}}}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment