Skip to content

Instantly share code, notes, and snippets.

@jayeb
Created October 1, 2014 18:24
Show Gist options
  • Save jayeb/c63b5f15bbd224e52b25 to your computer and use it in GitHub Desktop.
Save jayeb/c63b5f15bbd224e52b25 to your computer and use it in GitHub Desktop.
Google Play Music: Jump to random album
(function() {
var w = window,
getRandomAlbum = function() {
var albums, r, rAlbum;
if (w.location.hash == '#/albums') {
albums = document.querySelectorAll('div[data-type="album"]');
r = Math.random();
rAlbum = albums[Math.floor(r * albums.length)];
w.removeEventListener('hashchange', getRandomAlbum, false);
w.location.hash = '/album/' + rAlbum.dataset.id;
}
};
if (window.location.hash == '#/albums') {
getRandomAlbum();
} else {
w.addEventListener('hashchange', getRandomAlbum, false);
w.location.hash = '/albums';
}
})();
@jayeb
Copy link
Author

jayeb commented Oct 1, 2014

When run on a Google Play Music tab, this script will take you to a random album page. It works great at a bookmarklet!

Just run the above code through a minifier (http://closure-compiler.appspot.com/home is a good place to start), then add a new bookmark prepended with javascript:, like so:

javascript:(function(){var a=window,c=function(){var b,d;"#/albums"==a.location.hash&&(b=document.querySelectorAll('div[data-type="album"]'),d=Math.random(),b=b[Math.floor(d*b.length)],a.removeEventListener("hashchange",c,!1),a.location.hash="/album/"+b.dataset.id)};"#/albums"==window.location.hash?c():(a.addEventListener("hashchange",c,!1),a.location.hash="/albums")})();

@jayeb
Copy link
Author

jayeb commented May 27, 2015

Sadly, this doesn't work anymore :(

@arnfred
Copy link

arnfred commented Dec 31, 2015

Did you ever find a way to make it work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment