mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
removed unnecessary if and used better Repeat change detection
This commit is contained in:
@ -89,10 +89,9 @@ function registerMPRIS(win) {
|
||||
});
|
||||
|
||||
ipcMain.on('volumeChanged', (_, value) => {
|
||||
if (config.plugins.isEnabled('precise-volume')) {
|
||||
player.volume = value / 100;
|
||||
}
|
||||
});
|
||||
|
||||
player.on('volume', (newVolume) => {
|
||||
if (config.plugins.isEnabled('precise-volume')) {
|
||||
// With precise volume we can set the volume to the exact value.
|
||||
|
||||
@ -67,50 +67,14 @@ function setupTimeChangeListener() {
|
||||
}
|
||||
|
||||
function setupRepeatChangeListener() {
|
||||
const mp = { NONE: "Repeat off", ONE: "Repeat one", ALL: "Repeat all" }
|
||||
const repeatObserver = new MutationObserver(mutations => {
|
||||
document.cookie.split(';').forEach((cookie) => {
|
||||
let cookieName = cookie.substring(0, cookie.indexOf("=")).replaceAll(" ", "");
|
||||
if (cookieName === 'PREF') {
|
||||
let value = cookie.replace(cookieName + "=", "").replaceAll(" ", "");
|
||||
value.split('&').forEach((pair) => {
|
||||
if (pair !== '') {
|
||||
let splitpair = pair.split('=');
|
||||
if (splitpair[0] === "repeat") {
|
||||
if (splitpair[1] === "NONE")
|
||||
ipcRenderer.send('repeatChanged', "Repeat off");
|
||||
else if (splitpair[1] === "ONE") //MPRIS Playlist and Track Codes are switched to look the same as yt-music icons
|
||||
ipcRenderer.send('repeatChanged', "Repeat one");
|
||||
else if (splitpair[1] === "ALL")
|
||||
ipcRenderer.send('repeatChanged', "Repeat all");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
ipcRenderer.send('repeatChanged', mp[mutations[0].target.__dataHost.getState().queue.repeatMode])
|
||||
});
|
||||
repeatObserver.observe($('#right-controls .repeat'), {attributeFilter: ["title"]});
|
||||
|
||||
// Emit the initial value as well; as it's persistent between launches.
|
||||
// ipcRenderer.send('repeatChanged', $('#right-controls .repeat').title);
|
||||
document.cookie.split(';').forEach((cookie) => {
|
||||
let cookieName = cookie.substring(0, cookie.indexOf("=")).replaceAll(" ", "");
|
||||
if (cookieName === 'PREF') {
|
||||
let value = cookie.replace(cookieName + "=", "").replaceAll(" ", "");
|
||||
value.split('&').forEach((pair) => {
|
||||
if (pair !== '') {
|
||||
let splitpair = pair.split('=');
|
||||
if (splitpair[0] === "repeat") {
|
||||
if (splitpair[1] === "NONE")
|
||||
ipcRenderer.send('repeatChanged', "Repeat off");
|
||||
else if (splitpair[1] === "ONE") //MPRIS Playlist and Track Codes are switched to look the same as yt-music icons
|
||||
ipcRenderer.send('repeatChanged', "Repeat one");
|
||||
else if (splitpair[1] === "ALL")
|
||||
ipcRenderer.send('repeatChanged', "Repeat all");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
ipcRenderer.send('repeatChanged', mp[$('ytmusic-player-bar').getState().queue.repeatMode]);
|
||||
}
|
||||
|
||||
function setupVolumeChangeListener(api) {
|
||||
|
||||
Reference in New Issue
Block a user