Amaznorm

    @@ -1,11 +1,11 @@ /* * @title Amaznorm * @description normalize redundant url/canonical on www.amazon.tld - * @include http://www.amazon.tld/* + * @include https://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/* + * @include https://www.amazon.com.au/* + * @include https://www.amazon.com.br/* + * @include https://www.amazon.com.mx/* * @license MIT License http://opensource.org/licenses/MIT * @javascript_url */ @@ -16,34 +16,44 @@ // 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 +// https://www.amazon.co.jp/%E5%87%8D%E7%B5%90%E9%98%B2%E6%AD%A2%E5%89%A4-%E5%A1%A9%E5%8C%96%E3%83%8A%E3%83%88%E3%83%AA%E3%82%A6%E3%83%A025kg%C3%9740%E8%A2%8B-%E5%90%88%E8%A8%881000kg-%E8%9E%8D%E9%9B%AA%E5%89%A4-%E5%86%B7%E5%87%8D%E9%96%A2%E4%BF%82%E3%81%AE%E3%83%96%E3%83%A9%E3%82%A4%E3%83%B3/dp/B018QKEPII +// | +// v +// https://www.amazon.co.jp/dp/B018QKEPII -(function () { - var path = location.pathname; +// K*ndle manga trial +// http://let.hatelabo.jp/noromanba/let/hJmc2OiUh-0u + +(() => { + 'use strict'; // ".com.xx" unsupported Magic TLD c.f. - // http://wiki.greasespot.net/Magic_TLD + // https://web.archive.org/https://wiki.greasespot.net/Magic_TLD // https://publicsuffix.org/list/ // 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/'))) { + // TBD omit hostname assertion + if (!/(?:www\.)*amazon\.[a-z]{2,3}(?:\.[a-z]{2})*$/.test(location.hostname) || + !['/dp/', '/gp/', '/ASIN/', ].find(s => location.pathname.includes(s))) { return; } + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find + // -> 1st-exists | undefined - var canon = (document.head.querySelector('link[rel="canonical"][href]') || {}); + const 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 = [ + // https://www.amazon.<TLD>/<URL_ENCODED_ITEM_NAME>/dp/<ASIN> + const norm = [ location.origin, '/', - new URL(canon.href).pathname.split('/').slice(-2).join('/') + new URL(canon.href).pathname.split('/').slice(-2).join('/'), ].join(''); - canon.href = norm; // avoid canonical mismatch + // avoid canonical mismatch + canon.href = norm; //* window.history.pushState(null, null, norm); /*/ @@ -52,3 +62,11 @@ //*/ })(); + +// DEV +// +// https://www.amazon.co.jp/%E3%83%97%E3%83%AA%E3%83%B3%E3%83%86%E3%82%A3%E3%83%B3%E3%82%B0-%E9%AB%98%E3%81%95472cm%EF%BC%81%E3%83%96%E3%83%A9%E3%82%AD%E3%82%AA%E3%82%B5%E3%82%A6%E3%83%AB%E3%82%B9%E5%A4%A7%E5%9E%8B%E9%80%A0%E5%BD%A2%E7%89%A9%EF%BC%88%E6%81%90%E7%AB%9C%E7%AD%89%E8%BA%AB%E5%A4%A7%E3%83%95%E3%82%A3%E3%82%AE%E3%83%A5%E3%82%A2%EF%BC%89/dp/B00789E5H0 +// https://www.amazon.co.jp/dp/B00789E5H0 +// https://www.amazon.co.jp/One-Only-Jewellery-%E9%91%91%E5%AE%9A%E6%9B%B8%E4%BB%98%E3%80%91%E3%83%80%E3%82%A4%E3%83%A4%E3%83%A2%E3%83%B3%E3%83%89-31-04ct/dp/B07CJH1YP1 +// https://www.amazon.co.jp/dp/B018QKEPII +
  • /*
     * @title Amaznorm
     * @description normalize redundant url/canonical on www.amazon.tld
     * @include https://www.amazon.tld/*
     * @include https://www.amazon.com/*
     * @include https://www.amazon.com.au/*
     * @include https://www.amazon.com.br/*
     * @include https://www.amazon.com.mx/*
     * @license MIT License http://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    // ready to use @run-at document-body
    
    // UserScript
    // https://gist.github.com/noromanba/da0de2ed47a381ee8c1e
    
    // e.g.
    // https://www.amazon.co.jp/%E5%87%8D%E7%B5%90%E9%98%B2%E6%AD%A2%E5%89%A4-%E5%A1%A9%E5%8C%96%E3%83%8A%E3%83%88%E3%83%AA%E3%82%A6%E3%83%A025kg%C3%9740%E8%A2%8B-%E5%90%88%E8%A8%881000kg-%E8%9E%8D%E9%9B%AA%E5%89%A4-%E5%86%B7%E5%87%8D%E9%96%A2%E4%BF%82%E3%81%AE%E3%83%96%E3%83%A9%E3%82%A4%E3%83%B3/dp/B018QKEPII
    // |
    // v
    // https://www.amazon.co.jp/dp/B018QKEPII
    
    // K*ndle manga trial
    // http://let.hatelabo.jp/noromanba/let/hJmc2OiUh-0u
    
    (() => {
        'use strict';
    
        // ".com.xx" unsupported Magic TLD c.f.
        // https://web.archive.org/https://wiki.greasespot.net/Magic_TLD
        // https://publicsuffix.org/list/
        // https://en.wikipedia.org/wiki/Amazon.com#Website
        // TBD omit hostname assertion
        if (!/(?:www\.)*amazon\.[a-z]{2,3}(?:\.[a-z]{2})*$/.test(location.hostname) ||
            !['/dp/', '/gp/', '/ASIN/', ].find(s => location.pathname.includes(s))) {
            return;
        }
        // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
        //  -> 1st-exists | undefined
    
        const canon = (document.head.querySelector([
            'link[rel="canonical"][href]'
        ]) || {});
        if (!canon || !canon.href) return;
    
        // redundant canonical syntax;
        // https://www.amazon.<TLD>/<URL_ENCODED_ITEM_NAME>/dp/<ASIN>
        const norm = [
            location.origin,
            '/',
            new URL(canon.href).pathname.split('/').slice(-2).join('/'),
        ].join('');
    
        // avoid canonical mismatch
        canon.href = norm;
        //*
        window.history.pushState(null, null, norm);
        /*/
        // TODO title blank in Browser History
        window.history.replaceState(null, document.title, norm);
        //*/
    })();
    
    
    // DEV
    //
    // https://www.amazon.co.jp/%E3%83%97%E3%83%AA%E3%83%B3%E3%83%86%E3%82%A3%E3%83%B3%E3%82%B0-%E9%AB%98%E3%81%95472cm%EF%BC%81%E3%83%96%E3%83%A9%E3%82%AD%E3%82%AA%E3%82%B5%E3%82%A6%E3%83%AB%E3%82%B9%E5%A4%A7%E5%9E%8B%E9%80%A0%E5%BD%A2%E7%89%A9%EF%BC%88%E6%81%90%E7%AB%9C%E7%AD%89%E8%BA%AB%E5%A4%A7%E3%83%95%E3%82%A3%E3%82%AE%E3%83%A5%E3%82%A2%EF%BC%89/dp/B00789E5H0
    //  https://www.amazon.co.jp/dp/B00789E5H0
    // https://www.amazon.co.jp/One-Only-Jewellery-%E9%91%91%E5%AE%9A%E6%9B%B8%E4%BB%98%E3%80%91%E3%83%80%E3%82%A4%E3%83%A4%E3%83%A2%E3%83%B3%E3%83%89-31-04ct/dp/B07CJH1YP1
    //  https://www.amazon.co.jp/dp/B018QKEPII
    
    
  • 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