Bookmarklets

Bookmarklets are great. I first discovered them through this little experiment called slitscanner.js, and then forgot about them until Louis asked for something to help him work out what the date will be thirty days in the future.

Bookmarklets are great. I first discovered them through this little experiment called slitscanner.js, and then forgot about them until Louis asked for something to help him work out what the date will be thirty days in the future.

The JavaScript is easy enough:

var date = new Date(); new Date(date.setDate(date.getDate() + 30));  

Drop that in the console and we get the date. But opening up the console every time you want to work out what the date's going to be in thirty days' time is a pain. What to do?

javascript:(function() { var date = new Date(); var thirtyDays = new Date(date.setDate(date.getDate() + 30)); alert(thirtyDays); }());  

Wrap it up and bookmark it.

Nat extended it with a prompt, which I thought was very clever.

javascript:(function() { var date = new Date(); var thirtyDays = new Date(date.setDate(date.getDate() + Number(prompt('How many days?')))); alert(thirtyDays); }());  

Here's another one. Take a guess at where it's meant to be used:

javascript:(function() { window.location = document.getElementsByClassName('main-photo')[0].getAttribute('src').replace(/\/\//, 'http://'); })();  

READ MORE >