mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-15 04:11:47 +00:00
lint
This commit is contained in:
@ -4,30 +4,33 @@ const { getImage } = require("./song-info");
|
|||||||
|
|
||||||
global.songInfo = {};
|
global.songInfo = {};
|
||||||
|
|
||||||
|
let api = document.querySelector('#movie_player');
|
||||||
|
|
||||||
ipcRenderer.on("update-song-info", async (_, extractedSongInfo) => {
|
ipcRenderer.on("update-song-info", async (_, extractedSongInfo) => {
|
||||||
global.songInfo = JSON.parse(extractedSongInfo);
|
global.songInfo = JSON.parse(extractedSongInfo);
|
||||||
global.songInfo.image = await getImage(global.songInfo.imageSrc);
|
global.songInfo.image = await getImage(global.songInfo.imageSrc);
|
||||||
});
|
});
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
if (document.querySelector('#movie_player')) {
|
if (api) {
|
||||||
injectListener();
|
injectListener();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const observer = new MutationObserver(() => {
|
const observer = new MutationObserver(() => {
|
||||||
if (document.querySelector('#movie_player')) {
|
api = document.querySelector('#movie_player');
|
||||||
observer.disconnect();
|
if (api) {
|
||||||
injectListener();
|
observer.disconnect();
|
||||||
}
|
injectListener();
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
|
||||||
observer.observe(document.documentElement, { childList: true, subtree: true });
|
observer.observe(document.documentElement, { childList: true, subtree: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
function injectListener() {
|
function injectListener() {
|
||||||
document.querySelector('video').addEventListener('loadedmetadata', () => {
|
document.querySelector('video').addEventListener('loadedmetadata', () => {
|
||||||
const data = document.querySelector('#movie_player').getPlayerResponse();
|
const data = api.getPlayerResponse();
|
||||||
ipcRenderer.send("song-info-request", JSON.stringify(data));
|
ipcRenderer.send("song-info-request", JSON.stringify(data));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user