T/U box Fork

    @@ -11,6 +11,8 @@ /* modifications + * Show confirm dialog for doubtful URL + (location.pushState/replace will cause mismatch between meta URLs and current URL) * Fix copy format * Add Title+URL format * Append location.hash
    @@ -25,12 +27,15 @@ // 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.origin + location.pathname + (document.querySelector('head link[rel="canonical"][href]') || {}).href ) + location.hash; const title = document.title; - const hatenalink = `[${canonical}:title=]`; - const mdlink = `[${title}](${canonical})`; + + const url = + (!canonical && location.href) || + (new URL(canonical).pathname === location.pathname && canonical) || + (confirm(`次のURLがmetaタグから見つかりましたが、現在のpathと異なります。\nキャンセルを押すとlocation.hrefを使用します。\n${canonical}`) && canonical) || + location.href; const box = document.body.appendChild(Object.assign(document.createElement('div'), { id: 'copy-buttons',
    @@ -53,14 +58,14 @@ box.addEventListener('click', e => e.stopPropagation()); box.addEventListener('dblclick', onClose); document.addEventListener('click', onClose); - + // TBD alignment [ - { label: 'CanonicalURL', value: canonical }, + { label: 'URL', value: url }, { label: 'Title', value: title }, - { label: 'Title + URL', value: title + ' ' + canonical }, - { label: 'HatenaSyntax', value: `[${canonical}:title=${title}]` }, - { label: 'Markdown', value: `[${title}](${canonical})` }, + { label: 'Title + URL', value: title + ' ' + url }, + { label: 'HatenaSyntax', value: `[${url}:title=${title}]` }, + { label: 'Markdown', value: `[${title}](${url})` }, ].forEach(({label, value}) => { box.appendChild(Object.assign(document.createElement('label'), { style: `
    @@ -84,4 +89,3 @@ }); }); })(); -
  • /*
     * @title T/U box
     * @description w/ "{title} {url}" format. easy copyable title/url box; click to copy, double-click outer to close
     * @include http://*
     * @include https://*
     * @contributor	pacochi	http://let.hatelabo.jp/pacochi/let/hJme3OvVzN41
     * @contributor noromanba http://let.hatelabo.jp/noromanba/let/hJme3Pyylqos
     * @license MIT License	https://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    /* modifications
    
    * Show confirm dialog for doubtful URL
     (location.pushState/replace will cause mismatch between meta URLs and current URL)
    * Fix copy format
    * Add Title+URL format
    * Append location.hash
    * Avoid to use array for querySelector (for cloudflare rocket.js)
    * Close on click anywhere
    
    */
    
    (() => {
      'use strict';
    
      // 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.hash;
      const title = document.title;
      
      const url =
            (!canonical && location.href) ||
            (new URL(canonical).pathname === location.pathname && canonical) ||
            (confirm(`次のURLがmetaタグから見つかりましたが、現在のpathと異なります。\nキャンセルを押すとlocation.hrefを使用します。\n${canonical}`) && canonical) ||
            location.href;
    
      const box = 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: ${Number.MAX_SAFE_INTEGER || Number.MAX_VALUE};
    `,
      }));
      const onClose = e => {
        box.parentNode.removeChild(box);
        document.removeEventListener('click', onClose);
        e.stopPropagation();
      };
      
      box.addEventListener('click', e => e.stopPropagation());
      box.addEventListener('dblclick', onClose);
      document.addEventListener('click', onClose);
      
      // TBD alignment
      [
        { label: 'URL', value: url },
        { label: 'Title', value: title },
        { label: 'Title + URL', value: title + ' ' + url },
        { label: 'HatenaSyntax', value: `[${url}:title=${title}]` },
        { label: 'Markdown', value: `[${title}](${url})` },
      ].forEach(({label, value}) => {
        box.appendChild(Object.assign(document.createElement('label'), {
          style: `
    display: block;
    color: black;
    background-color: silver;
    text-align: left;
    `,
          textContent: `${label}: `,
        })).appendChild(Object.assign(document.createElement('input'), {
          style: `
    color: black;
    background-color: silver;
    margin: 0.5em;
    `,
          value,
        })).addEventListener('click', e => {
          e.target.select();
          document.execCommand('copy');
          e.stopPropagation();
        });
      });
    })();
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2018/12/25 05:59:51 - 2018-12-25
  2. 2018/08/09 07:09:12 - 2018-08-09
  3. 2018/07/19 07:26:12 - 2018-07-19
  4. 2018/06/03 14:15:58 - 2018-06-03
  5. 2018/03/18 17:34:37 - 2018-03-18
  6. 2018/02/27 01:06:21 - 2018-02-27
  7. 2018/02/27 01:04:04 - 2018-02-27
  8. 2018/02/18 12:29:38 - 2018-02-18
  9. 2018/01/21 16:10:08 - 2018-01-21
  10. 2018/01/21 15:49:28 - 2018-01-21
  11. 2018/01/21 15:34:27 - 2018-01-21
  12. 2018/01/06 11:03:54 - 2018-01-06
  13. 2017/07/08 19:14:17 - 2017-07-08
  14. 2017/07/01 16:00:23 - 2017-07-01
  15. 2017/07/01 12:48:51 - 2017-07-01
  16. 2017/06/29 12:09:02 - 2017-06-29
  17. 2017/06/28 10:18:42 - 2017-06-28
  18. 2017/06/28 09:37:56 - 2017-06-28
  19. 2017/06/27 01:23:22 - 2017-06-27
  20. 2017/06/27 01:20:43 - 2017-06-27
  21. 2017/06/27 01:18:32 - 2017-06-27
  22. 2017/06/25 22:56:10 - 2017-06-25
  23. 2017/06/25 04:30:31 - 2017-06-25
  24. 2017/06/25 04:29:40 - 2017-06-25
  25. 2017/06/25 04:26:52 - 2017-06-25