javascript 动态构建Blogger缩略图URL

t9aqgxwy  于 12个月前  发布在  Java
关注(0)|答案(1)|浏览(111)

我正在使用我的Blogger模板,并尝试使用JavaScript动态构建Blogger缩略图URL。我正在为两个部分构建URL,一个是intro-thumbnailis,另一个是favourite-thumbnail。构建的URL是默认的72 px分辨率,如下所示:s72
Blockquote
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLrpKHWGB4bTA1dgb1Mrmb1hPG5g1kdlSW-Z79_m-dKsXjniohW61DKX2D5g0UJIKwqoWlJBYc3S1bmGrGsoEN-3LnYVyQUVRwPDzfFVN_TqnuDvmOlBFpCU3fTxo-nBnxHOQrnpcOlWJcW4wAiA-Uc_G1TR5Ka_dHdjtsOXinIXAg03vzBNp1T9kB_GNH/s72-w640-h640-c/Airport%20Transfers.jpg
我想实现的是这个URL与s1600
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLrpKHWGB4bTA1dgb1Mrmb1hPG5g1kdlSW-Z79_m-dKsXjniohW61DKX2D5g0UJIKwqoWlJBYc3S1bmGrGsoEN-3LnYVyQUVRwPDzfFVN_TqnuDvmOlBFpCU3fTxo-nBnxHOQrnpcOlWJcW4wAiA-Uc_G1TR5Ka_dHdjtsOXinIXAg03vzBNp1T9kB_GNH/s1600-w640-h640-c/Airport%20Transfers.jpg
我在网上找到了一些解决方案,比如this onethis。但这些对我没有帮助。
这是我的HTML和JavaScript代码。请帮我找到一个解决方案。

<b:if cond='data:blog.url == data:blog.homepageUrl'>
        <!-- Intro Slider -->
        <div id='intro-slider'>
          <div class='container'>
            <div class='row'>
              <b:section class='intro-posts' id='intro-posts' maxwidgets='1' showaddelement='no'>
                <b:widget id='HTML4' locked='true' title='Intro Posts Slider' type='HTML' version='1'>
                  <b:widget-settings>
                    <b:widget-setting name='content'>News</b:widget-setting>
                  </b:widget-settings>
                  <b:includable id='main'>
                    <div class='widget-content'>
                      <div class='outer-slider'>
                        <div class='swiper-container'>
                          <b:if cond='data:content == &quot;recent&quot;'>
                            <script>
                              document.write(&quot;&lt;script src=\&quot;/feeds/posts/default?max-results=10&amp;orderby=published&amp;alt=json-in-script&amp;callback=introPosts\&quot;&gt;&lt;\/script&gt;&quot;);
                            </script>
                            <b:else/>
                            <script>
                              document.write(&quot;&lt;script src=\&quot;/feeds/posts/summary/-/<data:content/>?max-results=10&amp;orderby=published&amp;alt=json-in-script&amp;callback=introPosts\&quot;&gt;&lt;\/script&gt;&quot;);
                            </script>
                          </b:if>
                        </div>
                        <div class='swiper-button-prev'>
                          <i class='fa fa-angle-left'/>
                        </div>
                        <div class='swiper-button-next'>
                          <i class='fa fa-angle-right'/>
                        </div>
                      </div>
                    </div>
                  </b:includable>
                </b:widget>
                <b:widget id='HTML937' locked='true' title='Slider Style' type='HTML' version='1'>
                  <b:widget-settings>
                    <b:widget-setting name='content'/>
                  </b:widget-settings>
                  <b:includable id='main'>
                    <b:if cond='data:content == &quot;wide slider&quot;'>
                    </b:if>
                  </b:includable>
                </b:widget>
              </b:section>
            </div>
          </div>
        </div>
        <div class='f-p' id='intro-favourite-posts'>
          <div class='container'>
            <div class='row'>
              <b:section class='intro-favourite-posts' id='intro-favourite-posts' maxwidgets='1' showaddelement='no'>
                <b:widget id='HTML550' locked='true' title='Popular Posts' type='HTML' version='1'>
                  <b:widget-settings>
                    <b:widget-setting name='content'>News</b:widget-setting>
                  </b:widget-settings>
                  <b:includable id='main'>
                    <div class='widget-content'>
                      <div class='swiper-container-2'>
                          <!-- only display title if it's non-empty -->
                          <b:if cond='data:title != &quot;&quot;'>
                            <div class='favourite-posts-title-home'>
                            <h2 class='title'>
                              <data:title/>
                            </h2>
                              <div class='slider-pagination'>
                              <div class='swiper-button-prev-2'>
                                <i class='fa fa-angle-left'/>
                              </div>
                              <div class='swiper-button-next-2'>
                                <i class='fa fa-angle-right'/>
                              </div>
                              </div>
                            </div>
                          </b:if>
                          <b:if cond='data:content == &quot;recent&quot;'>
                            <script>
                              document.write(&quot;&lt;script src=\&quot;/feeds/posts/default?max-results=10&amp;orderby=published&amp;alt=json-in-script&amp;callback=favouritePosts\&quot;&gt;&lt;\/script&gt;&quot;);
                            </script>
                            <b:else/>
                            <script>
                              document.write(&quot;&lt;script src=\&quot;/feeds/posts/summary/-/<data:content/>?max-results=10&amp;orderby=published&amp;alt=json-in-script&amp;callback=favouritePosts\&quot;&gt;&lt;\/script&gt;&quot;);
                            </script>
                          </b:if>
                      </div>
                    </div>
                  </b:includable>
                </b:widget>
              </b:section>
            </div>
          </div>
        </div>
      </b:if>


