H#id link

    
      
  • /*
     * @title leanpub outline
     * @description append TOC links by fragment identifires on leanpub
     * @include  https://leanpub.com/*
     * @contributor efcl    http://let.hatelabo.jp/efcl/let/hJmfwszo56oZ (Fork of)
     * @license MIT License http://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    // - fix syntax error (illegal block-comment)
    // - work in Firefox and others (Array.from)
    
    // e.g.
    // https://leanpub.com/oopinjavascript/read
    (function () {
    
    if (!/leanpub\.com$/.test(location.hostname) ||
        !/read/.test(location.pathname.split('/').pop())) {
        return;
    }
    
    var headers = document.querySelectorAll("h1[id], h2[id], h3[id], h4[id], h5[id]");
    [].slice.call(headers).forEach(function(header) {
        var headerID = header.getAttribute("id");
        if (!headerID) { return; }
    
        var linkName = document.createElement("a");
        linkName.href = "#" + headerID;
        wrap(header, linkName);
    });
    
    function wrap(el, wrapper) {
        el.parentNode.insertBefore(wrapper, el);
        wrapper.appendChild(el);
    }
    
    })();
    
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2015/06/22 05:49:15 - 2015-06-22
  2. 2015/06/22 05:48:58 - 2015-06-22