Javascript

Post To Tumblr Version 0.3

Just made a quick little update to my chrome extension “Post To Tumblr”.

In this update I finally worked out how to catch bad username or password returns from the Tumbr API. Basically it just involved me using the ajax rather than the post jQuery function and using “async:false” like so:

$.ajax({
		  url: 'http://www.tumblr.com/api/write',
		  type: 'POST',
		  data:o,
		  async: false,
		  complete: function(transport)
		  {
				if(transport.status == 200 || transport.status == 201)
				{
					 postingNote.cancel();
					 var postedNote = webkitNotifications.createNotification('images/icon48.png', "Image Posted!", info.srcUrl);
					 setTimeout(function() { postedNote.cancel(); }, 5000);
					 postedNote.show();
				}
				else if(transport.status == 403)
				{
					postingNote.cancel();
					var errorNote = webkitNotifications.createNotification('images/icon48.png', "Posting Error!", "Bad email or password");
					setTimeout(function() { errorNote.cancel(); }, 5000);
					errorNote.show();
				}
 
			}
		 });

In addition I have added some notifications to indicate when the extension is doing something.

I have made a little demo video below to show this off:

Chrome should auto update for you. If you dont have the extension yet head over to the extension gallery to grab it now!

My First Chrome Extension – “Post To Tumblr”

Mummy wow! Im a big boy now! I have just published my first Chrome extension.

It was really annoying me that when I found a funny cat or some other silly image I would have to go through a whole ball-ache process to get that image on my Tumblr account.

What I really wanted was some right-click-post action going on and wondered why no one had one it yet. So with an hour or so to spare I whipped this extension up really quick.

It uses the Chrome 6 Context Menu API so you obviously need to have Chrome 6 to be able to use it.

Currently it only posts images as that’s all I needed for now but if enough people want more then ill whip out the other data types.

The source couldn’t be any simpler really, infact this is it here:

  1. chrome.contextMenus.create({"title": "Post Image To Tumblr", "contexts":["image"], "onclick": postImage});
  2.  
  3. function postImage(info, tab)
  4. {
  5. var email = localStorage["tumblr_email"];
  6. var password = localStorage["tumblr_pass"];
  7.  
  8. if(!email || email=="" || !password || password=="")
  9. {
  10. alert("Need to set your Tumblr username and password in the options before posting!");
  11. }
  12. else
  13. {
  14. var o =
  15. {
  16. "email":email,
  17. "password":password,
  18. "type":"photo",
  19. "source":info.srcUrl
  20. };
  21.  
  22. var success = function(data,textStatus,request)
  23. {
  24. if(textStatus=="success"){ alert("Image posted to Tumblr. Image -> "+info.srcUrl); }
  25. else { alert("Bad email or password"); }
  26. }
  27.  
  28. $.post("http://www.tumblr.com/api/write",o, success);
  29. }
  30. }

Simples!

Theres even an option page where you put in your Tumblr details:

Oh, there is one issue.

No matter what I tried I couldn’t manage to get the Tumblr API to return an error. So if you enter your username or password incorrectly it still reports success, not entirely sure why, if someone knows I would love to hear why!

Interested? You can go grab it over on the chrome extensions gallery page -> HERE

Funky Javascript Trick

img01

Ha! Tuhoojabotti just informed me of this neat little trick. If you are on Firefox stick the following into the address bar and hit enter.

javascript:document.body.contentEditable=true; document.designMode=on; void 0

Now see that you can move the images about and change the text on the page. No idea why you would want to, but its cool nonetheless.

Thinking about it, I guess this is how google docs works under the hood?

1 2 3 Scroll to top