SHARE
TWEET

Untitled

a guest Aug 21st, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (() => {
  2.     const positionEl = document.querySelector('.cwl-guide-prev-next .right');
  3.     const btn        = document.getElementsByName('next-step')[0];
  4.  
  5.     const INTERVAL       = 80;   // 75 wont work
  6.     const SLEEP_DURATION = 2000; // might be increased; ~1.8s is my avg load
  7.  
  8.     let currentStep = 1;
  9.     let currentPage = 1;
  10.  
  11.     const targetPage = prompt('please enter target page', 2);
  12.  
  13.     if(targetPage <= 1) {
  14.         alert('that\'s a no from me dawg');
  15.         return;
  16.     }
  17.  
  18.     const updateETA = (step, limit) => {
  19.         const newETA = Math.round(((targetPage - currentPage) * SLEEP_DURATION + (limit - step) * INTERVAL - SLEEP_DURATION) / 1000);
  20.  
  21.         etaBtn.innerText = `ETA: ~${newETA}s`;
  22.     };
  23.  
  24.     const doSteps = async () => {
  25.         if(currentPage < targetPage) {
  26.             const [step, limit] = positionEl.innerText.split(' / ');
  27.             updateETA(step, limit);
  28.  
  29.             // reset step on next page
  30.             if(step === 1) {
  31.                 currentStep = 1;
  32.             }
  33.  
  34.             // step limit reached, next page up
  35.             if(step === limit) {
  36.                 currentPage += 1;
  37.  
  38.                 pageBtn.innerText = 'loading...';
  39.  
  40.                 // click to force-load in case its something that needs loading
  41.                 btn.click();
  42.  
  43.                 // remove interval to prevent queueing
  44.                 clearInterval(interval);
  45.  
  46.                 // sleep SLEEP_DURATION seconds to await potential data load
  47.                 await new Promise(resolve => setTimeout(resolve, SLEEP_DURATION));
  48.  
  49.                 pageBtn.innerText = `Page ${currentPage}`;
  50.  
  51.                 // restart paused interval
  52.                 interval = setInterval(doSteps, INTERVAL);
  53.                 return;
  54.             }
  55.  
  56.                
  57.             btn.click();
  58.             return;
  59.         }
  60.  
  61.         clearInterval(interval);
  62.         etaBtn.remove();
  63.     }
  64.  
  65.     let interval = setInterval(doSteps, INTERVAL);
  66.  
  67.     // some UI info
  68.     const pageBtn = document.createElement('button');
  69.     const etaBtn  = document.createElement('button');
  70.  
  71.     pageBtn.innerText = 'Page 1';
  72.     etaBtn.innerText  = 'ETA: ?s';
  73.  
  74.     [pageBtn, etaBtn].forEach(injectedBtn => {
  75.         injectedBtn.type = 'button';
  76.         injectedBtn.style.marginRight = '1rem';
  77.         injectedBtn.disabled = true;
  78.         ['injected-btn', 'btn-small'].forEach(className => injectedBtn.classList.add(className));
  79.         btn.insertAdjacentElement('afterend', injectedBtn);
  80.     });
  81. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top