TAB imgs

    @@ -2,6 +2,7 @@ * @title TAB imgs * @description append tab navigation to image * @include http://* + * @exclude http://www.moae.jp/comic/* * @license MIT http://opensource.org/licenses/MIT * @javascript_url */
  • /*
     * @title TAB imgs
     * @description append tab navigation to image
     * @include http://*
     * @exclude http://www.moae.jp/comic/*
     * @license MIT http://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    // for background image
    // http://let.hatelabo.jp/noromanba/let/hLHW67STx8oc
    
    // e.g.
    // http://www.kurage-bunch.com/manga/youkai/01/
    
    (function () {
        // slice binding c.f.
        // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
        var slice = Function.prototype.call.bind(Array.prototype.slice);
    
        var handler = function (context) {
            // like a NodeFilter; c.f.
            // https://developer.mozilla.org/en-US/docs/Web/API/NodeFilter
            var filter = function(node, nodeName) {
                if (node.nodeName.toLowerCase() === nodeName.toLowerCase()) {
                    return [node];
                }
                if (!node.querySelectorAll) { // alt. document.ELEMENT_NODE
                    return [];
                }
                return slice(node.querySelectorAll(nodeName));
            };
    
            var each = function (imgs) {
                imgs.forEach(function (img) {
                    if (!img.src) return;
    
                    img.tabIndex = img.tabIndex > -1 ? img.tabIndex : 0;
                });
            };
    
            each(filter(context, 'img[src]'));
        };
        handler(document.body);
    
        // c.f. MutationObserver
        // https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
        // http://caniuse.com/#feat=mutationobserver
        new MutationObserver(function (records) {
            records.forEach(function (record) {
                handler(record.target);
            });
        }).observe(document.body, { childList: true, subtree: true });
    })();
    
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2015/07/07 04:44:27 - 2015-07-07
  2. 2015/05/20 07:41:48 - 2015-05-20
  3. 2015/05/19 04:53:10 - 2015-05-19
  4. 2015/05/19 04:32:27 - 2015-05-19
  5. 2015/05/19 04:20:38 - 2015-05-19
  6. 2015/05/19 04:18:21 - 2015-05-19
  7. 2015/05/19 04:04:20 - 2015-05-19
  8. 2015/05/19 03:22:56 - 2015-05-19
  9. 2015/05/19 03:03:56 - 2015-05-19
  10. 2014/11/19 03:25:56 - 2014-11-19
  11. 2014/11/19 03:14:12 - 2014-11-19