scrape
by
noromanba
2015-12-27 [2015/12/27 11:44:19]
download current html snapshot
/*
* @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
// 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();
})();
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。