<script type='text/javascript'>
      //<![CDATA[   
function introPosts(_0xdd92x2) {
    var _0xdd92x3 = '<ul class="swiper-wrapper">';
    document.write(_0xdd92x3);
    for (var _0xdd92x4 = 0; _0xdd92x4 < _0xdd92x2.feed.entry.length; _0xdd92x4++) {
        for (var _0xdd92x5 = 0; _0xdd92x5 < _0xdd92x2.feed.entry[_0xdd92x4].link.length; _0xdd92x5++) {
            if (_0xdd92x2.feed.entry[_0xdd92x4].link[_0xdd92x5].rel == 'alternate') {
                var _0xdd92x6 = _0xdd92x2.feed.entry[_0xdd92x4].link[_0xdd92x5].href;
                break
            }
        };
        var _0xdd92x7 = _0xdd92x2.feed.entry[_0xdd92x4].title.$t;
        var _0xdd92x8 = 600;
        var _0xdd92x9 = ' ';
        var _0xdd92xa = ' ';
        _0xdd92xa = _0xdd92xa.replace('/s72-c/', '/s' + _0xdd92x8 + '/');
        var _0xdd92xb = ' ';
        var _0xdd92xc = _0xdd92x2.feed.entry[_0xdd92x4].author[0].name.$t;
        var _0xdd92xd = _0xdd92x2.feed.entry[_0xdd92x4].published.$t;
        var _0xdd92xe = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
        var _0xdd92xf = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
        var _0xdd92x10 = _0xdd92xd.split('-')[2].substring(0, 2);
        var _0xdd92x11 = _0xdd92xd.split('-')[1];
        var _0xdd92x12 = _0xdd92xd.split('-')[0];
        for (var _0xdd92x13 = 0; _0xdd92x13 < _0xdd92xe.length; _0xdd92x13++) {
            if (parseInt(_0xdd92x11) == _0xdd92xe[_0xdd92x13]) {
                _0xdd92x11 = _0xdd92xf[_0xdd92x13];
                break
            }
        };
        _0xdd92xd = _0xdd92x11 + ' ' + _0xdd92x10 + ', ' + _0xdd92x12;
        try {
            _0xdd92xa = _0xdd92x2.feed.entry[_0xdd92x4].media$thumbnail.url
        } catch (nl) {
            _0xdd92xa = 'http://4.bp.blogspot.com/-OI0BoYP677M/VZu1TW7a3DI/AAAAAAAAFsE/4BRdE2YFS5A/s1600/noimg.png'
        };
        try {
            _0xdd92xb = _0xdd92x2.feed.entry[_0xdd92x4].category[0].term
        } catch (n) {
            _0xdd92xb = 'uncategorized'
        };
        try {
            _0xdd92x9 = _0xdd92x2.feed.entry[_0xdd92x4].author[0].gd$image.src
        } catch (nl) {
            _0xdd92x9 = 'http://3.bp.blogspot.com/-fgwrcZWeRrU/V26tvNcGtsI/AAAAAAAAAG4/lGwGnQDZsNY7bAPr8hVorZruD-jHHxxOgCLcB/s50/anonyme.png'
        };
        var _0xdd92x14 = '<div class="swiper-slide"><div class="item-outer"><div class="intro-thumbnail"><a href="' + _0xdd92x6 + '" style="background:url(' + _0xdd92xa + ') no-repeat center center;background-size: cover"/></div><div class="intro-posts-overlay"><span class="cat"><a class="category" href="/search/label/' + _0xdd92xb + '?max-results=6">' + _0xdd92xb + '</a><h1 class="intro-posts-title"><a href="' + _0xdd92x6 + '">' + _0xdd92x7 + '</a></h1><ul class="intro-posts-meta"><li class="intro-author-img"><img src="' + _0xdd92x9 + '" /></li><li class="intro-posts-author">' + _0xdd92xc + '</li><li class="intro-posts-meta">' + _0xdd92xd + '</li></ul></div></div></div>';
        _0xdd92x3 += '</ul>';
        document.write(_0xdd92x14);
        $('.intro-thumbnail a').attr('style', function (_0xdd92x4, _0xdd92x15) {
            return _0xdd92x15.replace('/s72-c', '/s1600')
        });
        $('.intro-thumbnail a').attr('style', function (_0xdd92x4, _0xdd92x15) {
            return _0xdd92x15.replace('/default.jpg', '/hqdefault.jpg')
        })
    }
}

