Created
April 14, 2019 12:42
-
-
Save Fyzu/c09c0607a812118c3398dac11047e828 to your computer and use it in GitHub Desktop.
Google Play Music Desktop Player OBS Widget
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>Google Music Player</title> | |
<meta name="author" content="https://github.com/Fyzu" /> | |
<link | |
href="https://fonts.googleapis.com/css?family=Open+Sans" | |
rel="stylesheet" | |
/> | |
<style type="text/css"> | |
html { | |
min-height: 100%; | |
} | |
body { | |
display: block; | |
margin: 0; | |
padding: 0; | |
min-height: 100vh; | |
font-family: 'Open Sans', sans-serif; | |
font-size: 18px; | |
line-height: 1.3; | |
} | |
#root { | |
position: absolute; | |
left: 0; | |
top: 0; | |
right: 0; | |
bottom: 0; | |
padding: 20px; | |
display: flex; | |
flex-direction: column; | |
justify-content: flex-end; | |
} | |
.primary-line { | |
color: white; | |
font-weight: 800; | |
white-space: nowrap; | |
overflow: hidden; | |
text-overflow: ellipsis; | |
} | |
.second-line { | |
color: #ccc; | |
font-weight: 600; | |
white-space: nowrap; | |
overflow: hidden; | |
text-overflow: ellipsis; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="root"> | |
<div class="primary-line"><span id="title"></span></div> | |
<div class="second-line"><span id="artist"></span></div> | |
</div> | |
<script type="text/javascript"> | |
const rootEl = document.getElementById('root') | |
const titleEl = document.getElementById('title') | |
const artistEl = document.getElementById('artist') | |
async function update() { | |
try { | |
const { playing, song } = await fetch( | |
`./json_store/playback.json?hash=${Date.now()}` | |
).then(response => response.json()) | |
if (playing && song) { | |
const { title, artist } = song | |
rootEl.style.visibility = 'visible' | |
titleEl.innerHTML = title | |
artistEl.innerHTML = artist | |
} else { | |
rootEl.style.visibility = 'hidden' | |
} | |
} catch (e) { | |
rootEl.style.visibility = 'hidden' | |
} | |
} | |
window.setInterval(update, 1000) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment