-
-
Save NoCtrlZkun/125bbe4ecd587fcf5e048b4dc12d41a4 to your computer and use it in GitHub Desktop.
TamperMonkey add to playlist
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
// ==UserScript== | |
// @name YouTube add to playlist | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @include https://www.youtube.com/* | |
// @grant none | |
// ==/UserScript== | |
let playlistButton = null; | |
let playlistName = null; | |
playlistName = "2017"; | |
function onKeyPress(e) { | |
// match ']' key | |
if (e.keyCode === 93){ | |
clickAdd(); | |
} | |
// match '\' key | |
if (e.keyCode === 92){ | |
playlistButton = findPlaylistButton(playlistName); | |
playlistButton.click(); | |
} | |
} | |
function clickAdd(){ | |
let addButton; | |
let col = document.getElementsByClassName("yt-uix-button-content") | |
for (let i = 0; i < col.length; i++){ | |
if(col.item(i).innerText === "Add to"){ | |
addButton = col.item(i); | |
} | |
} | |
addButton.click(); | |
} | |
function findPlaylistButton(playlistName){ | |
let classSearch = "addto-playlist-item yt-uix-button-menu-item contains-all-selected-videos"; | |
classSearch = "playlist-name"; | |
//console.log("scanning for playlist-status elements..."); | |
let collection = document.getElementsByClassName(classSearch); | |
//console.log("found " + playlistElem.length); | |
for (let i = 0; i < collection.length; i++){ | |
if(collection.item(i).innerText === playlistName){ | |
//console.log("item found!"); | |
return collection.item(i); | |
} | |
} | |
//console.log("finished scanning. no matches found"); | |
return null; | |
} | |
(function() { | |
'use strict'; | |
document.onkeypress = onKeyPress; | |
console.log("EDM_youtube"); | |
findPlaylistButton(); | |
})(); | |
/* | |
<button class="playlist-status" role="menuitemcheckbox" title="Click to remove video from 2017" aria-label="Click to remove video from 2017 Public playlist" aria-checked="checked"></button> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment