| import {injectStylesheet} from '../common/contentScriptsUtils.js'; |
| import {getOptions} from '../common/optionsUtils.js'; |
| import {redirectIfApplicable} from '../redirect/index.js'; |
| |
| const kLoadMoreButtons = [ |
| { |
| feature: 'thread', |
| buttonSelectors: [ |
| '.thread-all-replies__load-more-button', |
| '.scTailwindThreadMorebuttonload-more .scTailwindThreadMorebuttonbutton', |
| '.scTailwindThreadMessagegapload-more .scTailwindThreadMessagegapbutton', |
| ], |
| }, |
| { |
| feature: 'threadall', |
| buttonSelectors: [ |
| '.thread-all-replies__load-all-button', |
| '.scTailwindThreadMorebuttonload-all .scTailwindThreadMorebuttonbutton', |
| '.scTailwindThreadMessagegapload-all .scTailwindThreadMessagegapbutton', |
| ], |
| } |
| ]; |
| const kMsgidDelay = 3500; |
| |
| function main() { |
| const ok = redirectIfApplicable(); |
| if (ok) return; |
| |
| getOptions(null).then(options => { |
| setUpInfiniteScrollWithPotentialDelay(options); |
| |
| if (options.imagemaxheight) |
| injectStylesheet(chrome.runtime.getURL('css/image_max_height.css')); |
| }); |
| } |
| |
| var intersectionObserver; |
| |
| function intersectionCallback(entries) { |
| entries.forEach(entry => { |
| if (entry.isIntersecting) { |
| entry.target.click(); |
| } |
| }); |
| } |
| |
| var intersectionOptions = { |
| threshold: 1.0, |
| }; |
| |
| function setUpInfiniteScroll(options) { |
| for (const entry of kLoadMoreButtons) { |
| if (options[entry.feature]) { |
| for (const selector of entry.buttonSelectors) { |
| let buttons = document.querySelectorAll(selector); |
| buttons.forEach(button => { |
| intersectionObserver = new IntersectionObserver( |
| intersectionCallback, intersectionOptions); |
| intersectionObserver.observe(button); |
| }); |
| } |
| } |
| } |
| } |
| |
| function setUpInfiniteScrollWithPotentialDelay(options) { |
| // If the msgid query parameter is set, the page will scroll to that message, |
| // which will show the "load more" button. |
| const params = new URLSearchParams(window.location.search); |
| if (params.has('msgid')) { |
| window.setTimeout(() => { |
| setUpInfiniteScroll(options); |
| }, kMsgidDelay); |
| } else { |
| setUpInfiniteScroll(options); |
| } |
| } |
| |
| main(); |