MCPcopy Create free account
hub / github.com/Yantesoft/LinuxdoAssistant / scrollComment

Function scrollComment

linuxdo-helper.user.js:862–972  ·  view source on GitHub ↗

* 滚动评论区域并自动跳转 * @param {HTMLElement} commentElement - 评论容器元素

(commentElement)

Source from the content-addressed store, hash-verified

860 * @param {HTMLElement} commentElement - 评论容器元素
861 */
862 function scrollComment(commentElement) {
863 stopScrolling();
864
865 currentCommentElement = commentElement;
866
867 let linkWaitStartTime = null;
868 let currentRequiredWaitingTime = null;
869 let currentScrollCount = 0;
870 let currentMaxScrollCount = null;
871 const topicStartTime = Date.now();
872 const minimumReadTime = getTabValue(STORAGE_KEYS.currentTopicNeedsMinimumReadTime, false)
873 ? TOPIC_FIRST_CONFIG.newTopicMinimumReadTime
874 : 0;
875
876 if (minimumReadTime > 0) {
877 console.log(`新话题优先模式已开启,本帖至少阅读 ${minimumReadTime}ms`);
878 }
879
880 if (getTopicFirstMode()) {
881 currentMaxScrollCount = randomInt(
882 TOPIC_FIRST_CONFIG.minScrollCount,
883 TOPIC_FIRST_CONFIG.maxScrollCount
884 );
885
886 console.log(`话题优先模式已开启,本帖最多滚动 ${currentMaxScrollCount} 次`);
887 }
888
889 const doScroll = () => {
890 if (!getSwitchState()) {
891 stopScrolling();
892 return;
893 }
894
895 if (!currentCommentElement || currentCommentElement !== commentElement) {
896 return;
897 }
898
899 const currentConfig = getConfig();
900 const readTime = Date.now() - topicStartTime;
901 const hasReachedMinimumReadTime = readTime >= minimumReadTime;
902
903 if (getTopicFirstMode() && hasReachedMinimumReadTime && currentScrollCount >= currentMaxScrollCount) {
904 console.log(`话题优先模式达到滚动次数 ${currentScrollCount}/${currentMaxScrollCount},准备换下一个帖子`);
905 stopScrolling();
906 loadPage(getRawLinks());
907 return;
908 }
909
910 const randomStep = randomByJitter(
911 currentConfig.scrollStep,
912 RANDOM_DELAY_CONFIG.scrollStepJitter,
913 80
914 );
915
916 const scrollTarget = document.scrollingElement || commentElement;
917
918 scrollTarget.scrollTop += randomStep;
919 scrollTarget.dispatchEvent(new Event('scroll'));

Callers 2

restartScrollingFunction · 0.85
startAutoScrollFunction · 0.85

Calls 6

stopScrollingFunction · 0.85
getTabValueFunction · 0.85
getTopicFirstModeFunction · 0.85
randomIntFunction · 0.85
randomByJitterFunction · 0.85
getConfigFunction · 0.85

Tested by

no test coverage detected