+#link Fork

    @@ -1,30 +1,75 @@ /* - * @title Show IDs in the page - * @description Show IDs of the elements in the current page. - * @license CC0 + * @title +#link + * @description append Fragment Identifier links + * @include http://* + * @include https://* + * @contributor wakabatan http://let.hatelabo.jp/wakabatan/let/hJmcxuC90NBX + * @license CC0 https://creativecommons.org/publicdomain/zero/1.0/ + * @javascript_url */ + // keeping styles and strict ver + // http://let.hatelabo.jp/noromanba/let/hLHXwv6M9ohw - var els = document.querySelectorAll ('[id], a[name]'); - for (var i = 0; i < els.length; i++) { - var el = els[i]; - var id = el.id || el.name; - var anchor = document.createElement ('a'); - anchor.href = '#' + encodeURIComponent (id); - anchor.className = '___id_anchor'; - anchor.textContent = '#' + id; - if (el.namespaceURI == "http://www.w3.org/1999/xhtml") { - anchor.title = el.localName; - if (el.localName.match (/^(?:h[1-6]|td|th|li|dt|dd|html)$/)) { - el.insertBefore (anchor, el.firstChild); - continue; - } - } else { - anchor.title = '{' + el.namespaceURI + '}' + el.localName; + // e.g. + // https://www.sunday-webry.com/events/free/ + (() => { + 'use strict'; + + { + const wall = document.head || document.body || document.documentElement; + + wall.append(Object.assign(document.createElement('style'), { + charset: 'utf-8', + // TODO fix glitching e.g. in MDN + // TBD omit class-name + textContent: [ + '.___id_anchor {' + + 'display: inline', + 'width: auto', + 'height: auto', + 'margin: 0', + 'border: none', + 'padding: 0', + 'background-color: #ffa', + 'color: black', + 'font-size: 16px', + 'font-weight: normal', + 'font-family: monospace', + 'line-height: 1.0', + 'text-decoration: underline', + '}', + ].join('!important;'), + })); } - el.parentNode.insertBefore (anchor, el); - } - var style = document.createElement ('style'); + document.body.querySelectorAll([ - style.textContent = '.___id_anchor { display: inline !important; width: auto !important; height: auto !important; margin: 0 !important; border: none !important; padding: 0 !important; background-color: #ffa !important; color: black !important; font-size: 16px !important; font-weight: normal !important; font-family: monospace !important; line-height: 1.0 !important; text-decoration: underline !important }'; + '[id]', - document.head.appendChild (style); + 'a[name]', + ]).forEach(node => { + // legacy fallback + const id = node.id || node.name; + const anchor = Object.assign(document.createElement('a'), { + href: '#' + encodeURIComponent(id), + // TBD omit class-name + className: '___id_anchor', + textContent: '#' + id, + }); + + // TODO un-nest + // https://www.w3.org/1999/xhtml/ + if (node.namespaceURI === 'http://www.w3.org/1999/xhtml') { + const name = node.nodeName.toLowerCase(); + anchor.title = name; + + if (name.match(/^(?:h[1-6]|td|th|li|dt|dd|html)$/)) { + node.firstChild.before(anchor); + return; + } + } else { + anchor.title = '{' + node.namespaceURI + '}' + name; + } + node.before(anchor); + }); + })(); +
  • /*
     * @title +#link
     * @description append Fragment Identifier links
     * @include http://*
     * @include https://*
     * @contributor wakabatan http://let.hatelabo.jp/wakabatan/let/hJmcxuC90NBX
     * @license     CC0       https://creativecommons.org/publicdomain/zero/1.0/
     * @javascript_url
     */
    
    // keeping styles and strict ver
    // http://let.hatelabo.jp/noromanba/let/hLHXwv6M9ohw
    
    // e.g.
    // https://www.sunday-webry.com/events/free/
    (() => {
      'use strict';
    
      {
        const wall = document.head || document.body || document.documentElement;
    
        wall.append(Object.assign(document.createElement('style'), {
          charset: 'utf-8',
          // TODO fix glitching e.g. in MDN
          // TBD omit class-name
          textContent: [
            '.___id_anchor {' +
            'display: inline',
            'width: auto',
            'height: auto',
            'margin: 0',
            'border: none',
            'padding: 0',
            'background-color: #ffa',
            'color: black',
            'font-size: 16px',
            'font-weight: normal',
            'font-family: monospace',
            'line-height: 1.0',
            'text-decoration: underline',
            '}',
          ].join('!important;'),
        }));
      }
    
      document.body.querySelectorAll([
        '[id]',
        'a[name]',
      ]).forEach(node => {
        // legacy fallback
        const id = node.id || node.name;
        const anchor = Object.assign(document.createElement('a'), {
          href: '#' + encodeURIComponent(id),
          // TBD omit class-name
          className: '___id_anchor',
          textContent: '#' + id,
        });
    
        // TODO un-nest
        // https://www.w3.org/1999/xhtml/
        if (node.namespaceURI === 'http://www.w3.org/1999/xhtml') {
          const name = node.nodeName.toLowerCase();
          anchor.title = name;
    
          if (name.match(/^(?:h[1-6]|td|th|li|dt|dd|html)$/)) {
            node.firstChild.before(anchor);
            return;
          }
        } else {
          anchor.title = '{' + node.namespaceURI + '}' + name;
        }
        node.before(anchor);
      });
    })();
    
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。