2txt
@@ -1,41 +1,82 @@
/*
- * @title 【スマホ用】プレーンテキストでコピペしたい。
- * @description サイト上のテキスト書式をリセットします。
+ * @title 2txt
+ * @description show page text for copy
* @include http://*
- * @license MIT License
- * @require
-iPhone Safariで確認。
-4/26 viewport を設定する、等。
+ * @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
*/
-(function(){
- //viewport
- var meta = document.createElement('meta');
- meta.setAttribute('name','viewport');
- meta.setAttribute('content','width=device-width,initial-scale=1');
- document.getElementsByTagName('head')[0].appendChild(meta);
-
- //text
- var body=document.body.innerText
- .split(String.fromCharCode(160)).join(" ") // -> space
- .replace(/\r?\n/g,'\n') //改行コード -> 統一
- .replace(/[ \t ]{2,}/g,' ') //[ など]の連続 -> space一つ
- .replace(/[ \t ]\n/g,'\n') //行末の[ など] -> 削除
- .replace(/\n{3,}/g,'\n\n'); //¥nの3つ以上の連続 -> ¥n¥n
-
- //css
- var bodyStyle=document.getElementsByTagName('body')[0].style;
- bodyStyle.all='initial'; //reset
- bodyStyle.width=window.innerWidth+'px';
- bodyStyle.height='100%';
- bodyStyle.overFlow='hidden';
- document.getElementsByTagName('html')[0].style.height=window.innerHeight+'px';
-
- body='<textarea style="padding:6px;width:94%;height:100%;font-size:16px;border-radius:0" readonly>'+body+'</textarea>';
- document.body.innerHTML=body;
-})()
+// beautify 4-space indent from 3-space indent
-//js minify
+(function() {
+ 'use strict';
+
+ var head = document.head || document.querySelector('head') ||
+ document.documentElement.firstElementChild;
+
+ // PDFium has not head
+ if (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';
+
+ var html = document.documentElement || document.querySelector('html');
+ 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');
+
+ 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();
+})();
+
+// minified
+// https://chriszarate.github.io/bookmarkleter/
/*
-javascript:(function(){var c=document.createElement("meta");c.setAttribute("name","viewport");c.setAttribute("content","width=device-width,initial-scale=1");document.getElementsByTagName("head")[0].appendChild(c);var b=document.body.innerText.split(String.fromCharCode(160)).join(" ").replace(/\r?\n/g,"\n").replace(/[ \t ]{2,}/g," ").replace(/[ \t ]\n/g,"\n").replace(/\n{3,}/g,"\n\n");var a=document.getElementsByTagName("body")[0].style;a.all="initial";a.width=window.innerWidth+"px";a.height="100%";a.overFlow="hidden";document.getElementsByTagName("html")[0].style.height=window.innerHeight+"px";b='<textarea style="padding:6px;width:94%;height:100%;font-size:16px;border-radius:0" readonly>'+b+"</textarea>";document.body.innerHTML=b})();
+javascript:(function(){var e=document.head||document.querySelector("head")||document.documentElement.firstElementChild;if(e){var t=document.createElement("meta");t.name="viewport",t.content="width=device-width, initial-scale=1",e.appendChild(t)}var n=document.body.style;n.all="initial",n.maxWidth="100%",n.height="100%",n.overFlow="hidden",(document.documentElement||document.querySelector("html")).style.height=window.innerHeight+"px";var i=document.body.innerText.split(String.fromCharCode(160)).join(" ").replace(/\r?\n/g,"\n").replace(/[ \t ]{2,}/g," ").trim().replace(/\n{3,}/g,"\n\n"),d=['<textarea style="',"padding: 6px;","width: 94%;","height: 100%;","font-size: 16px;","border-radius: 0;",'" readonly>',i,"</textarea>"].join("");document.body.innerHTML=d})();
*/
+
/*
* @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
*/
// beautify 4-space indent from 3-space indent
(function() {
'use strict';
var head = document.head || document.querySelector('head') ||
document.documentElement.firstElementChild;
// PDFium has not head
if (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';
var html = document.documentElement || document.querySelector('html');
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');
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();
})();
// minified
// https://chriszarate.github.io/bookmarkleter/
/*
javascript:(function(){var e=document.head||document.querySelector("head")||document.documentElement.firstElementChild;if(e){var t=document.createElement("meta");t.name="viewport",t.content="width=device-width, initial-scale=1",e.appendChild(t)}var n=document.body.style;n.all="initial",n.maxWidth="100%",n.height="100%",n.overFlow="hidden",(document.documentElement||document.querySelector("html")).style.height=window.innerHeight+"px";var i=document.body.innerText.split(String.fromCharCode(160)).join(" ").replace(/\r?\n/g,"\n").replace(/[ \t ]{2,}/g," ").trim().replace(/\n{3,}/g,"\n\n"),d=['<textarea style="',"padding: 6px;","width: 94%;","height: 100%;","font-size: 16px;","border-radius: 0;",'" readonly>',i,"</textarea>"].join("");document.body.innerHTML=d})();
*/
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。