What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 122 Stack Exchange communities.

Tweet Tweet...

As the title suggests, let's see you javascript-guru's break out the grease and integrate twitter. This is absolutely necessary because the community has a sharp division over what SO is, and is not. Some say twitter should be avoided because SO isn't a social-networking site, and yet many of us find twitter to be a part of our normal every-day life.

Start your engines. And integrate "Tweet This"!

Hello World: http://twitter.com/home?status=hello+world

share|improve this question
1  
Is this truly required in light of the completed request meta.stackexchange.com/questions/4773/tweet-this-button ? –  Scott Wilson Apr 7 '12 at 20:48
add comment

1 Answer

up vote 11 down vote accepted
+75

Preview of SOtweet

..and it works


// ==UserScript==
// @name           SOtweet
// @namespace      org.neverfear.sotweet
// @include        http://stackoverflow.com/*
// @include        http://serverfault.com/*
// @include        http://meta.stackoverflow.com/*
// ==/UserScript==

// Set CSS style
var style = window.document.createElement('style');
style.type = 'text/css';
style.innerHTML = '#tweeeet{display:none;position:absolute;left:30%;top:40%;width:350px;height:100px;padding:10px;background:#9AE4E8;-moz-border-radius:10px}#tweetmsg{display:none;} #tweetsubmit{display:none}';
document.getElementsByTagName("head")[0].appendChild(style);

(function(){
  function GM_wait() {
    if(typeof unsafeWindow.jQuery == 'undefined') { 
      window.setTimeout(GM_wait,100); 
    } else { 
      $ = unsafeWindow.jQuery; letsJQuery(); 
    }
  }
  GM_wait();

  function letsJQuery() {
    function getTinyURL(longURL, success) {
        var API = 'http://json-tinyurl.appspot.com/?url=';
        var URL = API + encodeURIComponent(longURL) + '&callback=?';

        $.getJSON(URL, function(data){
            success && success(data.tinyurl);
        });
    }

    // The tweet'ify div, shown by the tweet link
    $('body').prepend('<div id="tweeeet"><form id="tweetform"><div id="tweetloading"><img src="http://stackoverflow.com/content/img/ajax-loader.gif" width="24" height="24"><span id="loadingmsg"></span></div><p><img src="http://img189.imageshack.us/img189/6721/twitterlogotransparent.png" width="27" height="26"><textarea rows="3" cols="40" id="tweetmsg"></textarea></p><p><input type="button" value="Close!" id="tweetclose">&nbsp;<input type="submit" value="Twitter\'ify it!" id="tweetsubmit"></p></form></div>');

    $('.post-menu').append('<span class="link-separator">|</span><a href="#" id="tweetifylink">tweet</a>');

    $('#tweetifylink').bind('click', function(){
      $('#tweeeet').show();

      // Show loading thingy, hide form until tinyurl is grabbed
      $('#tweetmsg').hide();
      $('#submit').hide();
      $('#loadingmsg').append('Getting TinyURLified address');
      $('#loading').show();

      $('#tweetclose').bind('click', function(){
        $('#tweeeet').hide();
      })

      getTinyURL(document.location, function(tinyurl){
        // TinyURLification complete, enter into tweetmsg input, submit
        $('#tweetmsg').val(tinyurl + ' "' + document.title +'"');
        $('#tweetmsg').show();
        $('#tweetloading').hide();
        $('#tweetsubmit').show();

        $('#tweetform').submit(function(){
          var submiturl = 'http://twitter.com/home?status=' + encodeURIComponent($('#tweetmsg').val());
          window.location.href = submiturl;
        })
      });

    })
  }
})();

Todo:

  • Make tweet buttons on each answer submit the link to the answer's permalink, not the question
  • Tidy up CSS styles from a single-line string
  • Tidy up HTMl additions from a single string
  • Truncate title if too long
  • Use #stackoverflow/#serverfault/#metaso hashtag, and remove - Stack Overflow/etc from message?
  • Move imageshack-hosted Twitter logo into data: URI?
  • Only add styles on-click, rather than at the scripts top level?
  • Dim page background when popup is added
  • Look for http://is.gd JSONP service, instead of tinyurl (shorter URL)?
  • Add support for SuperUser
share|improve this answer
    
is there an install script for this? if not how do you manually install a greasemonkey script –  Omar Kooheji Jul 13 '09 at 15:58
2  
Firefox > Tools > Greasemonkey > New User Script –  Jonathan Sampson Jul 13 '09 at 16:00
    
I can see this build out the twitter URL, but nothing seems to happen after that... –  RSolberg Jul 13 '09 at 17:14
1  
I hope this script puts the integrate a "Twitter Link" requests to bed. –  ahsteele Jul 13 '09 at 17:24
1  
@ahsteel: that request is just getting started... GreaseMonkey scripts don't work on all platforms... –  RSolberg Jul 14 '09 at 7:07
    
@RSolberg which platforms? You mean outside the Firefox ecosystem? Assuming you mean only those that aren't using Firefox if it is that important to them they can use Firefox and Greasemokey for SO. –  ahsteele Jul 15 '09 at 17:15
1  
dbr: You forgot Superuser! Also, how about bit.ly instead of is.gd? Sure the URLs will be a bit longer, but I like their support for metrics. –  Chris Charabaruk Jul 19 '09 at 16:00
    
Another thing: It doesn't seem to work for tweeting answers, just questions. –  Chris Charabaruk Jul 19 '09 at 16:05
add comment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .