id属性がある要素の後ろにアンカーリンクをつける

    @@ -22,6 +22,13 @@ ().textContent = '¶' ); + document.querySelectorAll('[name]').forEach( e => + pipe( document.createElement('a') ) + ( e.appendChild.bind(e) ) + ( $attr( 'href' )( "#" + e.name ) ) + ().textContent = '¶' + ); + void 0; }
  • /*
     * @title id属性がある要素の後ろにアンカーリンクをつける
     * @description ページ途中へのフラグメント付きURL(#xxx)が欲しい時に
     * @include http://*
     * @license MIT License
     * @javascript_url
     * @require 
     */
    
    {
      const pipe = x => f => f ? pipe(f(x)) : x;  // via https://qiita.com/nagtkk/items/5c54ec418c1c71fa491a
      const $attr = attr => val => e =>{
        if ( val == null) return e.getAttribute(attr);
        e.setAttribute(attr, val);
        return e;
      };
      
      document.querySelectorAll('[id]').forEach( e => 
        pipe( document.createElement('a') )
          ( e.appendChild.bind(e) )
          ( $attr( 'href' )( "#" + e.id ) )
          ().textContent = '¶'
      );
      
      document.querySelectorAll('[name]').forEach( e => 
        pipe( document.createElement('a') )
          ( e.appendChild.bind(e) )
          ( $attr( 'href' )( "#" + e.name ) )
          ().textContent = '¶'
      );
    
      void 0;
    }
    
    
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2020/10/13 16:29:12 - 2020-10-13
  2. 2020/02/13 13:58:30 - 2020-02-13
  3. 2020/02/13 13:56:28 - 2020-02-13
  4. 2020/02/12 12:24:33 - 2020-02-12