Anyone can be a B!KUMA Girl

    @@ -1,38 +1,58 @@ /* * @title Anyone can be a B!KUMA Girl - * @description B!KUMAize everyone's icon - * @include http://b.hatena.ne.jp/* - * @license MIT License + * @description B!KUMAize everyone's icon on Hatena or Other + * @include http://* + * @contributor yuta25 http://let.hatelabo.jp/yuta25/let/hJmetPek3eZM (Fork of) + * @license MIT License http://opensource.org/licenses/MIT + * @javascript_url */ +// TBD observe document.images, no needed filtering. so simple (function() { - var BKUMA = 'http://f.st-hatena.com/images/fotolife/h/hatenapr/20111228/20111228162520.png'; + var BKUMA = 'http://f.st-hatena.com/images/fotolife/h/hatenapr/20111228/20111228162520.png', + forEach = Array.prototype.forEach; + var bkumaize = function(node) { - function changeIcon(img) { - if (img.src.match(/^http:\/\/cdn1\.www\.st\-hatena\.com\/users\/.*\.gif$/)) { + if (node.nodeType === document.TEXT_NODE) return; + + var changeIcon = function(img) { + // Hatena CDN c.f. http://let.hatelabo.jp/noromanba/let/gYC-yeGlqrueQQ + var hatenaAvatar = /^http:\/\/(?:cdn(?:(?:-ak)?(?:\d+)?)?\.)?(?:www\.)?st\-hatena\.com\/users\/.*\.gif$/; + if (hatenaAvatar.test(img.src)) { img.src = BKUMA; } + }; + + // TODO into a observer or changeIcon + // like a NodeFilter; c.f. + // https://developer.mozilla.org/en-US/docs/Web/API/NodeFilter + if (node.nodeName === "IMG") { + changeIcon(node); + return; } - node = node || document; - if (typeof (node.querySelectorAll) !== "undefined") { - if (node.nodeName === "IMG") { - changeIcon(node); - } else { - Array.prototype.forEach.call(node.querySelectorAll('img'), function(img) { - changeIcon(img); - }); - } - } + + forEach.call(node.querySelectorAll('img'), function(img) { + changeIcon(img); + }); }; - bkumaize(); + + bkumaize(document.body); + // c.f. MutationObserver // https://developer.mozilla.org/en/docs/Web/API/MutationObserver - var observer = new MutationObserver(function(mutations) { + // BUG Webkit*; iOS Safari 6.0-6.1 doesn't trigger childList + // http://caniuse.com/#feat=mutationobserver + var MutationObserver = window.MutationObserver || window.WebkitMutationObserver; + new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { - for (var i = 0; i < mutation.addedNodes.length; i++) { - bkumaize(mutation.addedNodes[i]); - } + // TBD addedNodes or mutation.target + /*/ + forEach.call(mutation.addedNodes, function(node) { + bkumaize(node); + }); + /*/ + bkumaize(mutation.target); + //*/ }); - }); - observer.observe(document, {childList: true, subtree: true}); + }).observe(document.body, {childList: true, subtree: true}); })();
  • /*
     * @title Anyone can be a B!KUMA Girl
     * @description B!KUMAize everyone's icon on Hatena or Other
     * @include http://*
     * @contributor yuta25  http://let.hatelabo.jp/yuta25/let/hJmetPek3eZM (Fork of)
     * @license MIT License http://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    // TBD observe document.images, no needed filtering. so simple
    (function() {
      var BKUMA = 'http://f.st-hatena.com/images/fotolife/h/hatenapr/20111228/20111228162520.png',
          forEach = Array.prototype.forEach;
    
      var bkumaize = function(node) {
        if (node.nodeType === document.TEXT_NODE) return;
    
        var changeIcon = function(img) {
          // Hatena CDN c.f. http://let.hatelabo.jp/noromanba/let/gYC-yeGlqrueQQ
          var hatenaAvatar = /^http:\/\/(?:cdn(?:(?:-ak)?(?:\d+)?)?\.)?(?:www\.)?st\-hatena\.com\/users\/.*\.gif$/;
          if (hatenaAvatar.test(img.src)) {
            img.src = BKUMA;
          }
        };
    
        // TODO into a observer or changeIcon
        // like a NodeFilter; c.f.
        // https://developer.mozilla.org/en-US/docs/Web/API/NodeFilter
        if (node.nodeName === "IMG") {
          changeIcon(node);
          return;
        }
    
        forEach.call(node.querySelectorAll('img'), function(img) {
          changeIcon(img);
        });
      };
    
      bkumaize(document.body);
    
      // c.f. MutationObserver
      // https://developer.mozilla.org/en/docs/Web/API/MutationObserver
      // BUG Webkit*; iOS Safari 6.0-6.1 doesn't trigger childList
      //     http://caniuse.com/#feat=mutationobserver
      var MutationObserver = window.MutationObserver || window.WebkitMutationObserver;
      new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
          // TBD addedNodes or mutation.target
          /*/
          forEach.call(mutation.addedNodes, function(node) {
            bkumaize(node);
          });
          /*/
          bkumaize(mutation.target);
          //*/
        });
      }).observe(document.body, {childList: true, subtree: true});
    })();
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2014/11/18 04:50:35 - 2014-11-18
  2. 2014/11/15 05:49:30 - 2014-11-15
  3. 2014/11/15 05:16:58 - 2014-11-15
  4. 2014/11/15 04:18:02 - 2014-11-15
  5. 2014/11/15 02:45:48 - 2014-11-15
  6. 2014/11/14 03:47:59 - 2014-11-14
  7. 2014/11/14 03:42:55 - 2014-11-14