Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Move from Watch Later on YouTube
- // @namespace https://github.com/gheja
- // @version 0.1
- // @description Move the videos from "Watch later" to a different playlist
- // @author gheja
- // @match https://www.youtube.com/playlist?list=WL
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- let _playlist_from = "Watch later";
- let _playlist_to = "Watch later 2";
- function click5()
- {
- document.querySelector("#close-button").click();
- window.setTimeout(run, 1000 + Math.random() * 500);
- }
- function click4()
- {
- let a;
- for (a of document.querySelectorAll("tp-yt-paper-checkbox"))
- {
- if (a.innerText != _playlist_from)
- {
- continue;
- }
- // only click if it is checked
- if (a.querySelector("div.checked") != null)
- {
- a.click();
- }
- window.setTimeout(click5, 300 + Math.random() * 500);
- return;
- }
- console.log("Could not find the playlist \"" + _playlist_from +"\", aborting.");
- }
- function click3()
- {
- let a;
- for (a of document.querySelectorAll("tp-yt-paper-checkbox"))
- {
- if (a.innerText != _playlist_to)
- {
- continue;
- }
- // only click if it is not checked
- if (a.querySelector("div.checked") == null)
- {
- a.click();
- }
- window.setTimeout(click4, 300 + Math.random() * 500);
- return;
- }
- console.log("Could not find the playlist \"" + _playlist_to +"\", aborting.");
- }
- function click2()
- {
- let a;
- for (a of document.querySelectorAll(".ytd-menu-popup-renderer"))
- {
- if (a.innerText != "Save to playlist")
- {
- continue;
- }
- a.click();
- window.setTimeout(click3, 2000 + Math.random() * 500);
- return;
- }
- console.log("Could not find the \"Saver to playlist\" button, aborting.");
- }
- function run()
- {
- let item, a;
- for (item of document.querySelectorAll("ytd-playlist-video-renderer"))
- {
- if (item.dataset.done == 1)
- {
- continue;
- }
- item.dataset.done = 1;
- for (a of item.querySelectorAll("button.yt-icon-button"))
- {
- if (a.ariaLabel != "Action menu")
- {
- continue;
- }
- a.click();
- window.setTimeout(click2, 300 + Math.random() * 500);
- return;
- }
- console.log("Could not find the \"...\" button for the video, aborting.");
- return;
- }
- console.log("No more videos to process.");
- }
- function init()
- {
- let tmp;
- tmp = document.createElement("button");
- tmp.style.position = "fixed";
- tmp.style.bottom = 0;
- tmp.style.left = 0;
- tmp.style.zIndex = 3000;
- tmp.innerHTML = "Move to \"" + _playlist_to + "\"";
- tmp.addEventListener("click", run);
- document.body.appendChild(tmp)
- }
- init();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement