Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

FYI, if you implement this code for real, you'll need to make sure the symbol doesn't get repeated upon multiple plays and that it gets removed when not playing.

Edit: This is two different bugs. It means that if you are not playing, it will still look like it is playing and if you play multiple times, you will see the symbol get duplicated.

Edit 2: Code should be like this:

var documentTitle = document.title; function onPlayerStateChange(event) { var player = event.target; switch (event.data) { case YT.PlayerState.PLAYING: document.title = '▶' + documentTitle; break; default: document.title = documentTitle } }

but it assumes that the document title doesn't otherwise change.



In practice, the youtube api has other cases in that switch expression (ENDED, PAUSED, etc). For those, you would use the following in their case statement: document.title = document.title.replace("\u25B6","");

And to revise my original code, this is what you could use in the PLAYING statement to prevent multiple play symbols: document.title = "\u25B6" + document.title.replace("\u25B6","");

Notice, too, that I replaced the "▶" with the appropriate javascript encoding.


That's two ways of saying the same thing




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: