mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 02:31:45 +00:00
Remove preload.js in plugin uses and use front plugin injection
This commit is contained in:
@ -13,7 +13,6 @@ module.exports = (win) => {
|
||||
// did-finish-load is called after all elements finished loading, including said listeners
|
||||
// Thats the reason the timing is controlled from main
|
||||
win.webContents.once("did-finish-load", () => {
|
||||
win.webContents.send("restoreAddEventListener");
|
||||
win.webContents.send("setupVideoPlayerVolumeMousewheel", !isEnabled("hide-video-player"));
|
||||
});
|
||||
};
|
||||
|
||||
@ -5,6 +5,7 @@ const { setOptions } = require("../../config/plugins");
|
||||
function $(selector) { return document.querySelector(selector); }
|
||||
|
||||
module.exports = (options) => {
|
||||
overrideAddEventListener();
|
||||
|
||||
setupPlaybar(options);
|
||||
|
||||
@ -22,9 +23,35 @@ module.exports = (options) => {
|
||||
ipcRenderer.once("setupVideoPlayerVolumeMousewheel", (_event, toEnable) => {
|
||||
if (toEnable)
|
||||
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 */
|
||||
function setupVideoPlayerOnwheel(options) {
|
||||
$("#main-panel").addEventListener("wheel", event => {
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
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;
|
||||
});
|
||||
};
|
||||
@ -8,12 +8,6 @@ const { fileExists } = require("./plugins/utils");
|
||||
const plugins = config.plugins.getEnabled();
|
||||
|
||||
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");
|
||||
fileExists(actionPath, () => {
|
||||
const actions = require(actionPath).actions || {};
|
||||
|
||||
Reference in New Issue
Block a user