Skip to content

Commit

Permalink
:sparkçes: Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
adlerluiz committed Aug 25, 2020
1 parent 12cca64 commit 2dcc7fd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
16 changes: 14 additions & 2 deletions src/providers/infoPlayerProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
`
)
Expand Down
21 changes: 15 additions & 6 deletions src/utils/injectControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
})
Expand All @@ -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)
Expand Down

0 comments on commit 2dcc7fd

Please sign in to comment.