Last active
January 4, 2019 10:30
-
-
Save long-long-float/af6fef65671c8ada39cdb893b5a2cd70 to your computer and use it in GitHub Desktop.
Greasemonkey script that show title and artist of the music now playing at Amazon Music.
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
// ==UserScript== | |
// @name amazon-music-now-playing | |
// @namespace llf | |
// @include /^https://music\.amazon\.co\.jp/ | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
function charWidth(str) { | |
var w = 0; | |
for (var i = 0; i < str.length; i++) { | |
if (escape(str.charAt(i)).startsWith('%u')) { | |
w += 2; | |
} else { | |
w += 1; | |
} | |
} | |
return w; | |
} | |
var width = 20; | |
var count = 0; | |
var prevTitle = ''; | |
window.setInterval(function() { | |
var titleElem = document.querySelector('.trackTitle>a>span'); | |
if (titleElem !== null) { | |
var artistElem = document.querySelector('.trackArtist>a>span'); | |
var nowPlaying = document.querySelector('.playButton').classList.contains('playerIconPause'); | |
var title = titleElem.innerText + " [" + artistElem.innerText + "]"; | |
var slicedTitle = charWidth(title) >= width ? (title + " " + title).substr(count, width) : title; | |
document.title = (nowPlaying ? '▶ ' : '❚❚ ') + slicedTitle; | |
count++; | |
if (count > title.length) { | |
count = 0; | |
} | |
if (prevTitle !== title) { | |
count = 0; | |
document.querySelector('link[rel="icon"]').href = document.querySelector('.renderImage').dataset.src; | |
} | |
prevTitle = title; | |
} | |
}, 200); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment