Skip to content

Instantly share code, notes, and snippets.

@valorad
Last active January 17, 2023 14:06
Show Gist options
  • Save valorad/96bfd637d64b232ade019ef90e2f955c to your computer and use it in GitHub Desktop.
Save valorad/96bfd637d64b232ade019ef90e2f955c to your computer and use it in GitHub Desktop.
Woniu FR Auto load more. No need to scroll down and click that freaking button each time want to load more.
// update 20230117
// works on https://www.woniufr.vip/p/t_pc/course_pc_detail/video/xxx
// Important: Switch to "目录" tab before executing the following code.
const clickElementAndWait = (element, timeMS = 2000) => {
return new Promise((resolve, reject) => {
element.dispatchEvent(new MouseEvent('click'));
setTimeout(() => {
resolve();
}, timeMS);
});
};
const expand = async (targetCourseIndex = 0, times = 1) => {
const collapseItems = document.querySelectorAll("div.el-collapse-item");
const targetCourse = collapseItems[targetCourseIndex];
// Click the menu first for load button to appear
if (targetCourseIndex != 0) {
const itemToggler = targetCourse.querySelector("div.el-collapse-item__header");
if (!itemToggler) {
console.error(`WoniuFR-AEM: Cannot find the directory Toggler.`)
return;
}
await clickElementAndWait(itemToggler);
}
const loadMoreButton = targetCourse.querySelector(".load_text");
if (!loadMoreButton) {
console.error(`WoniuFR-AEM: Cannot find the load more button.`)
return;
}
for (let i = 0; i < times; i++) {
await clickElementAndWait(loadMoreButton);
}
};
expand(2, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment