From 2dcc7fd9473c31a030de1c1b022a74ed1ca657dd Mon Sep 17 00:00:00 2001 From: Adler Luiz Date: Tue, 25 Aug 2020 01:31:44 -0300 Subject: [PATCH] =?UTF-8?q?:spark=C3=A7es:=20Improve=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/providers/infoPlayerProvider.js | 16 ++++++++++++++-- src/utils/injectControls.js | 21 +++++++++++++++------ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/providers/infoPlayerProvider.js b/src/providers/infoPlayerProvider.js index f53e4fc6a..54481ceff 100644 --- a/src/providers/infoPlayerProvider.js +++ b/src/providers/infoPlayerProvider.js @@ -485,8 +485,20 @@ function isInLibrary() { .then((_) => { var popup = document.querySelector('.ytmusic-menu-popup-renderer'); var addLibrary = Array.from(popup.children) - .filter( (value) => value.querySelector('g path:not([fill])').getAttribute('d') == "M20 2H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-7.53 12L9 10.5l1.4-1.41 2.07 2.08L17.6 6 19 7.41 12.47 14zM4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6z" ) - return (addLibrary.length == 1) + .filter( (value) => value.querySelector('g path:not([fill])').getAttribute('d') == "M20 2H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-7.53 12L9 10.5l1.4-1.41 2.07 2.08L17.6 6 19 7.41 12.47 14zM4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6z" || value.querySelector('g path:not([fill])').getAttribute('d') == "M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-1 9h-4v4h-2v-4H9V9h4V5h2v4h4v2z" )[0] + + if(addLibrary != undefined) { + var _d = addLibrary.querySelector('g path:not([fill])').getAttribute('d') + + if(_d == 'M20 2H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-7.53 12L9 10.5l1.4-1.41 2.07 2.08L17.6 6 19 7.41 12.47 14zM4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6z') { + return true; + } else { + return false; + } + } else { + return true; + } + //return (addLibrary.length == 1) }) ` ) diff --git a/src/utils/injectControls.js b/src/utils/injectControls.js index 0af14073b..43573e3ae 100644 --- a/src/utils/injectControls.js +++ b/src/utils/injectControls.js @@ -395,14 +395,18 @@ function createBottomPlayerBarContent() { playerBarMiddleControls.insertBefore(elementAddToLibraryButton, playerBarMiddleControls.children.item(1)); + var showAddToLibrary = false; if(${shortcutButtons['add-to-library']}) { document.querySelector("#btn_ytmd_add_to_library").classList.remove("hide"); + showAddToLibrary = true; } - + settingsProvider.onDidChange('settings-shortcut-buttons.add-to-library', data => { if (data.newValue) { + showAddToLibrary = true; document.querySelector("#btn_ytmd_add_to_library").classList.remove("hide"); } else { + showAddToLibrary = false; document.querySelector("#btn_ytmd_add_to_library").classList.add("hide"); } }) @@ -411,13 +415,18 @@ function createBottomPlayerBarContent() { var popup = document.querySelector('.ytmusic-menu-popup-renderer'); var addLibrary = Array.from(popup.children) .filter( (value) => value.querySelector('g path:not([fill])').getAttribute('d') == "M20 2H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-7.53 12L9 10.5l1.4-1.41 2.07 2.08L17.6 6 19 7.41 12.47 14zM4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6z" || value.querySelector('g path:not([fill])').getAttribute('d') == "M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-1 9h-4v4h-2v-4H9V9h4V5h2v4h4v2z" )[0] - - var _d = addLibrary.querySelector('g path:not([fill])').getAttribute('d') - if(_d == 'M20 2H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-7.53 12L9 10.5l1.4-1.41 2.07 2.08L17.6 6 19 7.41 12.47 14zM4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6z') { - document.querySelector('#ytmd_add_to_library').innerText = 'check' + if(addLibrary != undefined && showAddToLibrary) { + var _d = addLibrary.querySelector('g path:not([fill])').getAttribute('d') + + if(_d == 'M20 2H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-7.53 12L9 10.5l1.4-1.41 2.07 2.08L17.6 6 19 7.41 12.47 14zM4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6z') { + document.querySelector('#ytmd_add_to_library').innerText = 'check' + } else { + document.querySelector('#ytmd_add_to_library').innerText = 'library_add' + } + document.querySelector('#btn_ytmd_add_to_library').classList.remove('hide'); } else { - document.querySelector('#ytmd_add_to_library').innerText = 'library_add' + document.querySelector('#btn_ytmd_add_to_library').classList.add('hide'); } }, 800)