Created
May 1, 2020 19:36
-
-
Save jsejcksn/6f8b55fb765e1f9e8fb61d64e4d1f7c3 to your computer and use it in GitHub Desktop.
Smash that like button (add current YouTube video to liked videos)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
const likeVideo = () => { | |
const [likeButton] = [...document.querySelectorAll('button')] | |
.filter(node => ( | |
typeof node.getAttribute('aria-label') === 'string' | |
&& node.getAttribute('aria-label').startsWith('like this video') | |
)); | |
let likeAnchor = likeButton; | |
while (likeAnchor.nodeName !== 'A') likeAnchor = likeAnchor.parentNode; | |
if (likeButton.getAttribute('aria-pressed') === 'true') { | |
console.log('Already liked'); | |
} | |
else if (likeButton.getAttribute('aria-pressed') === 'false') { | |
likeAnchor.click(); | |
console.log('Liked'); | |
} | |
else console.log('Cannot determine like status'); | |
}; | |
likeVideo(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment