Skip to content

Commit

Permalink
Add random scroll amount
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark committed Apr 5, 2024
1 parent 47c303c commit 9a0b2b1
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 71 deletions.
53 changes: 52 additions & 1 deletion gbppd-mini.js
Original file line number Diff line number Diff line change
@@ -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)<i?l[0].scrollBy(0,700):clearInterval(c)};return{start:function(){(t=new MutationObserver(s)).observe(e,{attributes:!0,childList:!0,subtree:!0}),c=setInterval(a,500)},finish:function(){{let e=new Set(n),o=window.open(),l=0;for(let t of e)o.document.write('<a href="'+t+'" download="page-0'+l+'">'+t+"</a><br>"),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)}}}}();
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(
'<a href="' + e + '" download="page-0' + r + '">' + e + "</a><br>"
),
(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;
},
};
})();
150 changes: 80 additions & 70 deletions gbppd.js
Original file line number Diff line number Diff line change
@@ -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('<a href="' + link + '" download="' + 'page-0' + pageNum + '">' + link + "</a>" + "<br>");
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(
'<a href="' +
link +
'" download="' +
"page-0" +
pageNum +
'">' +
link +
"</a>" +
"<br>"
);
pageNum = pageNum + 1;
}
};

let anchors = newWindow.document.getElementsByTagName("a");

downloadAllPages(anchors);

if (observer) {
observer.disconnect();
observer = null;
}
}
},
};
})();

0 comments on commit 9a0b2b1

Please sign in to comment.