diff --git a/main.js b/main.js index 8d795dbc9..2b78e3f0d 100644 --- a/main.js +++ b/main.js @@ -1117,8 +1117,8 @@ function createWindow() { backgroundColor: '#232323', width: 600, minWidth: 600, - height: 300, - minHeight: 300, + height: 220, + minHeight: 220, autoHideMenuBar: false, skipTaskbar: false, webPreferences: { diff --git a/src/pages/settings/discord_settings.html b/src/pages/settings/discord_settings.html index 867a6fe60..fd261a8c1 100644 --- a/src/pages/settings/discord_settings.html +++ b/src/pages/settings/discord_settings.html @@ -107,14 +107,6 @@ - -
diff --git a/src/pages/settings/discord_settings.js b/src/pages/settings/discord_settings.js index 9df519bbc..8cc3b883e 100644 --- a/src/pages/settings/discord_settings.js +++ b/src/pages/settings/discord_settings.js @@ -20,17 +20,19 @@ function loadSettings() { discordSettings.hideIdle } -document.addEventListener('DOMContentLoaded', function () { - loadSettings() -}) - -buttonSave.addEventListener('click', function () { +function save() { settingsProvider.set('discord-presence-settings', { details: document.getElementById('settings-discord-show-title').checked, state: document.getElementById('settings-discord-show-artist').checked, time: document.getElementById('settings-discord-show-time').checked, hideIdle: document.getElementById('settings-discord-show-idle').checked, }) +} + +document.addEventListener('DOMContentLoaded', function () { loadSettings() - buttonSave.innerText = __.trans('LABEL_SAVED') +}) + +document.querySelectorAll('input').forEach((input) => { + input.addEventListener('click', () => save()) }) diff --git a/src/providers/infoPlayerProvider.js b/src/providers/infoPlayerProvider.js index 65c817a19..30b34e308 100644 --- a/src/providers/infoPlayerProvider.js +++ b/src/providers/infoPlayerProvider.js @@ -75,7 +75,7 @@ function getTrackInfo() { function isPaused(webContents) { webContents - .executeJavaScript(`document.getElementsByTagName('video')[0].paused;`) + .executeJavaScript(`document.querySelector('video').paused;`) .then((isPaused) => { debug(`Is paused: ${isPaused}`) player.isPaused = isPaused @@ -86,7 +86,7 @@ function isPaused(webContents) { function getTitle(webContents) { webContents .executeJavaScript( - `document.getElementsByClassName('title ytmusic-player-bar')[0].innerText;` + `document.querySelector('.title.ytmusic-player-bar').textContent;` ) .then((title) => { debug(`Title is: ${title}`) @@ -98,7 +98,7 @@ function getTitle(webContents) { function getDuration(webContents) { webContents .executeJavaScript( - `document.getElementById('progress-bar').getAttribute('aria-valuemax');` + `document.querySelector('#progress-bar').getAttribute('aria-valuemax');` ) .then((duration) => { debug(`Duration is: ${parseInt(duration)}`) @@ -116,7 +116,7 @@ function getDuration(webContents) { function getLikeStatus(webContents) { webContents .executeJavaScript( - `document.getElementById('like-button-renderer').getAttribute('like-status');` + `document.querySelector('#like-button-renderer').getAttribute('like-status');` ) .then((likeStatus) => { debug(`Like status is: ${likeStatus}`) @@ -132,7 +132,7 @@ function getLikeStatus(webContents) { function getSeekbarPosition(webContents) { webContents .executeJavaScript( - `document.getElementById('progress-bar').getAttribute('aria-valuenow');` + `document.querySelector('#progress-bar').getAttribute('aria-valuenow');` ) .then((position) => { debug(`Seekbar position is: ${parseInt(position)}`) @@ -147,7 +147,7 @@ function getSeekbarPosition(webContents) { function getVolume(webContents) { webContents .executeJavaScript( - `document.getElementsByClassName('volume-slider style-scope ytmusic-player-bar')[0].getAttribute('value');` + `document.querySelector('.volume-slider.ytmusic-player-bar').getAttribute('value');` ) .then((volume) => { debug(`Volume % is: ${parseInt(volume)}`) @@ -160,14 +160,14 @@ function getAuthor(webContents) { webContents .executeJavaScript( ` - var bar = document.getElementsByClassName('subtitle ytmusic-player-bar')[0]; - - if (bar.getElementsByClassName('yt-simple-endpoint yt-formatted-string')[0]) { - title = bar.getElementsByClassName('yt-simple-endpoint yt-formatted-string')[0].innerText; - } else if (bar.getElementsByClassName('byline ytmusic-player-bar')[0]) { - title = bar.getElementsByClassName('byline ytmusic-player-bar')[0].innerText; - } - title; + var bar = document.getElementsByClassName('subtitle ytmusic-player-bar')[0]; + + if (bar.getElementsByClassName('yt-simple-endpoint yt-formatted-string')[0]) { + title = bar.getElementsByClassName('yt-simple-endpoint yt-formatted-string')[0].textContent; + } else if (bar.getElementsByClassName('byline ytmusic-player-bar')[0]) { + title = bar.getElementsByClassName('byline ytmusic-player-bar')[0].textContent; + } + title; ` ) .then((author) => { @@ -181,19 +181,19 @@ function getAlbum(webContents) { webContents .executeJavaScript( ` - var album = ''; - var player_bar = document.getElementsByClassName("byline ytmusic-player-bar")[0].children; - var arr_player_bar = Array.from(player_bar); - - arr_player_bar.forEach( function(data, index) { - - if (data.getAttribute('href') != null && data.getAttribute('href').includes('browse')) { - album = data.innerText; - } - } ) - - album - ` + var album = ''; + var player_bar = document.getElementsByClassName("byline ytmusic-player-bar")[0].children; + var arr_player_bar = Array.from(player_bar); + + arr_player_bar.forEach( function(data, index) { + + if (data.getAttribute('href') != null && data.getAttribute('href').includes('browse')) { + album = data.innerText; + } + } ) + + album + ` ) .then((album) => { debug(`Album is: ${album}`) @@ -206,19 +206,19 @@ function getCover(webContents) { webContents .executeJavaScript( ` - var cover; + var cover; - var thumbnail = document.getElementsByClassName('thumbnail ytmusic-player no-transition')[0]; - var image = thumbnail.getElementsByClassName('yt-img-shadow')[0].src; + var thumbnail = document.querySelector('.thumbnail.ytmusic-player.no-transition'); + var image = thumbnail.querySelector('.yt-img-shadow').src; - cover = image; + cover = image; - if (cover.includes("data:image")) { - cover = document.getElementsByClassName("image ytmusic-player-bar")[0].src - } + if (cover.includes("data:image")) { + cover = document.querySelector(".image.ytmusic-player-bar").src; + } - cover; - ` + cover; + ` ) .then((cover) => { debug(`Cover is: ${cover}`) @@ -230,7 +230,7 @@ function getCover(webContents) { function getRepeatType(webContents) { webContents .executeJavaScript( - `document.getElementsByTagName("ytmusic-player-bar")[0].getAttribute("repeat-mode_");` + `document.querySelector("ytmusic-player-bar").getAttribute("repeat-mode_");` ) .then((repeatType) => { debug(`Repeat type is: ${repeatType}`) @@ -242,7 +242,7 @@ function getRepeatType(webContents) { function getUrl(webContents) { webContents .executeJavaScript( - `document.getElementsByClassName('ytp-title-link yt-uix-sessionlink')[0].href` + `document.querySelector('.ytp-title-link.yt-uix-sessionlink').href` ) .then((url) => { if (url) { @@ -333,7 +333,7 @@ function addToLibary(webContents) { function isVideo(webContents) { webContents .executeJavaScript( - `document.getElementById('player').hasAttribute('video-mode_')` + `document.querySelector('#player').hasAttribute('video-mode_')` ) .then((isVideo) => { track.isVideo = !!isVideo @@ -345,7 +345,7 @@ function isVideo(webContents) { function isAdvertisement(webContents) { webContents .executeJavaScript( - `document.getElementsByClassName('advertisement ')[0].hasAttribute('hidden')` + `document.querySelector('.advertisement').hasAttribute('hidden')` ) .then((isAdvertisement) => { track.isAdvertisement = !isAdvertisement @@ -447,11 +447,12 @@ function firstPlay(webContents) { webContents .executeJavaScript( ` - var carousel = document.getElementsByClassName('carousel')[0]; - var firstChild = carousel.querySelector('#items').children[0]; - var playButton = firstChild.querySelector('#play-button') - - playButton.click();` + var carousel = document.querySelector('.carousel'); + var firstChild = carousel.querySelector('#items').children[0]; + var playButton = firstChild.querySelector('#play-button') + + playButton.click(); + ` ) .then() .catch((_) => console.log('error firstPlay'))