2txt Fork

    @@ -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); + // beautify 4-space indent from 3-space indent - //text - var body=document.body.innerText - .split(String.fromCharCode(160)).join(" ") //&nbsp; -> 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 + (function() { + 'use strict'; - //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'; + var head = document.head || document.querySelector('head') || + document.documentElement.firstElementChild; - body='<textarea style="padding:6px;width:94%;height:100%;font-size:16px;border-radius:0" readonly>'+body+'</textarea>'; - document.body.innerHTML=body; - })() + // PDFium has not head + if (head) { + var viewport = document.createElement('meta'); + viewport.name = 'viewport'; + viewport.content = 'width=device-width, initial-scale=1'; - //js minify + 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: &nbsp; + .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: &nbsp;
            .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 です。

History

  1. 2017/04/28 17:18:24 - 2017-04-28
  2. 2017/04/28 00:57:20 - 2017-04-28
  3. 2017/04/28 00:56:31 - 2017-04-28