mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
30 lines
969 B
JavaScript
30 lines
969 B
JavaScript
const { ipcRenderer } = require("electron");
|
|
|
|
const { getImage } = require("./song-info");
|
|
|
|
global.songInfo = {};
|
|
|
|
ipcRenderer.on("update-song-info", async (_, extractedSongInfo) => {
|
|
global.songInfo = JSON.parse(extractedSongInfo);
|
|
global.songInfo.image = await getImage(global.songInfo.imageSrc);
|
|
});
|
|
|
|
module.exports = () => {
|
|
document.addEventListener('apiLoaded', e => {
|
|
setupTimeChangeListener();
|
|
|
|
document.querySelector('video').addEventListener('loadedmetadata', () => {
|
|
const data = e.detail.getPlayerResponse();
|
|
ipcRenderer.send("song-info-request", JSON.stringify(data));
|
|
});
|
|
}, { once: true, passive: true })
|
|
};
|
|
|
|
function setupTimeChangeListener() {
|
|
const progressObserver = new MutationObserver(mutations => {
|
|
ipcRenderer.send('timeChanged', mutations[0].target.value);
|
|
global.songInfo.elapsedSeconds = mutations[0].target.value;
|
|
});
|
|
progressObserver.observe(document.querySelector('#progress-bar'), { attributeFilter: ["value"] })
|
|
}
|