mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 02:31:45 +00:00
Merge pull request #259 from Araxeus/force-pause
fix playPause bugs by directly playPause video element
This commit is contained in:
@ -5,6 +5,8 @@ const { remote } = require("electron");
|
|||||||
const config = require("./config");
|
const config = require("./config");
|
||||||
const { fileExists } = require("./plugins/utils");
|
const { fileExists } = require("./plugins/utils");
|
||||||
const setupFrontLogger = require("./providers/front-logger");
|
const setupFrontLogger = require("./providers/front-logger");
|
||||||
|
const setupSongControl = require("./providers/song-controls-front");
|
||||||
|
const setupSongInfo = require("./providers/song-info-front");
|
||||||
|
|
||||||
const plugins = config.plugins.getEnabled();
|
const plugins = config.plugins.getEnabled();
|
||||||
|
|
||||||
@ -37,8 +39,10 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// inject song-info provider
|
// inject song-info provider
|
||||||
const songInfoProviderPath = path.join(__dirname, "providers", "song-info-front.js")
|
setupSongInfo();
|
||||||
fileExists(songInfoProviderPath, require(songInfoProviderPath));
|
|
||||||
|
// inject song-control provider
|
||||||
|
setupSongControl();
|
||||||
|
|
||||||
// inject front logger
|
// inject front logger
|
||||||
setupFrontLogger();
|
setupFrontLogger();
|
||||||
|
|||||||
18
providers/song-controls-front.js
Normal file
18
providers/song-controls-front.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
const { ipcRenderer } = require("electron");
|
||||||
|
|
||||||
|
let videoStream = document.querySelector(".video-stream");
|
||||||
|
module.exports = () => {
|
||||||
|
ipcRenderer.on("playPause", () => {
|
||||||
|
if (!videoStream) {
|
||||||
|
videoStream = document.querySelector(".video-stream");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (videoStream.paused) {
|
||||||
|
videoStream.play();
|
||||||
|
} else {
|
||||||
|
videoStream.yns_pause ?
|
||||||
|
videoStream.yns_pause() :
|
||||||
|
videoStream.pause();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -12,7 +12,7 @@ module.exports = (win) => {
|
|||||||
// Playback
|
// Playback
|
||||||
previous: () => pressKey(win, "k"),
|
previous: () => pressKey(win, "k"),
|
||||||
next: () => pressKey(win, "j"),
|
next: () => pressKey(win, "j"),
|
||||||
playPause: () => pressKey(win, "space"),
|
playPause: () => win.webContents.send("playPause"),
|
||||||
like: () => pressKey(win, "_"),
|
like: () => pressKey(win, "_"),
|
||||||
dislike: () => pressKey(win, "+"),
|
dislike: () => pressKey(win, "+"),
|
||||||
go10sBack: () => pressKey(win, "h"),
|
go10sBack: () => pressKey(win, "h"),
|
||||||
|
|||||||
@ -10,17 +10,16 @@ ipcRenderer.on("update-song-info", async (_, extractedSongInfo) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const injectListener = () => {
|
const injectListener = () => {
|
||||||
var oldXHR = window.XMLHttpRequest;
|
const oldXHR = window.XMLHttpRequest;
|
||||||
function newXHR() {
|
function newXHR() {
|
||||||
var realXHR = new oldXHR();
|
const realXHR = new oldXHR();
|
||||||
realXHR.addEventListener(
|
realXHR.addEventListener(
|
||||||
"readystatechange",
|
"readystatechange",
|
||||||
() => {
|
() => {
|
||||||
if (realXHR.readyState == 4 && realXHR.status == 200) {
|
if (realXHR.readyState === 4 && realXHR.status === 200
|
||||||
if (realXHR.responseURL.includes("/player")) {
|
&& realXHR.responseURL.includes("/player")) {
|
||||||
// if the request contains the song info, send the response to ipcMain
|
// if the request contains the song info, send the response to ipcMain
|
||||||
ipcRenderer.send("song-info-request", realXHR.responseText);
|
ipcRenderer.send("song-info-request", realXHR.responseText);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
|
|||||||
Reference in New Issue
Block a user