mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 20:01:47 +00:00
lint
This commit is contained in:
@ -7,8 +7,9 @@ let enabled = false;
|
|||||||
module.exports = (win) => {
|
module.exports = (win) => {
|
||||||
enabled = true;
|
enabled = true;
|
||||||
|
|
||||||
//did-finish-load is called after DOMContentLoaded.
|
// youtube-music register some of the target listeners after DOMContentLoaded
|
||||||
//thats the reason the timing is controlled from main
|
// 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.once("did-finish-load", () => {
|
||||||
win.webContents.send("restoreAddEventListener");
|
win.webContents.send("restoreAddEventListener");
|
||||||
});
|
});
|
||||||
|
|||||||
@ -24,7 +24,6 @@ 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
|
||||||
@ -68,7 +67,7 @@ function changeVolume(increase, options) {
|
|||||||
// Change tooltips to new value
|
// Change tooltips to new value
|
||||||
setTooltip(options.savedVolume);
|
setTooltip(options.savedVolume);
|
||||||
// Show volume slider on volume change
|
// Show volume slider on volume change
|
||||||
slider.classList.add("on-hover")
|
slider.classList.add("on-hover");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save volume + Update the volume tooltip when volume-slider is manually changed
|
// Save volume + Update the volume tooltip when volume-slider is manually changed
|
||||||
@ -95,7 +94,7 @@ function setupSliderObserver(options) {
|
|||||||
// Set new volume as tooltip for volume slider and icon + expanding slider (appears when window size is small)
|
// Set new volume as tooltip for volume slider and icon + expanding slider (appears when window size is small)
|
||||||
const tooltipTargets = [
|
const tooltipTargets = [
|
||||||
"#volume-slider",
|
"#volume-slider",
|
||||||
"tp-yt-paper-icon-button.volume.style-scope.ytmusic-player-bar",
|
"tp-yt-paper-icon-button.volume",
|
||||||
"#expand-volume-slider",
|
"#expand-volume-slider",
|
||||||
"#expand-volume"
|
"#expand-volume"
|
||||||
];
|
];
|
||||||
|
|||||||
@ -1,28 +1,28 @@
|
|||||||
const { ipcRenderer } = require("electron");
|
const { ipcRenderer } = require("electron");
|
||||||
|
|
||||||
// Override specific listeners of volume-slider by modifying Element.prototype
|
// Override specific listeners of volume-slider by modifying Element.prototype
|
||||||
function overrideAddEventListener(){
|
function overrideAddEventListener() {
|
||||||
// Events to ignore
|
// Events to ignore
|
||||||
const nativeEvents = ["mousewheel", "keydown", "keyup"];
|
const nativeEvents = ["mousewheel", "keydown", "keyup"];
|
||||||
// Save native addEventListener
|
// Save native addEventListener
|
||||||
Element.prototype._addEventListener = Element.prototype.addEventListener;
|
Element.prototype._addEventListener = Element.prototype.addEventListener;
|
||||||
|
// Override addEventListener to Ignore specific events in volume-slider
|
||||||
Element.prototype.addEventListener = function(type,listener,useCapture=false) {
|
Element.prototype.addEventListener = function (type, listener, useCapture = false) {
|
||||||
if(this.tagName === "TP-YT-PAPER-SLIDER") { //tagName of #volume-slider
|
if (this.tagName === "TP-YT-PAPER-SLIDER") { // tagName of #volume-slider
|
||||||
for (const eventType of nativeEvents) {
|
for (const eventType of nativeEvents) {
|
||||||
if (eventType === type) {
|
if (eventType === type) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} //else
|
}//else
|
||||||
this._addEventListener(type,listener,useCapture);
|
this._addEventListener(type, listener, useCapture);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
overrideAddEventListener();
|
overrideAddEventListener();
|
||||||
// Restore the listeners after load to avoid keeping Element.prototype altered
|
// 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
|
ipcRenderer.once("restoreAddEventListener", () => { //called from Main to make sure page is completly loaded
|
||||||
Element.prototype.addEventListener = Element.prototype._addEventListener;
|
Element.prototype.addEventListener = Element.prototype._addEventListener;
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user