mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 02:31:45 +00:00
Revert "Remove preload.js in plugin uses and use front plugin injection"
This reverts commit 4cb658daca.
This commit is contained in:
@ -13,6 +13,7 @@ module.exports = (win) => {
|
|||||||
// did-finish-load is called after all elements finished loading, including said listeners
|
// did-finish-load is called after all elements finished loading, including said listeners
|
||||||
// Thats the reason the timing is controlled from main
|
// Thats the reason the timing is controlled from main
|
||||||
win.webContents.once("did-finish-load", () => {
|
win.webContents.once("did-finish-load", () => {
|
||||||
|
win.webContents.send("restoreAddEventListener");
|
||||||
win.webContents.send("setupVideoPlayerVolumeMousewheel", !isEnabled("hide-video-player"));
|
win.webContents.send("setupVideoPlayerVolumeMousewheel", !isEnabled("hide-video-player"));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -5,7 +5,6 @@ const { setOptions } = require("../../config/plugins");
|
|||||||
function $(selector) { return document.querySelector(selector); }
|
function $(selector) { return document.querySelector(selector); }
|
||||||
|
|
||||||
module.exports = (options) => {
|
module.exports = (options) => {
|
||||||
overrideAddEventListener();
|
|
||||||
|
|
||||||
setupPlaybar(options);
|
setupPlaybar(options);
|
||||||
|
|
||||||
@ -23,35 +22,9 @@ module.exports = (options) => {
|
|||||||
ipcRenderer.once("setupVideoPlayerVolumeMousewheel", (_event, toEnable) => {
|
ipcRenderer.once("setupVideoPlayerVolumeMousewheel", (_event, toEnable) => {
|
||||||
if (toEnable)
|
if (toEnable)
|
||||||
setupVideoPlayerOnwheel(options);
|
setupVideoPlayerOnwheel(options);
|
||||||
// Restore original function after did-finish-load to avoid keeping Element.prototype altered
|
|
||||||
Element.prototype.addEventListener = Element.prototype._addEventListener;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Override specific listeners of volume-slider by modifying Element.prototype
|
|
||||||
function overrideAddEventListener() {
|
|
||||||
// Events to ignore
|
|
||||||
const nativeEvents = ["mousewheel", "keydown", "keyup"];
|
|
||||||
// Save native addEventListener
|
|
||||||
Element.prototype._addEventListener = Element.prototype.addEventListener;
|
|
||||||
// Override addEventListener to Ignore specific events in volume-slider
|
|
||||||
Element.prototype.addEventListener = function (
|
|
||||||
type,
|
|
||||||
listener,
|
|
||||||
useCapture = false
|
|
||||||
) {
|
|
||||||
if (this.tagName === "TP-YT-PAPER-SLIDER") {
|
|
||||||
// tagName of #volume-slider
|
|
||||||
for (const eventType of nativeEvents) {
|
|
||||||
if (eventType === type) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //else
|
|
||||||
this._addEventListener(type, listener, useCapture);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Add onwheel event to video player */
|
/** Add onwheel event to video player */
|
||||||
function setupVideoPlayerOnwheel(options) {
|
function setupVideoPlayerOnwheel(options) {
|
||||||
$("#main-panel").addEventListener("wheel", event => {
|
$("#main-panel").addEventListener("wheel", event => {
|
||||||
|
|||||||
28
plugins/precise-volume/preload.js
Normal file
28
plugins/precise-volume/preload.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
const { ipcRenderer } = require("electron");
|
||||||
|
|
||||||
|
// Override specific listeners of volume-slider by modifying Element.prototype
|
||||||
|
function overrideAddEventListener() {
|
||||||
|
// Events to ignore
|
||||||
|
const nativeEvents = ["mousewheel", "keydown", "keyup"];
|
||||||
|
// Save native addEventListener
|
||||||
|
Element.prototype._addEventListener = Element.prototype.addEventListener;
|
||||||
|
// Override addEventListener to Ignore specific events in volume-slider
|
||||||
|
Element.prototype.addEventListener = function (type, listener, useCapture = false) {
|
||||||
|
if (this.tagName === "TP-YT-PAPER-SLIDER") { // tagName of #volume-slider
|
||||||
|
for (const eventType of nativeEvents) {
|
||||||
|
if (eventType === type) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}//else
|
||||||
|
this._addEventListener(type, listener, useCapture);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = () => {
|
||||||
|
overrideAddEventListener();
|
||||||
|
// Restore original function after did-finish-load to avoid keeping Element.prototype altered
|
||||||
|
ipcRenderer.once("restoreAddEventListener", () => { //called from Main to make sure page is completly loaded
|
||||||
|
Element.prototype.addEventListener = Element.prototype._addEventListener;
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -9,6 +9,12 @@ const setupFrontLogger = require("./providers/front-logger");
|
|||||||
const plugins = config.plugins.getEnabled();
|
const plugins = config.plugins.getEnabled();
|
||||||
|
|
||||||
plugins.forEach(([plugin, options]) => {
|
plugins.forEach(([plugin, options]) => {
|
||||||
|
const preloadPath = path.join(__dirname, "plugins", plugin, "preload.js");
|
||||||
|
fileExists(preloadPath, () => {
|
||||||
|
const run = require(preloadPath);
|
||||||
|
run(options);
|
||||||
|
});
|
||||||
|
|
||||||
const actionPath = path.join(__dirname, "plugins", plugin, "actions.js");
|
const actionPath = path.join(__dirname, "plugins", plugin, "actions.js");
|
||||||
fileExists(actionPath, () => {
|
fileExists(actionPath, () => {
|
||||||
const actions = require(actionPath).actions || {};
|
const actions = require(actionPath).actions || {};
|
||||||
|
|||||||
Reference in New Issue
Block a user