Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for another player (play) available on emumo.xiami.com. Fix play/pause detection of main player. Closes #1817. Closes #1975.
- Loading branch information
1 parent
e75f9a3
commit ae17889
Showing
2 changed files
with
71 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,78 @@ | ||
'use strict'; | ||
|
||
Connector.playerSelector = '.play-bar'; | ||
const mainPlayerSelector = '.play-bar'; | ||
const playPlayerSelector = '#player-main'; | ||
|
||
Connector.trackSelector = '.music .info .title'; | ||
const PLAYER_MAIN = 0x1; | ||
const PLAYER_PLAY = 0x2; | ||
const PLAYER_UNKNOWN = 0x3; | ||
|
||
Connector.artistSelector = '.music .info .singers'; | ||
initConnectorProps(); | ||
|
||
Connector.trackArtSelector = '.music .cover-link .active img'; | ||
function initConnectorProps() { | ||
switch (getPlayerType()) { | ||
case PLAYER_MAIN: | ||
Util.debugLog('Init connector for main player'); | ||
initPropsForMainPlayer(); | ||
break; | ||
case PLAYER_PLAY: | ||
Util.debugLog('Init connector for play player'); | ||
initPropsForPlayPlayer(); | ||
break; | ||
default: | ||
Util.debugLog('Unknown player', 'warn'); | ||
break; | ||
} | ||
} | ||
|
||
Connector.getUniqueID = () => $('.play-bar .content .title').attr('href').split('?')[0].split('/song/')[1]; | ||
function getPlayerType() { | ||
if ($(mainPlayerSelector).length > 0) { | ||
return PLAYER_MAIN; | ||
} | ||
|
||
Connector.timeInfoSelector = '.audio-progress .range .bar .handle'; | ||
if ($(playPlayerSelector).length > 0) { | ||
return PLAYER_PLAY; | ||
} | ||
|
||
Connector.isPlaying = () => { | ||
return $('.main-control .play-btn').length !== 0; | ||
}; | ||
return PLAYER_UNKNOWN; | ||
} | ||
|
||
function initPropsForMainPlayer() { | ||
const PAUSE_SYMBOL = '\ue619'; | ||
|
||
Connector.playerSelector = mainPlayerSelector; | ||
|
||
Connector.trackSelector = '.music .info .title'; | ||
|
||
Connector.artistSelector = '.music .info .singers'; | ||
|
||
Connector.trackArtSelector = '.music .cover-link .active img'; | ||
|
||
Connector.getUniqueID = () => $('.play-bar .content .title').attr('href').split('?')[0].split('/song/')[1]; | ||
|
||
Connector.timeInfoSelector = '.audio-progress .range .bar .handle'; | ||
|
||
Connector.isPlaying = () => { | ||
return $('.main-control .play-btn').text() === PAUSE_SYMBOL; | ||
}; | ||
} | ||
|
||
function initPropsForPlayPlayer() { | ||
Connector.playerSelector = playPlayerSelector; | ||
|
||
Connector.getArtist = () => { | ||
const artists = $('#J_trackInfo a').toArray().slice(1); | ||
return Util.joinArtists(artists); | ||
}; | ||
|
||
Connector.trackSelector = '#J_trackName'; | ||
|
||
Connector.playButtonSelector = '.play-btn'; | ||
|
||
Connector.currentTimeSelector = '#J_positionTime'; | ||
|
||
Connector.durationSelector = '#J_durationTime'; | ||
|
||
Connector.trackArtSelector = '#J_playerCoverImg'; | ||
|
||
} |
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