Skip to content
This repository has been archived by the owner on May 3, 2019. It is now read-only.

Commit

Permalink
Add favorites support (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmMlhch authored and ColinDuquesnoy committed Apr 10, 2018
1 parent d9a83e0 commit b564c3a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/plugins/web/googleplaymusic/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function getButtons() {
playpause: document.getElementById("player-bar-play-pause"),
skip: document.getElementById("player-bar-forward"),
back: document.getElementById("player-bar-rewind"),
thumbUp: document.querySelector('#player .player-rating-container [icon^="sj:thumb-"][data-rating="5"]'),
seekBar: document.getElementById('progressContainer')
};
}
Expand Down Expand Up @@ -132,12 +133,25 @@ function update() {

var canSeek = getButtons().seekBar != null && duration != 0;

// Adapted from gmusic.js
// please see https://github.com/gmusic-utils/gmusic.js/blob/master/src/namespaces/RatingNamespace.js
// and https://github.com/gmusic-utils/gmusic.js/blob/master/src/constants/selectors.js

elm = getButtons().thumbUp;
var canAddToFavorites = elm != null && playbackStatus != mellowplayer.PlaybackStatus.STOPPED;
var isFavorite = false;
try {
isFavorite = elm.__data__.icon === 'thumb-up';
} catch (e) {
canAddToFavorites = false;
}

return {
"playbackStatus": playbackStatus,
"canSeek": canSeek,
"canGoNext": true,
"canGoPrevious": true,
"canAddToFavorites": false,
"canAddToFavorites": canAddToFavorites,
"volume": 1,
"duration": duration,
"position": position,
Expand All @@ -146,7 +160,7 @@ function update() {
"artistName": artistName,
"albumTitle": albumTitle,
"artUrl": artUrl,
"isFavorite": false
"isFavorite": isFavorite
}
}

Expand Down Expand Up @@ -183,13 +197,13 @@ function setVolume(volume) {

function addToFavorites() {

// not currently supported
getButtons().thumbUp.click();

}

function removeFromFavorites() {

// not currently supported
getButtons().thumbUp.click();

}

Expand Down

0 comments on commit b564c3a

Please sign in to comment.