diff options
author | 2023-09-17 15:06:16 +0900 | |
---|---|---|
committer | 2023-09-17 14:06:16 +0800 | |
commit | 04b6a3a3ba64d424ff4628a5600cf8c48242ef1b (patch) | |
tree | 1ab0e4fc66eb6b1ca1f34290212710293820e240 /source/features/infinite-scroll.tsx | |
parent | 15e1ce757793b804297e5243b8aec31bb0b0c113 (diff) | |
download | refined-github-04b6a3a3ba64d424ff4628a5600cf8c48242ef1b.tar.gz refined-github-04b6a3a3ba64d424ff4628a5600cf8c48242ef1b.tar.zst refined-github-04b6a3a3ba64d424ff4628a5600cf8c48242ef1b.zip |
Restore `infinite-scroll` broken on new dashboard (#6918)23.9.17
Diffstat (limited to '')
-rw-r--r-- | source/features/infinite-scroll.tsx | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/source/features/infinite-scroll.tsx b/source/features/infinite-scroll.tsx index 4098f61e..f5df3ea9 100644 --- a/source/features/infinite-scroll.tsx +++ b/source/features/infinite-scroll.tsx @@ -7,35 +7,28 @@ import features from '../feature-manager.js'; import observe from '../helpers/selector-observer.js'; import onAbort from '../helpers/abort-controller.js'; -const loadMore = debounce(() => { - const button = select('[role="tabpanel"]:not([hidden]) button.ajax-pagination-btn')!; +const loadMore = debounce((button: HTMLButtonElement) => { button.click(); - button.textContent = 'Loading…'; // If GH hasn't loaded the JS, the click will not load anything. // We can detect if it worked by looking at the button's state, // and then trying again (auto-debounced) if (!button.disabled) { - loadMore(); + loadMore(button); } }, {wait: 200}); -const inView = new IntersectionObserver(([{isIntersecting}]) => { +const inView = new IntersectionObserver(([{target, isIntersecting}]) => { if (isIntersecting) { - loadMore(); + loadMore(target as HTMLButtonElement); } }, { rootMargin: '500px', // https://github.com/refined-github/refined-github/pull/505#issuecomment-309273098 }); -function init(signal: AbortSignal): void { - onAbort(signal, inView); - observe('.ajax-pagination-btn', button => { - inView.observe(button); - }, {signal}); - +function copyFooter(originalFooter: HTMLElement): void { // Copy the footer links to the sidebar to make them more accessible. Also keep a copy in the footer. - const footer = select('.footer > .d-flex')!.cloneNode(true); + const footer = originalFooter.cloneNode(true); for (const child of footer.children) { child.classList.remove('pl-lg-4', 'col-xl-3'); @@ -48,12 +41,19 @@ function init(signal: AbortSignal): void { ); } +function init(signal: AbortSignal): void { + onAbort(signal, inView); + observe('.ajax-pagination-btn', button => { + inView.observe(button); + }, {signal}); + + observe('.footer > .d-flex', copyFooter, {signal}); +} + void features.add(import.meta.url, { include: [ pageDetect.isDashboard, ], - deduplicate: 'has-rgh', - awaitDomReady: true, // Must wait for the whole page to load anyway init, }); |