function favouritePosts(_0xdd92x2) {
    var _0xdd92x3 = '<ul class="swiper-wrapper favourite-posts">';
    document.write(_0xdd92x3);
    for (var _0xdd92x4 = 0; _0xdd92x4 < _0xdd92x2.feed.entry.length; _0xdd92x4++) {
        for (var _0xdd92x5 = 0; _0xdd92x5 < _0xdd92x2.feed.entry[_0xdd92x4].link.length; _0xdd92x5++) {
            if (_0xdd92x2.feed.entry[_0xdd92x4].link[_0xdd92x5].rel == 'alternate') {
                var _0xdd92x6 = _0xdd92x2.feed.entry[_0xdd92x4].link[_0xdd92x5].href;
                break
            }
        };
        var _0xdd92x17 = _0xdd92x2.feed.entry[_0xdd92x4].thr$total.$t;
        var _0xdd92x7 = _0xdd92x2.feed.entry[_0xdd92x4].title.$t;
        var _0xdd92x8 = 600;
        var _0xdd92xa = ' ';
        _0xdd92xa = _0xdd92xa.replace('/s72-c/', '/s' + _0xdd92x8 + '/');
        var _0xdd92xb = ' ';
        try {
            _0xdd92xa = _0xdd92x2.feed.entry[_0xdd92x4].media$thumbnail.url
        } catch (nl) {
            _0xdd92xa = 'http://4.bp.blogspot.com/-OI0BoYP677M/VZu1TW7a3DI/AAAAAAAAFsE/4BRdE2YFS5A/s1600/noimg.png'
        };
        try {
            _0xdd92xb = _0xdd92x2.feed.entry[_0xdd92x4].category[0].term
        } catch (n) {
            _0xdd92xb = 'uncategorized'
        };
        var pageTitle = document.title;
        var _0xdd92x14 = '<div class="swiper-slide favourite-post"><div class="item-outer"><div class="favourite-thumbnail"><a href="' + _0xdd92x6 + '"><img src="' + _0xdd92xa.replace('/s72-c/', '/s' + 400 + '/') + '" alt="' + pageTitle + '"/></a></div><a class="favourite-category" href="/search/label/' + _0xdd92xb + '?max-results=6">' + _0xdd92xb + '</a><div class="favourite-posts-overlay"><h1 class="favourite-posts-title"><a href="' + _0xdd92x6 + '">' + _0xdd92x7 + '</a></h1></div></div></div>';
        _0xdd92x3 += '</ul>';
        document.write(_0xdd92x14)
    }
}

