Created
October 28, 2015 10:52
-
-
Save Nippey/dc6fa312c9c4a5103ff7 to your computer and use it in GitHub Desktop.
This gist showcases a way of how to get artist and title information from bop.fm to be used by browser extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lastObservation = ""; | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
var classes = mutation.target.className; | |
var observation = ""; | |
if ( classes.indexOf("song-playing") > -1 ) | |
{ | |
var artist = $(".song-info .artist")[0]; | |
artist = (artist && artist.textContent) ? artist.textContent.trim() : ""; | |
var title = $(".song-info .title")[0]; | |
title = (title && title.textContent) ? title.textContent.trim() : ""; | |
var duration = $(".queue .current-song .duration")[0]; | |
duration = (duration && duration.textContent) ? duration.textContent.trim() : ""; | |
var progress = $(".current-song-wrapper .bar b")[0]; | |
progress = (progress && progress.style) ? progress.style.width : ""; | |
observation = "PLAYING: " + artist + " - " + title + " - " + duration + " - " + progress; | |
} | |
else if ( classes.indexOf("song-started") > -1 ) | |
{ | |
observation = "PAUSED"; | |
} | |
else | |
{ | |
observation = "STOPPED"; | |
} | |
if (lastObservation != observation) | |
{ | |
/* HANDLE NEW SONG */ | |
console.log(observation); | |
lastObservation = observation; | |
} | |
}); | |
}); | |
/* The easiest hook was so look for changes in the big and green play/pause button. */ | |
/* The image of the button is controlled via a #page-playlist class name. */ | |
var config = { attributes: true, attributeFilter: ["class"] }; | |
var root = $("#page-playlist")[0]; | |
observer.observe(root, config); | |
/* observer.disconnect(); */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment