Ebay URL Cleaner/ shorter

Show the shortest possible URL for Ebay items.

// ==UserScript==
// @name        Ebay URL Cleaner/ shorter 
// @description Show the shortest possible URL for Ebay items.
// @namespace   https://arantius.com/misc/greasemonkey/
// @match       https://www.ebay.com/itm/*
// @run-at      document-start
// @version     1
// @grant       none
// @icon        https://pages.ebay.com/favicon.ico
// ==/UserScript==

function getProductId() {
  var m;
  m = document.location.href.match(/(?:.+\/)?itm\/([^/?]+)/);
  if (m) return m[1];
}

var productId = getProductId();
if (productId) {
  history.replaceState(
      {}, document.title, 'https://www.ebay.com/itm/' + productId);
}