#4 James 我使用自定义页脚实现了这个扩展的功能!
<script>
function clickLoadMoreButton() {
const loadMoreButton = document.querySelector('.DiscussionList-loadMore .Button');
if (loadMoreButton) {
loadMoreButton.click();
}
}
function isButtonInViewport() {
const loadMoreButton = document.querySelector('.DiscussionList-loadMore .Button');
if (!loadMoreButton) return false;
const rect = loadMoreButton.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
window.addEventListener('scroll', function() {
if (isButtonInViewport()) {
clickLoadMoreButton();
}
});
document.addEventListener('DOMContentLoaded', function() {
if (isButtonInViewport()) {
clickLoadMoreButton();
}
});
</script>
原理:当滚动到出现“加载更多”按钮时,自动点击“加载更多”按钮。
emmm…然后我优化了一下
<script>
function simulateButtonClick() {
const button = document.querySelector('.DiscussionList-loadMore .Button');
if (button) {
button.click();
}
}
function isButtonInViewport() {
const button = document.querySelector('.DiscussionList-loadMore .Button');
if (!button) return false;
const rect = button.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight)
);
}
function checkButtonInView() {
if (isButtonInViewport()) {
simulateButtonClick();
}
}
setInterval(checkButtonInView, 100);
if (isButtonInViewport()) {
simulateButtonClick();
}
</script>