タイトルとかのコピー

  • /*
     * @title タイトルとかのコピー
     * @description 出てきたやつをクリックするとクリップボードに入ります。外枠をダブルクリックすると消えます。
     * @include *
     * @license MIT License
     * @javascript_url
     */
    
    // タイトルコピーするために入れたアドオンが次々使えなくなっていくからこれでしのぐっていう用途
    
    (() => {
    
    	// 元のコード: https://gist.github.com/noromanba/d730ccf3ae5e6916cd60
    	const canonical = (document.querySelector('head meta[property="og:url"][content]') || {}).content ||
    	 (document.querySelector('head link[rel="canonical"][href]') || {}).href ||
    	 location.href;
    	const title = document.title;
    	const hatenalink = `[${canonical}:title=${title}]`;
    	const base = document.body.appendChild(Object.assign(document.createElement('div'), {
    			id: 'copy-buttons',
    			style: 'background-color: white; border: 1px solid silver;padding: 1em; position: fixed; top: 0; left: 0; z-index: 2147483646;'
    	}));
    	base.addEventListener('dblclick', e => {
    
    		document.body.removeChild(e.target);
    		e.stopPropagation();
    
    	}, false);
    	
    	[{ label: 'CanonicalURL', value: canonical },
    	 { label: 'タイトル', value: title },
    	 { label: 'はてな記法', value: hatenalink }].forEach(({label, value}) => {
    
    		base.appendChild(Object.assign(document.createElement('label'), {
    		 style: 'display: block; color: black; background-color: silver;',
    		 textContent: `${label}: `
    		})).appendChild(Object.assign(document.createElement('input'), {
    		 style: 'color: black; background-color: silver; margin: 0.5em;',
    		 value: value
    		})).addEventListener('click', e => {
    
    			e.target.select();
    			document.execCommand('copy');
    			e.stopPropagation();
    
    		}, false);
    
    	});
    
    })();
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2017/03/19 22:56:03 - 2017-03-19
  2. 2017/03/19 22:25:23 - 2017-03-19
  3. 2017/03/19 22:21:19 - 2017-03-19