function relatedPosts(_0xdd92x2) {
    var _0xdd92x3 = '<ul class="row">';
    document.write(_0xdd92x3);
    for (var _0xdd92x4 = 0; _0xdd92x4 < _0xdd92x2.feed.entry.length; _0xdd92x4++) {
        for (var _0xdd92x5 = 0; _0xdd92x5 < _0xdd92x2.feed.entry[_0xdd92x4].link.length; _0xdd92x5++) {
            if (_0xdd92x2.feed.entry[_0xdd92x4].link[_0xdd92x5].rel == 'alternate') {
                var _0xdd92x6 = _0xdd92x2.feed.entry[_0xdd92x4].link[_0xdd92x5].href;
                break
            }
        };
        var _0xdd92x7 = _0xdd92x2.feed.entry[_0xdd92x4].title.$t;
        var _0xdd92x8 = 600;
        var _0xdd92xa = ' ';
        var _0xdd92xb = ' ';
        _0xdd92xa = _0xdd92xa.replace('/s72-c/', '/s' + _0xdd92x8 + '/');
        try {
            _0xdd92xa = _0xdd92x2.feed.entry[_0xdd92x4].media$thumbnail.url
        } catch (nl) {
            _0xdd92xa = 'http://4.bp.blogspot.com/-OI0BoYP677M/VZu1TW7a3DI/AAAAAAAAFsE/4BRdE2YFS5A/s1600/noimg.png'
        };
        try {
            _0xdd92xb = _0xdd92x2.feed.entry[_0xdd92x4].category[0].term
        } catch (n) {
            _0xdd92xb = 'uncategorized'
        };
        var _0xdd92x14 = '<li class="related-post"><div class="item-outer"><div class="related-thumbnail"><a href="' + _0xdd92x6 + '"><img src="' + _0xdd92xa.replace('/s72-c/', '/s' + 400 + '/') + '"/></a></div><div class="related-posts-overlay"><a class="category" href="/search/label/' + _0xdd92xb + '?max-results=6">' + _0xdd92xb + '</a><h4 class="related-posts-title"><a href="' + _0xdd92x6 + '">' + _0xdd92x7 + '</a></h4></div></div></li>';
        _0xdd92x3 += '</ul>';
        document.write(_0xdd92x14)
    }
}
$(function () {
    var _0xdd92x19 = $('#header-wrapper').outerHeight();
    $(window).scroll(function () {
        if ($(window).scrollTop() > _0xdd92x19) {
            $('#menu-wrapper').addClass('fixed-menu').next()
        } else {
            $('#menu-wrapper').removeClass('fixed-menu').next()
        }
    })
});

//]]>
</script>

字符串

huwehgph

huwehgph1#

请提供可读的变量。这是非常难以阅读和理解。请尝试,虽然我不确定。

/*
Replace this line

   _0xdd92xa.replace('/s72-c/', '/s' + 400 + '/')

with

  _0xdd92xa.replace('/s72/', '/s1600/')
 
*/

字符串

相关问题