KMT

    @@ -1,9 +1,68 @@ /* - * @title Kindle漫画試し読み - * @description 選択した文字列をASINとみなして、Kindle漫画ブラウザ試し読みを開く。Kindle漫画以外は試し読みできない。利用例としては、Google検索で「作品名 kindle ASIN」で、表示されたASINを選択してブックマークレット実行。ブックマークレットの登録方法で確認済みなのは、下記のソースコードをそのままブラウザのブックマークバーにドロップする方法。それ以外は未確認。 - * @include - * @license MIT License - * @require + * @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 */ -javascript:(function(){ var d=document; var tx=d.selection?d.selection.createRange().text:d.getSelection(); var subw=window.open('https://read.amazon.co.jp/manga/'+tx+'?sample=true').document;})(); +/* 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'; + + // Kindle Manga 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; + + // c.f. + // http://let.hatelabo.jp/noromanba/let/hJmcjrPV1ecx + // redundant canonical syntax; + // https://www.amazon.<TLD>/<URL_ENCODED_ITEM_NAME>/dp/<ASIN> + /*/ + // [2] + const asin = new URL(canon.href).pathname.split('/').pop(); + //*/ + const asin = canon.href.split('/').pop(); + //*/ + if (!asin) return; + + // remove "www.amazon." -> TLD [1] + 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] 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 +// +// [:2] 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/ +
  • /*
     * @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';
    
        // Kindle Manga 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;
    
        // c.f.
        // http://let.hatelabo.jp/noromanba/let/hJmcjrPV1ecx
        // redundant canonical syntax;
        // https://www.amazon.<TLD>/<URL_ENCODED_ITEM_NAME>/dp/<ASIN>
        /*/
        // [2]
        const asin = new URL(canon.href).pathname.split('/').pop();
        //*/
        const asin = canon.href.split('/').pop();
        //*/
        if (!asin) return;
    
        // remove "www.amazon." -> TLD [1]
        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] 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
    //
    // [:2] 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/
    
    
  • 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