From 01b1801e97e3f38916d474b3d091047fc7d08cb6 Mon Sep 17 00:00:00 2001 From: Mark Code Design <> Date: Tue, 31 Dec 2024 00:56:01 +0900 Subject: [PATCH] Updated code. --- gbppd-mini.js | 45 ++++++++++++++++++++++++--------------------- gbppd.js | 9 +++++++-- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/gbppd-mini.js b/gbppd-mini.js index 58276f5..bfdabb1 100644 --- a/gbppd-mini.js +++ b/gbppd-mini.js @@ -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) { @@ -15,7 +15,7 @@ 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); }; @@ -23,30 +23,33 @@ var gbppd = (function () { 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( - '' + e + "
" + let e = new Set(n), + o = window.open(), + l = 0; + for (let t of e) + o.document.write( + '' + t + "
" ), - (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; }, }; })(); diff --git a/gbppd.js b/gbppd.js index fb8e6f8..d1ecc89 100644 --- a/gbppd.js +++ b/gbppd.js @@ -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 = ""; @@ -34,8 +34,10 @@ var gbppd = (function () { }; let downloadAllPages = function (a) { + let timeOutId = null; function next(i) { if (i >= a.length) { + if (timeOutId) clearTimeout(timeOutId); return; } @@ -43,7 +45,7 @@ var gbppd = (function () { a[i].click(); } - setTimeout(function () { + timeOutId = setTimeout(function () { next(i + 1); }, 500); } @@ -92,6 +94,9 @@ var gbppd = (function () { observer.disconnect(); observer = null; } + + clearInterval(intervalId); + clearTimeout(timeOutId); } }, };