T/U area Fork

    @@ -1,52 +1,62 @@ /* - * @title title and url (for copy) - * @description タイトルと URL をコピーするための TEXTAREA + * @title T/U area + * @description show textarea for copy title/url * @include http://* * @include https://* - * @license MIT License + * @contributor a-kuma3 http://let.hatelabo.jp/a-kuma3/let/hJme4N-s77x7 + * @license MIT License https://opensource.org/licenses/MIT * @javascript_url */ - (function () { + + (() => { + "use strict"; + + // XXX possibility of overwritten by Extension + // e.g. It's All Text! const c_id = "a-kuma3-" + Date.now(); - const remove_textarea = function() { - this.parentNode.parentNode.removeChild(this.parentNode); + + const remove_node = (node) => { + node.parentNode.removeChild(node); }; - function append_element(parent, tag, attr) { - return parent.appendChild(Object.assign(document.createElement(tag), attr)); - } + const append_element = (paren, tag, attr) => { + return paren.appendChild(Object.assign(document.createElement(tag), attr)); + }; - let c = append_element(document.body, "div", { - id: c_id + const container = append_element(document.body, "div", { + id: c_id, }); - let txt = append_element(c, "textarea", { - className: "txt", + // TBD readonly + const area = append_element(container, "textarea", { + className: "page-desc", value: document.title + "\n" + location.href, cols: 100, rows: 5, - onkeypress: function(ev) { - if (ev.keyCode == 27) { // ESC - remove_textarea.call(this); + onkeypress(evt) { + const ESC = 27; + if (evt.keyCode === ESC) { + remove_node(container); } }, }); - append_element(c, "div", { + append_element(container, "div", { className: "btn close", innerHTML: "&#x274c;", - onclick: remove_textarea, + onclick() { remove_node(container); }, }); - append_element(c, "div", { + append_element(container, "div", { className: "btn bookmark", - innerHTML: "<img src='http://localhost/images/firefox_favicon/hatebu.png'>", - onclick: function() { + innerHTML: "<img src='https://www.hatena.com/images/serviceicon-b-m.gif'>", + onclick() { location.href = "http://b.hatena.ne.jp/entry/" + location.href; }, }); - append_element(document.head, "style", { + // TODO icon alignment + append_element(document.head || document.body, "style", { innerHTML: ` #${c_id} { display: inline-block;
    @@ -98,9 +108,8 @@ `, }); - txt.focus(); - txt.select(); - + area.focus(); + area.select(); + //document.execCommand('copy'); })(); -
  • /*
     * @title T/U area
     * @description show textarea for copy title/url
     * @include http://*
     * @include https://*
     * @contributor a-kuma3 http://let.hatelabo.jp/a-kuma3/let/hJme4N-s77x7
     * @license MIT License https://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    (() => {
        "use strict";
    
        // XXX possibility of overwritten by Extension
        //     e.g. It's All Text!
        const c_id = "a-kuma3-" + Date.now();
    
        const remove_node = (node) => {
            node.parentNode.removeChild(node);
        };
    
        const append_element = (paren, tag, attr) => {
            return paren.appendChild(Object.assign(document.createElement(tag), attr));
        };
    
        const container = append_element(document.body, "div", {
            id: c_id,
        });
    
        // TBD readonly
        const area = append_element(container, "textarea", {
            className: "page-desc",
            value: document.title + "\n" + location.href,
            cols: 100,
            rows: 5,
            onkeypress(evt) {
                const ESC = 27;
                if (evt.keyCode === ESC) {
                    remove_node(container);
                }
            },
        });
    
        append_element(container, "div", {
            className: "btn close",
            innerHTML: "&#x274c;",
            onclick() { remove_node(container); },
        });
    
        append_element(container, "div", {
            className: "btn bookmark",
            innerHTML: "<img src='https://www.hatena.com/images/serviceicon-b-m.gif'>",
            onclick() {
                location.href = "http://b.hatena.ne.jp/entry/" + location.href;
            },
        });
    
        // TODO icon alignment
        append_element(document.head || document.body, "style", {
            innerHTML: `
            #${c_id} {
                display: inline-block;
                position: fixed;
                top: 0;
                left: 0;
                background-color: white;
                border: 1px inset gray;
                z-index: 10000;
            }
            #${c_id} textarea {
                height: 5em !important;
                vertical-align: top;
                font-family: monospace;
                font-size: 10pt;
                height: 5em;
                width: auto;
                margin: 0;
            }
            #${c_id} textarea::-moz-selection {
                background-color: #5dacf2;
                color: #444;
            }
            #${c_id} .btn {
                display: inline-block;
                position: absolute;
                right: 0;
                color: white;
                width: 1.5em;
                height: "1.5em";
                border: 2px silver solid;
                cursor: pointer;
                text-align: center;
                font-family: monospace;
                font-size: 10pt;
            }
            #${c_id} .close {
                background-color: darkred;
                vertical-align: top;
            }
            #${c_id} .bookmark {
                top: 1.5em;
                padding: 0;
            }
            #${c_id} .bookmark img {
                width: 1.5em;
                height: 1.5em;
            }
            `,
        });
    
        area.focus();
        area.select();
        //document.execCommand('copy');
    })();
    
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。