Skip to content

Commit

Permalink
Updated code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Code Design committed Dec 30, 2024
1 parent 9a0b2b1 commit d51c920
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
45 changes: 24 additions & 21 deletions gbppd-mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var gbppd = (function () {
n = [],
o = [],
l = document.getElementsByClassName("overflow-scrolling"),
r = l[0].scrollHeight,
r = l ? l[0].scrollHeight : 0,
i = 0,
a = "",
c = function (e, t) {
Expand All @@ -15,38 +15,41 @@ var gbppd = (function () {
)
for (let e of o) n.push(e.src);
},
s = function () {
u = 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));
(a = setInterval(u, 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>"
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>"
),
(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));
(l += 1);
!(function (e) {
let t = null;
!(function n(o) {
o >= e.length
? t && clearTimeout(t)
: (e[o].href.match(/books.google./) && e[o].click(),
(t = setTimeout(function () {
n(o + 1);
}, 500)));
})(0);
})(o.document.getElementsByTagName("a")),
t && (t.disconnect(), (t = null)),
clearInterval(a),
clearTimeout(timeOutId);
}
var e;
},
};
})();
9 changes: 7 additions & 2 deletions gbppd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var gbppd = (function () {
let targets = [];

let scroll = document.getElementsByClassName("overflow-scrolling");
let scrollHeight = scroll[0].scrollHeight;
let scrollHeight = scroll ? scroll[0].scrollHeight : 0;
let scrollAmount = 800;
let scrollCount = 0;
let intervalId = "";
Expand Down Expand Up @@ -34,16 +34,18 @@ var gbppd = (function () {
};

let downloadAllPages = function (a) {
let timeOutId = null;
function next(i) {
if (i >= a.length) {
if (timeOutId) clearTimeout(timeOutId);
return;
}

if (a[i].href.match(/books.google./)) {
a[i].click();
}

setTimeout(function () {
timeOutId = setTimeout(function () {
next(i + 1);
}, 500);
}
Expand Down Expand Up @@ -92,6 +94,9 @@ var gbppd = (function () {
observer.disconnect();
observer = null;
}

clearInterval(intervalId);
clearTimeout(timeOutId);
}
},
};
Expand Down

0 comments on commit d51c920

Please sign in to comment.