Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const sleep = function(n = 0) {
  2.     return new Promise((resolve, reject) => {
  3.         setTimeout(() => resolve({ resolvedAfterNSeconds: n }), n * 1000);
  4.     });
  5. };
  6.  
  7. async function unCollapseVids(){
  8.     const arrows = document.querySelectorAll('span.udi-angle-down');
  9.     arrows.forEach(arrow => arrow.click());
  10.     await sleep(5);
  11. };
  12.  
  13. function goThrowVideos(){
  14.     const timeStep = 3000;
  15.     const vids = document.querySelectorAll('div[data-purpose="curriculum-section-container"] ul li.curriculum-item-link--curriculum-item--KX9MD > div');
  16.  
  17.     let index = 0;
  18.     let goToNextVid = true;
  19.     let lastUrl = '';
  20.  
  21.     const intrvl = setInterval(() => {
  22.         if(index >= vids.length) clearInterval(intrvl);
  23.  
  24.         if(goToNextVid){
  25.             const vid = vids[index];
  26.             vid.click();
  27.  
  28.             goToNextVid = false;
  29.             index++;
  30.         } else {
  31.             const video = document.querySelector('video');
  32.             const url = video && video.src;
  33.  
  34.             if (url && url !== lastUrl) {
  35.                 download(url);
  36.                 setTimeout(() => { goToNextVid = true }, timeStep*2);
  37.                 lastUrl = url;
  38.             }
  39.         }
  40.     }, timeStep);
  41. }
  42.  
  43.  
  44. function download (url) {
  45.     let a = document.createElement('a');
  46.     a.href = url;
  47.     a.textContent = 'download';
  48.     a.target = '_blank';
  49.     a.download = '';
  50.     a.style.display = 'none';
  51.  
  52.     document.body.appendChild(a);
  53.     a.click();
  54. }
  55.  
  56. unCollapseVids().then(() => goThrowVideos())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement