Archive for November, 2013

svtplaylist.se

November 11, 2013

I would really like to see support for playlists in SVT Play, but that has not been high enough on the priority list at SVT yet. So in the meantime I’ve built a small hack to provide a simple playlist using a bookmarklet. You can try it out on www.svtplaylist.se

The idea was born when a colleague of mine showed a really smart way to create bookmarklets by dynamically loading a script hosted on github. The only code you need to put in the bookmarklet looks something like this:

(function() {
  var e = document.createElement("script");
  e.async = 1;
  e.src = "https://gist.github.com/{user}/{hash}/raw";
  document.getElementsByTagName("body")[0].appendChild(e)
})()

This code just creates a <script> tag that loads a javascript file hosted on github. You can then put any stuff you want in that script. To make it a real bookmarklet you also need to pack it into one line, url-encode it and put a javascript: prefix in front, like this:

javascript:(function()%7Bvar%20e%3Ddocument.createElement(%22script%22)%3Be.async%3D1%3Be.src%3D%22https%3A%2F%2Fgist.github.com%2F%7Buser%7D%2F%7Bhash%7D%2Fraw%22%3Bdocument.getElementsByTagName(%22body%22)%5B0%5D.appendChild(e)%7D)()

What is really nice about this approach is that you can change the functionality of the bookmarklet after it has been saved as a bookmark.