/*
* @title 2txt
* @description show page text for copy
* @include http://*
* @include https://*
* @contributor tokyo_2020 http://let.hatelabo.jp/tokyo_2020/let/hJme68iP0Yt-
* @license MIT License https://opensource.org/licenses/MIT
* @version 2017.4.27.0
* @javascript_url
*/
/* for mobile
javascript:(function(){var a=document.documentElement||document.querySelector('html'),b=document.head||document.querySelector('head')||a.firstElementChild;if(b&&'head'===b.nodeName.toLowerCase()){var c=document.createElement('meta');c.name='viewport',c.content='width=device-width, initial-scale=1',b.appendChild(c)}var d=document.body.style;d.all='initial',d.maxWidth='100%',d.height='100%',d.overFlow='hidden',a.style.height=window.innerHeight+'px';var e=document.body.innerText.split(String.fromCharCode(160)).join(' ').replace(/\r?\n/g,'\n').replace(/[ \t ]{2,}/g,' ').trim().replace(/\n{3,}/g,'\n\n'),f=['<textarea style="','padding: 6px;','width: 94%;','height: 100%;','font-size: 16px;','border-radius: 0;','" readonly>',e,'</textarea>'].join('');document.body.innerHTML=f})();
*/
// minified w/ Babili
// https://babeljs.io/repl/
// beautify 4-space indent from 3-space indent
(function() {
'use strict';
var html = document.documentElement || document.querySelector('html');
var head = document.head || document.querySelector('head') ||
html.firstElementChild;
// PDFium has not head
if (head && head.nodeName.toLowerCase() === 'head') {
var viewport = document.createElement('meta');
viewport.name = 'viewport';
viewport.content = 'width=device-width, initial-scale=1';
head.appendChild(viewport);
}
var bodyStyle = document.body.style;
// XXX rough and tangled
bodyStyle.all = 'initial';
// TBD disable css and contentEditable
//Array.prototype.forEach.call(document.styleSheets, function(sheet) {
// sheet.disabled = true;
//});
//bodyStyle.width = window.innerWidth + 'px';
bodyStyle.maxWidth = '100%';
bodyStyle.height = '100%';
bodyStyle.overFlow = 'hidden';
html.style.height = window.innerHeight + 'px';
var letter = document.body.innerText
// 160:
.split(String.fromCharCode(160)).join(' ')
.replace(/\r?\n/g,'\n')
// include U+3000 "IDEOGRAPHIC SPACE" aka "Zenkaku Space"
.replace(/[ \t ]{2,}/g,' ')
.trim()
// 3+ times linebreak -> 2 times
.replace(/\n{3,}/g,'\n\n');
// TBD heredoc func c.f.
// https://github.com/to/tombloo/blob/d040ea4/xpi/chrome/content/library/01_utility.js#L2489
// http://let.hatelabo.jp/noromanba/let/hJmcrJG18dRE
var area = [
'<textarea style="',
'padding: 6px;',
'width: 94%;',
'height: 100%;',
'font-size: 16px;',
'border-radius: 0;',
'" readonly>',
letter,
'</textarea>'
].join('');
// TBD wrap
//area.style.wordBreak = 'break-word';
//area.style.whiteSpace = 'pre-wrap';
document.body.innerHTML = area;
// TBD selection
//area.focus();
//area.select();
})();