scrape

    @@ -10,6 +10,9 @@ // via // http://blog.mudatobunka.org/entry/2015/12/23/211425 +// c.f. +// http://h.hatena.ne.jp/noromanba/81805704781216737 + // omit window.webkitURL, old/minor browsers only // https://developer.mozilla.org/en-US/docs/Web/API/URL#Browser_compatibility // https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL#Browser_compatibility @@ -36,3 +39,7 @@ pool.click(); })(); +// FYI +// if you need <html> tree w/o <!DOCTYPE>, like this; +// const snapshot = document.documentElement.outerHTML +
  • /*
     * @title scrape
     * @description download current html snapshot
     * @include http://*
     * @include https://*
     * @license MIT License http://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    // via
    // http://blog.mudatobunka.org/entry/2015/12/23/211425
    
    // c.f.
    // http://h.hatena.ne.jp/noromanba/81805704781216737
    
    // omit window.webkitURL, old/minor browsers only
    // https://developer.mozilla.org/en-US/docs/Web/API/URL#Browser_compatibility
    // https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL#Browser_compatibility
    (() => {
        'use strict';
    
        const pool = document.createElement('a');
        const filename = decodeURIComponent([
                location.hostname,
                location.pathname.split('/').slice(1).join('_'),
                location.search,
                location.hash
        ].filter(s => !!s).join('_'))
        .replace(/[,:;@&=~%\+\$\?#]/g,'_').replace(/(?:_){2,}/g, '_') + '.html';
        pool.download = filename;
    
        // get <!DOCTYPE> and <html> tree, old new thing; c.f.
        // https://developer.mozilla.org/en-US/docs/XMLSerializer
        // http://caniuse.com/#feat=xml-serializer
        const snapshot = new XMLSerializer().serializeToString(document);
        const snapURL = window.URL.createObjectURL(new Blob([snapshot]));
        pool.href = snapURL;
    
        pool.click();
    })();
    
    // FYI
    // if you need <html> tree w/o <!DOCTYPE>, like this;
    // const snapshot = document.documentElement.outerHTML
    
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2015/12/27 11:44:19 - 2015-12-27
  2. 2015/12/27 11:02:08 - 2015-12-27
  3. 2015/12/27 08:30:51 - 2015-12-27
  4. 2015/12/27 08:25:26 - 2015-12-27
  5. 2015/12/26 06:22:11 - 2015-12-26
  6. 2015/12/26 05:54:07 - 2015-12-26
  7. 2015/12/26 05:34:42 - 2015-12-26