Arbalist / Amazon URL Fixer

// ==UserScript==
// @name         Amazon URL Fixer
// @namespace    https://github.com/TheArbalist
// @version      0.1
// @description  Redirect from homepage
// @author       Arbalist
// @match        *://www.amazon.com*/gp/*
// @include        *://www.amazon.com*/dp/*
// @run-at       document-start
// @grant        none
// @license MIT
// @updateURL https://openuserjs.org/meta/Arbalist/Amazon_URL_Fixer.meta.js
// ==/UserScript==

(function() {
    var html = document.documentElement.innerHTML,
        gpProduct = location.href.indexOf('/gp/product/'),
        gpCustomerReviews = location.href.indexOf('/gp/customer-reviews/'),
        dp = location.href.indexOf('/dp/'),
        path;

    if (gpProduct != -1)
        path = '/gp/product/' + location.href.split('/gp/product/')[1].split('/')[0];
    else if (gpCustomerReviews != -1)
        path = '/gp/customer-reviews/' + location.href.split('/gp/customer-reviews/')[1].split('/')[0];
    else if (dp != -1)
        path = '/dp/' + location.href.split('/dp/')[1].split('/')[0];

    history.replaceState(null, null, path.split('?')[0]);
})();