KMT

  • /*
     * @title KMT
     * @description K*ndle manga trial
     * @include https://www.amazon.tld/*
     * @contributor cat2151 http://let.hatelabo.jp/cat2151/let/hLHU2LGPnagi
     * @license MIT License https://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    /* for mobile and/or too old browsers
    javascript:(function(){var a=document.head.querySelector(['link[rel="canonical"][href]'])||{};if(a&&a.href){var b=a.href.split('/').pop();if(b){var c='.'+location.hostname.split('.').slice(2).join('.');window.open('https://read.amazon'+c+'/manga/'+b+'?sample=true','_blank')}}})();
    */
    // transpile and minify w/ Babili
    // https://babeljs.io/repl/
    
    // c.f.
    // http://let.hatelabo.jp/noromanba/let/hJmcjrPV1ecx
    
    // e.g. Terra Formars, Vol. 1
    // https://www.amazon.co.jp/dp/B00C9DYZFC
    //  https://read.amazon.co.jp/manga/B00C9DYZFC?sample=true
    (() => {
        'use strict';
    
        // comics page nullable "#ASIN"
        // c.f.
        // http://let.hatelabo.jp/noromanba/let/hJmcjrPV1ecx
        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>
        /*/
        // readable but incompatible [1]
        const asin = new URL(canon.href).pathname.split('/').pop();
        //*/
        const asin = canon.href.split('/').pop();
        //*/
        if (!asin) return;
    
        // remove "www.amazon." -> TLD [2]
        const tld = '.' + location.hostname.split('.').slice(2).join('.');
        // TODO this syntax only .co.jp
        const reader = 'https://read.amazon' + tld + '/manga/' + asin + '?sample=true';
    
        window.open(reader, '_blank');
    })();
    
    // DBG
    //
    // [:1] omit IE and Android 4.4.3< due to URL API c.f.
    // https://caniuse.com/#feat=url
    // https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#Browser_compatibility
    // https://developer.mozilla.org/en-US/docs/Web/API/URL#Browser_compatibility
    // https://developer.microsoft.com/en-us/microsoft-edge/platform/status/urlapi/
    //
    // [:2] TLDs e.g. Terra Formars, Vol. 1
    // https://www.amazon.co.jp/dp/B00C9DYZFC
    // https://www.amazon.com/dp/B00LH87EBC
    // https://www.amazon.com.au/dp/1421571544
    // https://www.amazon.com.mx/dp/1421571544
    // https://www.amazon.com.br/dp/8545700423
    //  .com.mx and .com.br has not Kindle yet
    
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2018/04/15 09:03:28 - 2018-04-15
  2. 2018/04/15 08:38:09 - 2018-04-15
  3. 2018/04/15 08:34:50 - 2018-04-15
  4. 2018/04/15 08:34:24 - 2018-04-15