“Unnesting” Nested Blockquotes Using jQuery (to fit tumblr's September 2015 update)

谁说我不能喝 提交于 2019-12-02 01:34:32

There doesn't seem to be an official way to do it. However it is possible to achieve the effect using JS. The following script will flatten the nested blockquotes and also remove the ":" after the blog names and instead prepend them with "- ". Just put it in a new script tag under the body tag.

$(function() {
    // flatten reblogs
    $("div.cont blockquote").each(function() {
        $(this).parent().prepend($(this).children());
        $(this).remove();
    });

    // remove : and add -
    $("div.cont a.tumblr_blog").each(function() {
        var authorPTag = $(this).parent();
        authorPTag.html($(this));
        authorPTag.prepend("- ");
    });
});

It looks like this on the default theme:

Note however that this may break the next time Tumblr updates the way reblogs are rendered. It will also not work with endless scrolling.

@relgukxilef's answer almost worked for me.

I had to insert jQuery into the theme and then wait for jQuery to be initialised. Tumblr has also updated it's tagging.

Here is the solution I went with:

<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>

<script type="text/javascript">
  $(document).ready(function () {
    // flatten reblogs
    $("div.post-content blockquote").each(function() {
      $(this).parent().prepend($(this).children());
      $(this).remove();
    });

    // remove : and add -
    $("div.post-content a.tumblr_blog").each(function() {
      var authorPTag = $(this).parent();
      authorPTag.html($(this));
      authorPTag.prepend("- ");
    });
  });
</script>

I added this to the bottom of the theme and everything worked perfectly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!