image post fitness

    @@ -5,24 +5,21 @@ * @license reblog commons license ( cc by 3.0 ) */ -// http://itakura26.hateblo.jp/entry/2014/06/04/%E8%A1%A8%E7%A4%BA%E9%A0%98%E5%9F%9F%E3%81%AB%E5%90%88%E3%82%8F%E3%81%9B%E3%81%A6%E7%94%BB%E5%83%8F%E3%81%AE%E3%83%AA%E3%82%B5%E3%82%A4%E3%82%BA%E3%82%92%E3%81%99%E3%82%8B (function () { var w = window var d = document var spreadImage = function(img) { + if (!img) + img = this if (!img.width) { img = img.data; } if (!img.complete) { - img.onload = spreadImage(img); + img.onload = spreadImage; return; } var iW = img.naturalWidth; - if (iW === 0) { - img.load(img,spreadImage); - return; - } var iH = img.naturalHeight; var vW = img.parentNode.parentNode.clientWidth; var vH = w.innerHeight - 120;
  • /*
     * @title image post fitness
     * @description 画像のpostをdsbdとwindowに合わせる(for user script & please use with http://userstyles.org/styles/102353/dashboard-1-column)
     * @include https://www.tumblr.com/dashboard*
     * @license reblog commons license ( cc by 3.0 )
     */
    
    
    (function () {
      var w = window
      var d = document
      var spreadImage = function(img) {
        if (!img)
          img = this
        if (!img.width) {
          img = img.data;
        }
        if (!img.complete) {
          img.onload = spreadImage;
          return;
        }
        var iW = img.naturalWidth;
        var iH = img.naturalHeight;
        var vW = img.parentNode.parentNode.clientWidth;
        var vH = w.innerHeight - 120;
        var vR = vW / vH;
        var rate;
        var adjust = {};
        iR = iW / iH;
        rate = vR > iR ? vH / iH : vW / iW;
        adjust.width = Math.round(iW * rate);
        adjust.height = Math.round(iH * rate);
        img.style.width = adjust.width + 'px'
        img.style.height = adjust.height + 'px'
      };
    
      var spreadImagesIntoDashboard = function(dom) {
        var imgs = dom.querySelectorAll('img.post_media_photo');
        Array.prototype.forEach.call(imgs, function(img) {
          spreadImage(img)
        });
      };
    
      spreadImagesIntoDashboard(d);
    
      window.myTimer = 0;
      d.addEventListener('DOMNodeInserted', function() {
        if(window.timer) return;
        window.myTimer = setTimeout(function() {
          spreadImagesIntoDashboard(document);
          window.myTimer = 0;
        }, 200);
      });
      w.addEventListener('resize', function() {
        if(window.myTimer) return;
        window.myTimer = setTimeout(function() {
          spreadImagesIntoDashboard(document);
          window.myTimer = 0;
        }, 200);
      });
    }())
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2016/03/09 10:05:04 - 2016-03-09
  2. 2016/03/08 12:27:48 - 2016-03-08
  3. 2014/10/20 23:59:20 - 2014-10-20
  4. 2014/10/16 10:33:38 - 2014-10-16
  5. 2014/09/03 10:39:55 - 2014-09-03
  6. 2014/07/17 12:42:46 - 2014-07-17
  7. 2014/07/03 16:23:27 - 2014-07-03
  8. 2014/07/03 13:31:39 - 2014-07-03
  9. 2014/07/03 13:19:21 - 2014-07-03
  10. 2014/07/02 14:46:27 - 2014-07-02
  11. 2014/06/10 17:56:45 - 2014-06-10
  12. 2014/06/10 17:56:29 - 2014-06-10