Skip to content

Instantly share code, notes, and snippets.

@shortstuffsushi
Created April 25, 2017 23:52
Show Gist options
  • Save shortstuffsushi/c9e67fcfdb08794685db4e22736788a6 to your computer and use it in GitHub Desktop.
Save shortstuffsushi/c9e67fcfdb08794685db4e22736788a6 to your computer and use it in GitHub Desktop.
Skip Google Music
// This script will monitor the Google Music page and skip songs you've already downvoted.
// Google doesn't do this automatically for some weird reason, so this hacks around that.
// Note that you're limited to somewhere around five skips per hour per station, so you
// can pretty quickly run into a scenario where this won't work. In the case that you want
// to stop the script, just run clearInterval(skipper) after this script.
var skipper = setInterval(function() {
// Grab the rating container (first of two with the same class)
var ratingContainer = document.getElementsByClassName('rating-container')[0];
// The down thumb is the middle element
var downThumbButton = ratingContainer.children[1];
// Get the "title" attribute from the button
var titleAttr = downThumbButton.attributes.title.textContent;
// Check if the title is prefixed with "Undo" in the case that you've already thumbed
var isDownThumbed = titleAttr.startsWith('Undo');
// If it is thumbed down, "click" the next / skip button
if (isDownThumbed) {
document.getElementById('player-bar-forward').click();
}
}, 5000);
@jonathanmcdougall
Copy link

jonathanmcdougall commented May 21, 2018

Works well. I added a check for title because it would log errors to the console when no song is currently playing and I reduced the interval to 500 ms to make sure it skips as soon as possible.

I've also added another timer which hides the songs from the queue. It's purely cosmetic. It will still show blank entries in the list because changing display to none instead seems to break everything.

let gmusicSkipper = setInterval(function()
{
    let container = document.getElementsByClassName('rating-container')[0];
    let button = container.children[1];

    if (button)
    {
        let title = button.attributes.title;

        if (title && title.textContent.startsWith('Undo'))
            document.getElementById('player-bar-forward').click();
    }
}, 500);


let gmusicHider = setInterval(function()
{
    let table = document.getElementsByClassName("song-table mini")[0];
    if (!table || !table.rows)
        return;

    for (let r of table.rows)
    {
        if (!r)
            continue;

        for (let c of r.cells)
        {
            if (c.dataset.col == "rating")
            {
                if (c.dataset.rating == "1")
                {
                    r.style.setProperty("visibility", "hidden");
                    break;
                }
            }
        }
    }
}, 1000);

Amusingly, data-rating is 5 for thumb-up and 1 for thumb-down, showing that it's really a simplified UI for a 5-star rating instead of a "don't play that song".

@Paprikas
Copy link

@glichtenstein
Use greasemonkey for firefox https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/
or tampermonkey for chrome.

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