Last active
August 29, 2015 14:14
-
-
Save drugoi/7731d10503d8f1b9ba0d to your computer and use it in GitHub Desktop.
Set title for Yandex.Music tab
This file contains hidden or 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 loadScript = function() { | |
window._player = false; | |
var updateTitle = function(songTitle, songArtists) { | |
document.title = songTitle + ' — ' + songArtists; | |
} | |
for (var i in Mu.blocks.binding) { | |
if (Mu.blocks.binding[i].type == 'volume') { | |
window._player = Mu.blocks.binding[i].block.player; | |
break; | |
} | |
} | |
var songInfo = window._player.getTrackData(); | |
var allSongArtists = function(artistsList) { | |
var artists = []; | |
for (artist in artistsList) { | |
artists.push(artistsList[artist].name); | |
} | |
return artists.join(', '); | |
} | |
if (songInfo) { | |
updateTitle(songInfo.metadata.title, allSongArtists(songInfo.metadata.artists)); | |
} | |
window._player.on('trackdata', function(event) { | |
var currentSongInfo = event.currentTrackData; | |
updateTitle(currentSongInfo.metadata.title, allSongArtists(currentSongInfo.metadata.artists)); | |
}); | |
}; | |
var injectScript = function(script) { | |
var actualCode = 'try {(' + script + ')(); } catch(e) {console.log("injected error", e);};'; | |
var script = document.createElement('script'); | |
script.textContent = actualCode; | |
(document.head || document.documentElement).appendChild(script); | |
script.parentNode.removeChild(script); | |
} | |
injectScript(loadScript); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment