title: Build chrome extension to tweet
body: <p>I'm trying to build a simple chrome extension which consists of one icon that when clicked, pops up the official twitter window (as in <a href="https://dev.twitter.com/docs/intents" rel="nofollow">here</a>). The problem with most extensions that do this is that the window remains open after. If, however, you include <a href="http://platform.twitter.com/widgets.js" rel="nofollow">this script</a> provided by Twitter , they take care of closing the window after a few seconds, and that is what I want to do, so I'm trying to inject that code and then executing the URL. (Keep in mind both my javascript and chrome extensions knowledge is very limited).</p>
  
  <p>This is what I have so far.</p>
  
  <pre><code>function onClicked(tab) {
          var twitterWidgets = document.createElement("script");
          twitterWidgets.type = "text/javascript";
          twitterWidgets.src = "https://platform.twitter.com/widgets.js";
          var head = document.getElementsByTagName("head")[0];
          head.appendChild(twitterWidgets);
  
          var urlToTweet = "https://twitter.com/intent/tweet?"
      + "text=" + encodeURIComponent(tab.title)
      + "&amp;url=" + encodeURIComponent(tab.url);
  
          //window.open(urlToTweet);
  }
  
  chrome.browserAction.onClicked.addListener(onClicked);
  </code></pre>
  
  <p><i>window.open</i> is no good, as it opens a new tab. Neither is <i>window.location</i> and variants, that don't even seem to work at all. I realise I may have to add some <i>chrome.extension.getURL</i> to <i>twitterWidgets.src</i>, or something like it, but at this point, the more I mess with the script, the more confused I get.</p>
  
  <p>Any help in the right direction is greatly appreciated.</p>