From 9a0b2b1960c2a5a6f80035820864212c05d979c6 Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 6 Apr 2024 01:51:44 +0900 Subject: [PATCH] Add random scroll amount --- gbppd-mini.js | 53 +++++++++++++++++- gbppd.js | 150 +++++++++++++++++++++++++++----------------------- 2 files changed, 132 insertions(+), 71 deletions(-) diff --git a/gbppd-mini.js b/gbppd-mini.js index 411d2b3..58276f5 100644 --- a/gbppd-mini.js +++ b/gbppd-mini.js @@ -1 +1,52 @@ -var gbppd=function(){let e=document.getElementById("viewport"),t=null,n=[],o=[],l=document.getElementsByClassName("overflow-scrolling"),i=l[0].scrollHeight,r=0,c="",s=function(e,t){for(let t of e)if("childList"==t.type&&(o=t.target.getElementsByTagName("img")))for(let e of o)n.push(e.src)},a=function(){(r+=700)'+t+"
"),l+=1;!function(e){!function t(n){n>=e.length||(e[n].href.match(/books.google./)&&e[n].click(),setTimeout(function(){t(n+1)},500))}(0)}(o.document.getElementsByTagName("a")),t&&(t.disconnect(),t=null)}}}}(); \ No newline at end of file +var gbppd = (function () { + let e = document.getElementById("viewport"), + t = null, + n = [], + o = [], + l = document.getElementsByClassName("overflow-scrolling"), + r = l[0].scrollHeight, + i = 0, + a = "", + c = function (e, t) { + for (let t of e) + if ( + "childList" == t.type && + ((o = t.target.getElementsByTagName("img")), o) + ) + for (let e of o) n.push(e.src); + }, + s = function () { + (i += Math.floor(751 * Math.random()) + 50), + i < r ? l[0].scrollBy(0, 800) : clearInterval(a); + }; + return { + start: function () { + (t = new MutationObserver(c)), + t.observe(e, { attributes: !0, childList: !0, subtree: !0 }), + (a = setInterval(s, 500)); + }, + finish: function () { + { + let o = new Set(n), + l = window.open(), + r = 0; + for (let e of o) + l.document.write( + '' + e + "
" + ), + (r += 1); + let i = l.document.getElementsByTagName("a"); + (e = i), + (function t(n) { + n >= e.length || + (e[n].href.match(/books.google./) && e[n].click(), + setTimeout(function () { + t(n + 1); + }, 500)); + })(0), + t && (t.disconnect(), (t = null)); + } + var e; + }, + }; +})(); diff --git a/gbppd.js b/gbppd.js index 82d82cf..fb8e6f8 100644 --- a/gbppd.js +++ b/gbppd.js @@ -1,88 +1,98 @@ -var gbppd = (function (){ - let book = document.getElementById("viewport"); - let observer = null; - let links = []; - let targets = []; +var gbppd = (function () { + let book = document.getElementById("viewport"); + let observer = null; + let links = []; + let targets = []; - let scroll = document.getElementsByClassName("overflow-scrolling"); - let scrollHeight = scroll[0].scrollHeight; - let scrollAmount = 700; - let scrollCount = 0; - let intervalId = ''; + let scroll = document.getElementsByClassName("overflow-scrolling"); + let scrollHeight = scroll[0].scrollHeight; + let scrollAmount = 800; + let scrollCount = 0; + let intervalId = ""; - let callback = function(mutationsList, observer) { - - for(let mutation of mutationsList) { - if (mutation.type == 'childList') { - - targets = mutation.target.getElementsByTagName("img"); + let callback = function (mutationsList, observer) { + for (let mutation of mutationsList) { + if (mutation.type == "childList") { + targets = mutation.target.getElementsByTagName("img"); - if(targets) { - for(let target of targets){ - links.push(target.src); - } - } - } + if (targets) { + for (let target of targets) { + links.push(target.src); + } } + } } + }; - let movePage = function() { - scrollCount += scrollAmount; - if(scrollCount < scrollHeight) { - scroll[0].scrollBy(0, scrollAmount); - }else { - clearInterval(intervalId); - } + let movePage = function () { + scrollCount += Math.floor(Math.random() * (scrollAmount - 50 + 1)) + 50; + if (scrollCount < scrollHeight) { + scroll[0].scrollBy(0, scrollAmount); + } else { + clearInterval(intervalId); } - - let downloadAllPages = function(a) { - function next(i){ - if(i >= a.length) { - return; - } + }; - if(a[i].href.match(/books.google./)) { - a[i].click(); - } - - setTimeout(function() { - next(i + 1); - }, 500); - } + let downloadAllPages = function (a) { + function next(i) { + if (i >= a.length) { + return; + } + + if (a[i].href.match(/books.google./)) { + a[i].click(); + } - next(0); + setTimeout(function () { + next(i + 1); + }, 500); } - - return { - start: function(){ - observer = new MutationObserver(callback); - observer.observe(book, { attributes: true, childList: true, subtree: true }); - intervalId = setInterval(movePage, 500); - }, + next(0); + }; - finish: function(){ - { - let uniqLinks = new Set(links); - let newWindow = window.open(); - - let pageNum = 0; - - for(let link of uniqLinks) { - newWindow.document.write('' + link + "" + "
"); - pageNum = pageNum + 1; - } + return { + start: function () { + observer = new MutationObserver(callback); + observer.observe(book, { + attributes: true, + childList: true, + subtree: true, + }); + intervalId = setInterval(movePage, 500); + }, - let anchors = newWindow.document.getElementsByTagName("a"); + finish: function () { + { + let uniqLinks = new Set(links); + let newWindow = window.open(); - downloadAllPages(anchors); + let pageNum = 0; - if(observer) { - observer.disconnect(); - observer = null; - } - } + for (let link of uniqLinks) { + newWindow.document.write( + '' + + link + + "" + + "
" + ); + pageNum = pageNum + 1; } - }; + let anchors = newWindow.document.getElementsByTagName("a"); + + downloadAllPages(anchors); + + if (observer) { + observer.disconnect(); + observer = null; + } + } + }, + }; })();