scrape

    @@ -24,7 +24,7 @@ // POSIX class [:punct:] not impl yet, alt expanded ASCII c.f. // http://www.regular-expressions.info/posixbrackets.html#class // [!"#$%&'()*+,\-.:;<=>?@[\\\]^_`{|}~] minus "-._" plus "\s" - const PUNCT = /[!"#$%&'()*+,/:;<=>?@[\\\]^`{|}~\s]/g; + const PUNCT = /[!"#$%&'()*+,:;<=>?@[\\\]^`{|}~\s]/g; const filename = decodeURIComponent([ location.hostname, location.pathname.split('/').slice(1).join('_'),
  • /*
     * @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
    // thx id:todays_mitsui
    
    // 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');
        // POSIX class [:punct:] not impl yet, alt expanded ASCII c.f.
        // http://www.regular-expressions.info/posixbrackets.html#class
        // [!"#$%&'()*+,\-.:;<=>?@[\\\]^_`{|}~] minus "-._" plus "\s"
        const PUNCT = /[!"#$%&'()*+,:;<=>?@[\\\]^`{|}~\s]/g;
        const filename = decodeURIComponent([
            location.hostname,
            location.pathname.split('/').slice(1).join('_'),
            location.search,
            location.hash
        ].filter(s => !!s).join('_'))
        .replace(PUNCT,'_').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