Skip to content

Instantly share code, notes, and snippets.

@jsejcksn
Created May 1, 2020 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsejcksn/6f8b55fb765e1f9e8fb61d64e4d1f7c3 to your computer and use it in GitHub Desktop.
Save jsejcksn/6f8b55fb765e1f9e8fb61d64e4d1f7c3 to your computer and use it in GitHub Desktop.
Smash that like button (add current YouTube video to liked videos)
(() => {
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