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

« 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.

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