Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (() => {
- const positionEl = document.querySelector('.cwl-guide-prev-next .right');
- const btn = document.getElementsByName('next-step')[0];
- const INTERVAL = 80; // 75 wont work
- const SLEEP_DURATION = 2000; // might be increased; ~1.8s is my avg load
- let currentStep = 1;
- let currentPage = 1;
- const targetPage = prompt('please enter target page', 2);
- if(targetPage <= 1) {
- alert('that\'s a no from me dawg');
- return;
- }
- const updateETA = (step, limit) => {
- const newETA = Math.round(((targetPage - currentPage) * SLEEP_DURATION + (limit - step) * INTERVAL - SLEEP_DURATION) / 1000);
- etaBtn.innerText = `ETA: ~${newETA}s`;
- };
- const doSteps = async () => {
- if(currentPage < targetPage) {
- const [step, limit] = positionEl.innerText.split(' / ');
- updateETA(step, limit);
- // reset step on next page
- if(step === 1) {
- currentStep = 1;
- }
- // step limit reached, next page up
- if(step === limit) {
- currentPage += 1;
- pageBtn.innerText = 'loading...';
- // click to force-load in case its something that needs loading
- btn.click();
- // remove interval to prevent queueing
- clearInterval(interval);
- // sleep SLEEP_DURATION seconds to await potential data load
- await new Promise(resolve => setTimeout(resolve, SLEEP_DURATION));
- pageBtn.innerText = `Page ${currentPage}`;
- // restart paused interval
- interval = setInterval(doSteps, INTERVAL);
- return;
- }
- btn.click();
- return;
- }
- clearInterval(interval);
- etaBtn.remove();
- }
- let interval = setInterval(doSteps, INTERVAL);
- // some UI info
- const pageBtn = document.createElement('button');
- const etaBtn = document.createElement('button');
- pageBtn.innerText = 'Page 1';
- etaBtn.innerText = 'ETA: ?s';
- [pageBtn, etaBtn].forEach(injectedBtn => {
- injectedBtn.type = 'button';
- injectedBtn.style.marginRight = '1rem';
- injectedBtn.disabled = true;
- ['injected-btn', 'btn-small'].forEach(className => injectedBtn.classList.add(className));
- btn.insertAdjacentElement('afterend', injectedBtn);
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement