☆button on anond

    @@ -92,7 +92,7 @@ }; var addStarButton = function () { - if (document.readyState !== 'interactive' || 'complete') return; + if (document.readyState !== 'interactive' || document.readyState !== 'complete') return; clearInterval(timer); var s = document.createElement('script'); s.src = 'http://s.hatena.ne.jp/js/HatenaStar.js';
  • /*
     * @title ☆button on anond
     * @description はてな匿名ダイアリーに☆ボタン出します (for userscript)
     * @include http://anond.hatelabo.jp*
     * @contributor yuta25
     * @contributor noromanba http://let.hatelabo.jp/noromanba/let/hLHVyMu855wo
     * @license MIT License http://opensource.org/licenses/MIT
     */
    
    // c.f.
    // http://jsbeautifier.org/
    // http://www.jshint.com/
    // https://developer.mozilla.org/ja/docs/DOM/element.classList
    // http://archive.today/86e6T (404, but works well)
    
    (function() {
      var Hatena = window.Hatena;
    
      function main() {
        var ICONIZING = false;
    
        var setupStar = function() {
          var style = document.createElement('style');
          style.textContent = '.hatena-star-add-button-image { background: url("http://hatenablog.com/images/theme/star/hatena-star-add-button.png"); }';
          document.body.appendChild(style);
    
          if (!Hatena.Star) return;
    
          var entryConfig = {
            entryNodes: {
              // PC, article
              'div.star-target': {
                uri: 'h3:first-child a:first-child',
                title: 'h3:first-child',
                container: 'h3:first-child'
              }
            }
          };
          Hatena.Star.SiteConfig = entryConfig;
        };
    
        var setupSection = function() {
          var sections = document.querySelectorAll('.section');
          Array.prototype.slice.call(sections).forEach(function(section) {
            section.classList.add('star-target'); // fallback; node.className += ' class';
          });
        };
    
        var iconize = function() {
          ICONIZING = true;
          var sections = document.querySelectorAll('div.section');
          Array.prototype.slice.call(sections).forEach(function(section) {
            if (section.querySelectorAll('.hatena-star-star-container').length == 0) return;
            var starlinks = section.querySelectorAll('.hatena-star-star-container a:not([iconized])');
            Array.prototype.slice.call(starlinks).forEach(function(link) {
              link.setAttribute('iconized','');
              link.style.width = '20px';
              link.style.height = '20px';
              link.style.position = 'relative';
              link.style.display = 'inline-block';
              link.style.margin = '0 1px 0 1px';
    
              var user = link.pathname.replace('/', '');
              var icon = document.createElement('img');
              icon.src = 'http://cdn1.www.st-hatena.com/users/' + user.slice(0, 2) + '/' + user + 'profile.gif';
              icon.style.height = '20px';
              icon.style.position = 'absolute';
              icon.style.width = '20px';
    
              var star = link.querySelector('.hatena-star-star');
              star.style.position = 'absolute';
              star.style.bottom = '1px';
              star.style.width = '10px';
              link.insertBefore(icon, star);
            });
            section.classList.remove('star-target'); // or .toggle()
          });
          ICONIZING = false;
        };
    
        var startPolling = function() {
          var timer = 0;
          document.addEventListener('DOMNodeInserted', function() {
            if (timer) return;
            timer = setTimeout(function() {
              setupSection();
              iconize();
              if (!ICONIZING) Hatena.Star.EntryLoader();
              timer = 0;
            }, 500);
          }, false);
        };
    
        var addStarButton = function () {
          if (document.readyState !== 'interactive' || document.readyState !== 'complete') return;
          clearInterval(timer);
          var s = document.createElement('script');
          s.src = 'http://s.hatena.ne.jp/js/HatenaStar.js';
          s.type = 'text/javascript';
          s.addEventListener('load', function() {
            setupStar();
            setupSection();
            startPolling();
          }, false);
          document.body.appendChild(s);
        };
    
        var timer = setInterval(addStarButton, 500);
      } // /main
    
      // executeBrowserContext
      var script = document.createElement('script');
      script.textContent = '(' + main.toString() + '());';
      document.body.appendChild(script);
    }());
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2014/12/23 16:09:12 - 2014-12-23
  2. 2014/08/28 17:26:25 - 2014-08-28
  3. 2014/08/28 17:23:36 - 2014-08-28
  4. 2014/08/28 17:22:59 - 2014-08-28
  5. 2014/08/28 17:21:36 - 2014-08-28
  6. 2014/08/28 13:10:27 - 2014-08-28
  7. 2014/05/29 11:39:52 - 2014-05-29
  8. 2014/05/29 03:11:17 - 2014-05-29