Amaznorm

    @@ -3,12 +3,14 @@ * @description normalize redundant canonical on www.amazon.tld * @include http://www.amazon.tld/* * @include https://www.amazon.com/* + * @include http://www.amazon.com.au/* * @include http://www.amazon.com.br/* + * @include http://www.amazon.com.mx/* * @license MIT License http://opensource.org/licenses/MIT * @javascript_url */ -// ready to use @run-at document-body +// ready to use @runat document-body // UserScript // https://gist.github.com/noromanba/da0de2ed47a381ee8c1e @@ -18,10 +20,13 @@ // to // http://www.amazon.co.jp/dp/B00G9THZCW - (function () { - if (!/www\.amazon\.[\a-z]{2,}(?:\.[\a-z]{2})*/.test(location.hostname) || - location.pathname.split('/').length < 3) { // XXX strict assert + var path = location.pathname; + + // ".com.xx" unsupported Magic TLD c.f. + // https://en.wikipedia.org/wiki/Amazon.com#Website + if (!/www\.amazon\.[\a-z]{2,3}(?:\.[\a-z]{2})*$/.test(location.hostname) || + (!path.includes('/dp/') && !path.includes('/gp/'))) { return; } @@ -40,8 +45,8 @@ //* window.history.pushState(null, null, norm); /*/ - window.history.replaceState(null, null, norm); + // TODO title blank in Browser History + window.history.replaceState(null, document.title, norm); //*/ })(); -
  • /*
     * @title Amaznorm
     * @description normalize redundant canonical on www.amazon.tld
     * @include http://www.amazon.tld/*
     * @include https://www.amazon.com/*
     * @include http://www.amazon.com.au/*
     * @include http://www.amazon.com.br/*
     * @include http://www.amazon.com.mx/*
     * @license MIT License http://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    // ready to use @runat document-body
    
    // UserScript
    // https://gist.github.com/noromanba/da0de2ed47a381ee8c1e
    
    // e.g.
    // http://www.amazon.co.jp/COOKPAD-Inc-%E3%82%AF%E3%83%83%E3%82%AF%E3%83%91%E3%83%83%E3%83%89-No-1%E3%83%AC%E3%82%B7%E3%83%94%E6%A4%9C%E7%B4%A2%E3%82%A2%E3%83%97%E3%83%AA/dp/B00G9THZCW/
    // to
    // http://www.amazon.co.jp/dp/B00G9THZCW
    
    (function () {
        var path = location.pathname;
    
        // ".com.xx" unsupported Magic TLD c.f.
        // https://en.wikipedia.org/wiki/Amazon.com#Website
        if (!/www\.amazon\.[\a-z]{2,3}(?:\.[\a-z]{2})*$/.test(location.hostname) ||
            (!path.includes('/dp/') && !path.includes('/gp/'))) {
            return;
        }
    
        var canon = (document.head.querySelector('link[rel="canonical"][href]') || {});
        if (!canon || !canon.href) return;
    
        // redundant canonical syntax;
        // http://www.amazon.<TLD>/<URL_ENCODED_ITEM_NAME>/dp/<ASIN>
        var norm = [
            location.origin,
            '/',
            new URL(canon.href).pathname.split('/').slice(-2).join('/')
        ].join('');
    
        canon.href = norm; // avoid canonical mismatch
        //*
        window.history.pushState(null, null, norm);
        /*/
        // TODO title blank in Browser History
        window.history.replaceState(null, document.title, norm);
        //*/
    })();
    
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2018/06/16 01:46:55 - 2018-06-16
  2. 2016/01/24 04:36:20 - 2016-01-24
  3. 2016/01/24 04:35:10 - 2016-01-24
  4. 2015/10/18 14:05:44 - 2015-10-18
  5. 2015/10/17 09:45:10 - 2015-10-17
  6. 2015/10/17 09:41:25 - 2015-10-17
  7. 2015/10/17 09:37:18 - 2015-10-17