Advertisement
gheja

Move from Watch Later on YouTube - GreaseMonkey script / TamperMonkey script

May 21st, 2021
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Move from Watch Later on YouTube
  3. // @namespace    https://github.com/gheja
  4. // @version      0.1
  5. // @description  Move the videos from "Watch later" to a different playlist
  6. // @author       gheja
  7. // @match        https://www.youtube.com/playlist?list=WL
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.  
  14.     let _playlist_from = "Watch later";
  15.     let _playlist_to = "Watch later 2";
  16.  
  17.     function click5()
  18.     {
  19.         document.querySelector("#close-button").click();
  20.         window.setTimeout(run, 1000 + Math.random() * 500);
  21.     }
  22.  
  23.     function click4()
  24.     {
  25.         let a;
  26.  
  27.         for (a of document.querySelectorAll("tp-yt-paper-checkbox"))
  28.         {
  29.             if (a.innerText != _playlist_from)
  30.             {
  31.                 continue;
  32.             }
  33.  
  34.             // only click if it is checked
  35.             if (a.querySelector("div.checked") != null)
  36.             {
  37.                 a.click();
  38.             }
  39.  
  40.             window.setTimeout(click5, 300 + Math.random() * 500);
  41.             return;
  42.         }
  43.  
  44.         console.log("Could not find the playlist \"" + _playlist_from +"\", aborting.");
  45.     }
  46.  
  47.     function click3()
  48.     {
  49.         let a;
  50.  
  51.         for (a of document.querySelectorAll("tp-yt-paper-checkbox"))
  52.         {
  53.             if (a.innerText != _playlist_to)
  54.             {
  55.                 continue;
  56.             }
  57.  
  58.             // only click if it is not checked
  59.             if (a.querySelector("div.checked") == null)
  60.             {
  61.                 a.click();
  62.             }
  63.  
  64.             window.setTimeout(click4, 300 + Math.random() * 500);
  65.             return;
  66.         }
  67.  
  68.         console.log("Could not find the playlist \"" + _playlist_to +"\", aborting.");
  69.     }
  70.  
  71.     function click2()
  72.     {
  73.         let a;
  74.  
  75.         for (a of document.querySelectorAll(".ytd-menu-popup-renderer"))
  76.         {
  77.             if (a.innerText != "Save to playlist")
  78.             {
  79.                 continue;
  80.             }
  81.  
  82.             a.click();
  83.             window.setTimeout(click3, 2000 + Math.random() * 500);
  84.             return;
  85.         }
  86.  
  87.         console.log("Could not find the \"Saver to playlist\" button, aborting.");
  88.     }
  89.  
  90.     function run()
  91.     {
  92.         let item, a;
  93.  
  94.         for (item of document.querySelectorAll("ytd-playlist-video-renderer"))
  95.         {
  96.             if (item.dataset.done == 1)
  97.             {
  98.                 continue;
  99.             }
  100.  
  101.             item.dataset.done = 1;
  102.  
  103.             for (a of item.querySelectorAll("button.yt-icon-button"))
  104.             {
  105.                 if (a.ariaLabel != "Action menu")
  106.                 {
  107.                     continue;
  108.                 }
  109.  
  110.                 a.click();
  111.                 window.setTimeout(click2, 300 + Math.random() * 500);
  112.                 return;
  113.             }
  114.  
  115.             console.log("Could not find the \"...\" button for the video, aborting.");
  116.             return;
  117.         }
  118.  
  119.         console.log("No more videos to process.");
  120.     }
  121.  
  122.     function init()
  123.     {
  124.         let tmp;
  125.  
  126.         tmp = document.createElement("button");
  127.         tmp.style.position = "fixed";
  128.         tmp.style.bottom = 0;
  129.         tmp.style.left = 0;
  130.         tmp.style.zIndex = 3000;
  131.         tmp.innerHTML = "Move to \"" + _playlist_to + "\"";
  132.         tmp.addEventListener("click", run);
  133.  
  134.         document.body.appendChild(tmp)
  135.  
  136.     }
  137.  
  138.     init();
  139.  
  140. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement