Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Tim Morgan http://timmorgan.org

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Tumblr: Turn Twitter Posts into Quotes

Stick the following code in your Tumblr custom template to turn the posts from your Twitter feed into quotes.

YMMV. I use the Litewire theme and import my Twitter feed as Regular posts without titles.

I used to use this on timmorgan.org, but I don't any more. In fact, Tumblr has changed so much since I wrote this, I'm not sure it still works.

<script type="text/javascript">
    onload = function() {
      var divs = document.getElementsByTagName('div');
      for(var i=0; i<divs.length; i++) {
        if(divs[i].className == 'regular' && divs[i].innerHTML.match(/\(via.*Twitter\s\//)) {
          divs[i].className = 'quote';
          var q = divs[i].innerHTML;
          var t = q.replace(/^\s*.*?:/, '').replace(/\(via [^\)]+\)/, '');
          size = (t.length > 75) ? 'medium' : 'short';
          try {
            divs[i].innerHTML = '<div class="quote_text"><span class="' + size + '">' + t + '</span></div><div class="source">' + q.match(/\((via [^\)]+)\)/)[1] + '</div>';
          } catch(e) {}
        }
      }
    }
</script>
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS