mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 03:41:46 +00:00
39 lines
912 B
JavaScript
39 lines
912 B
JavaScript
const { ipcRenderer } = require("electron");
|
|
|
|
const { getImage } = require("./song-info");
|
|
|
|
global.songInfo = {};
|
|
|
|
let api = document.querySelector('#movie_player');
|
|
|
|
ipcRenderer.on("update-song-info", async (_, extractedSongInfo) => {
|
|
global.songInfo = JSON.parse(extractedSongInfo);
|
|
global.songInfo.image = await getImage(global.songInfo.imageSrc);
|
|
});
|
|
|
|
function setup() {
|
|
if (api) {
|
|
injectListener();
|
|
return;
|
|
}
|
|
|
|
const observer = new MutationObserver(() => {
|
|
api = document.querySelector('#movie_player');
|
|
if (api) {
|
|
observer.disconnect();
|
|
injectListener();
|
|
}
|
|
})
|
|
|
|
observer.observe(document.documentElement, { childList: true, subtree: true });
|
|
}
|
|
|
|
function injectListener() {
|
|
document.querySelector('video').addEventListener('loadedmetadata', () => {
|
|
const data = api.getPlayerResponse();
|
|
ipcRenderer.send("song-info-request", JSON.stringify(data));
|
|
});
|
|
};
|
|
|
|
module.exports = setup;
|