feat(infinite-scroll): add debug logs
These debug logs will help us troubleshoot
https://groups.google.com/g/twpowertools-discuss/c/4rJlGMkJNic/m/G0kymmwpAgAJ.
Change-Id: Id66d8fcb49b5002222d51fdf59163ccaaafde704
diff --git a/src/features/infiniteScroll/core/ccInfiniteScroll.ts b/src/features/infiniteScroll/core/ccInfiniteScroll.ts
index 84c3d63..2fbb3fd 100644
--- a/src/features/infiniteScroll/core/ccInfiniteScroll.ts
+++ b/src/features/infiniteScroll/core/ccInfiniteScroll.ts
@@ -51,33 +51,20 @@
return window.location.href.includes('/message/');
}
- observeWithPotentialDelay(node: Element) {
- if (this.intersectionObserver === null) {
- console.warn(
- '[infinitescroll] The intersectionObserver is not ready yet.',
- );
- return;
- }
-
- if (this.isPotentiallyArtificialScroll()) {
- window.setTimeout(() => {
- this.intersectionObserver.observe(node);
- }, kArtificialScrollingDelay);
- } else {
- this.intersectionObserver.observe(node);
- }
- }
-
observeLoadMoreBar(bar: Element) {
+ console.debug('[infinitescroll] Found load more bar:', bar);
getOptions(['thread', 'threadall']).then((threadOptions) => {
- if (threadOptions.thread)
+ if (threadOptions.thread) {
this.observeWithPotentialDelay(bar.querySelector('.load-more-button'));
- if (threadOptions.threadall)
+ }
+ if (threadOptions.threadall) {
this.observeWithPotentialDelay(bar.querySelector('.load-all-button'));
+ }
});
}
observeLoadMoreInteropBtn(btn: Element) {
+ console.debug('[infinitescroll] Found load more interop button:', btn);
const parentNode = btn.parentNode;
if (!(parentNode instanceof Element)) return;
const parentClasses = parentNode?.classList;
@@ -93,4 +80,36 @@
if (isEnabled) this.observeWithPotentialDelay(btn);
});
}
+
+ private observeWithPotentialDelay(node: Element) {
+ if (this.intersectionObserver === null) {
+ console.warn(
+ '[infinitescroll] The intersectionObserver is not ready yet.',
+ );
+ return;
+ }
+
+ if (this.isPotentiallyArtificialScroll()) {
+ console.debug(
+ `[infinitescroll] Delaying observing`,
+ node,
+ `due to potential artifical scroll.`,
+ );
+ window.setTimeout(() => {
+ console.debug(
+ '[infinitescroll] Starting to observe',
+ node,
+ 'after delay.',
+ );
+ this.intersectionObserver.observe(node);
+ }, kArtificialScrollingDelay);
+ } else {
+ console.debug(
+ '[infinitescroll] Starting to observe',
+ node,
+ 'without delay.',
+ );
+ this.intersectionObserver.observe(node);
+ }
+ }
}