mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 02:31:45 +00:00
32 lines
861 B
JavaScript
32 lines
861 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);
|
|
});
|
|
|
|
const injectListener = () => {
|
|
const oldXHR = window.XMLHttpRequest;
|
|
function newXHR() {
|
|
const realXHR = new oldXHR();
|
|
realXHR.addEventListener(
|
|
"readystatechange",
|
|
() => {
|
|
if (realXHR.readyState === 4 && realXHR.status === 200
|
|
&& realXHR.responseURL.includes("/player")) {
|
|
// if the request contains the song info, send the response to ipcMain
|
|
ipcRenderer.send("song-info-request", realXHR.responseText);
|
|
}
|
|
},
|
|
false
|
|
);
|
|
return realXHR;
|
|
}
|
|
window.XMLHttpRequest = newXHR;
|
|
};
|
|
module.exports = injectListener;
|