Răsfoiți Sursa

process only if not already scrolled to the bottom

Gildas 7 ani în urmă
părinte
comite
82f3a1e747
1 a modificat fișierele cu 14 adăugiri și 2 ștergeri
  1. 14 2
      lib/lazy/content/content-lazy-loader.js

+ 14 - 2
lib/lazy/content/content-lazy-loader.js

@@ -18,7 +18,7 @@
  *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* global browser, document, MutationObserver, setTimeout, clearTimeout, hooksFrame, addEventListener, removeEventListener */
+/* global browser, document, MutationObserver, setTimeout, clearTimeout, hooksFrame, addEventListener, removeEventListener, scrollY, scrollX */
 
 this.lazyLoader = this.lazyLoader || (() => {
 
@@ -26,7 +26,19 @@ this.lazyLoader = this.lazyLoader || (() => {
 	const SINGLE_FILE_UI_ELEMENT_CLASS = "single-file-ui-element";
 	const LAZY_SRC_ATTRIBUTE_NAME = "data-lazy-loaded-src";
 
-	return { process };
+	return {
+		process: options => {
+			const clientHeight = document.documentElement.clientHeight;
+			const clientWidth = document.documentElement.clientWidth;
+			const scrollHeight = Math.max(document.documentElement.scrollHeight - (clientHeight * 1.5), 0);
+			const scrollWidth = Math.max(document.documentElement.scrollWidth - (clientWidth * 1.5), 0);
+			if (scrollY <= scrollHeight && scrollX <= scrollWidth) {
+				return process(options);
+			} else {
+				return Promise.resolve();
+			}
+		}
+	};
 
 	function process(options) {
 		return new Promise(async resolve => {