mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
disable native volume-slider listeners
This commit is contained in:
@ -3,8 +3,15 @@ This is used to determine if plugin is actually active
|
|||||||
(not if its only enabled in options)
|
(not if its only enabled in options)
|
||||||
*/
|
*/
|
||||||
let enabled = false;
|
let enabled = false;
|
||||||
module.exports = () => {
|
|
||||||
|
module.exports = (win) => {
|
||||||
enabled = true;
|
enabled = true;
|
||||||
|
|
||||||
|
//did-finish-load is called after DOMContentLoaded.
|
||||||
|
//thats the reason the timing is controlled from main
|
||||||
|
win.webContents.once("did-finish-load", () => {
|
||||||
|
win.webContents.send("restoreAddEventListener");
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.enabled = () => {
|
module.exports.enabled = () => {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
const { setOptions } = require("../../config/plugins");
|
|
||||||
const { ipcRenderer } = require("electron");
|
const { ipcRenderer } = require("electron");
|
||||||
|
const { setOptions } = require("../../config/plugins");
|
||||||
|
|
||||||
function $(selector) { return document.querySelector(selector); }
|
function $(selector) { return document.querySelector(selector); }
|
||||||
|
|
||||||
module.exports = (options) => {
|
module.exports = (options) => {
|
||||||
@ -23,6 +24,7 @@ function firstRun(options) {
|
|||||||
const slider = $("#volume-slider");
|
const slider = $("#volume-slider");
|
||||||
// Those elements load abit after DOMContentLoaded
|
// Those elements load abit after DOMContentLoaded
|
||||||
if (videoStream && slider) {
|
if (videoStream && slider) {
|
||||||
|
|
||||||
// Set saved volume IF it pass checks
|
// Set saved volume IF it pass checks
|
||||||
if (options.savedVolume
|
if (options.savedVolume
|
||||||
&& options.savedVolume >= 0 && options.savedVolume <= 100
|
&& options.savedVolume >= 0 && options.savedVolume <= 100
|
||||||
|
|||||||
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;
|
||||||
|
|
||||||
|
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 the listeners after 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;
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user