mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2025-12-25 20:36:47 +08:00
refactor(XHS-Downloader.js): 重构用户脚本自动滚动页面功能
This commit is contained in:
parent
14d8ee3abe
commit
fc58bc84f3
@ -193,12 +193,14 @@ def api_demo():
|
||||
<ul>
|
||||
<li>下载小红书无水印作品文件时,脚本需要花费时间处理文件,请等待片刻,切勿多次点击下载按钮</li>
|
||||
<li>无水印图片文件为 PNG 格式;无水印视频文件较大,可能需要较长的时间处理,页面跳转可能会导致下载失败</li>
|
||||
<li>(已禁用)<del>提取账号发布、收藏、点赞、专辑作品链接时,脚本会尝试自动滚动屏幕直至加载全部作品,滚动检测间隔:2.5 秒</del></li>
|
||||
<li>(已禁用)<del>提取发现作品链接、搜索作品、用户链接时,脚本会自动滚动屏幕以尝试加载更多内容,滚动屏幕次数:10 次</del></li>
|
||||
<li>(已禁用)<del>可以修改滚动检测间隔、滚动屏幕次数,修改后立即生效;亦可关闭自动滚动屏幕功能,手动滚动屏幕加载内容</del></li>
|
||||
<li>提取账号发布、收藏、点赞、专辑作品链接时,脚本可以自动滚动页面直至加载全部作品,默认滚动检测间隔:2.5 秒</li>
|
||||
<li>提取发现作品链接、搜索作品、用户链接时,脚本可以自动滚动页面加载更多内容,默认滚动页面次数:10 次</li>
|
||||
<li>自动滚动页面功能默认关闭;用户可以自由开启,并修改滚动检测间隔、滚动页面次数,修改后立即生效</li>
|
||||
<li>如果未开启自动滚动页面功能,用户需要手动滚动页面以便加载更多内容后再进行其他操作</li>
|
||||
<li>使用全局代理工具可能会导致脚本下载文件失败,如有异常,请尝试关闭代理工具,必要时向作者反馈</li>
|
||||
<li>XHS-Downloader 用户脚本仅实现可见即可得的数据采集功能,无任何收费功能和破解功能</li>
|
||||
</ul>
|
||||
<p><strong>自动滚动页面功能代码已重构,该功能默认关闭!启用该功能可能会被小红书检测为自动化操作,从而导致账号受到风控或封禁风险!</strong></p>
|
||||
<h1>💻 二次开发</h1>
|
||||
<p>如果有其他需求,可以根据 <code>main.py</code> 的注释提示进行代码调用或修改!</p>
|
||||
<pre>
|
||||
|
||||
16
README_EN.md
16
README_EN.md
@ -195,14 +195,16 @@ def api_demo():
|
||||
<p>Note: Using the XHS-Downloader user script to batch extract content links, in combination with the XHS-Downloader program, can achieve batch downloading of watermark-free content files!</p>
|
||||
<h2>📜 Script Instructions</h2>
|
||||
<ul>
|
||||
<li>When downloading watermark-free Xiaohongshu作品 files, the script will take some time to process the files, please wait a moment and do not click the download button multiple times</li>
|
||||
<li>Watermark-free image files are in PNG format; watermark-free video files are larger and may take longer to process, page jumps may cause download failures</li>
|
||||
<li>(Disabled)<del>When extracting links of account posts, favorites, likes, and album作品, the script will attempt to automatically scroll the screen until all作品 are loaded, with a scroll detection interval of 2.5 seconds</del></li>
|
||||
<li>(Disabled)<del>When extracting discovery作品 links, search作品, and user links, the script will automatically scroll the screen to try to load more content, scrolling the screen up to 10 times</del></li>
|
||||
<li>(Disabled)<del>You can modify the scroll detection interval and the number of screen scrolls, changes will take effect immediately; you can also disable the automatic screen scrolling function and manually scroll to load content</del></li>
|
||||
<li>Using global proxy tools may cause the script to fail to download files, if there are issues, please try closing the proxy tool, and feedback to the author if necessary</li>
|
||||
<li>The XHS-Downloader user script only implements the data collection function that can be obtained visibly, with no paid features or cracking functions</li>
|
||||
<li>When downloading watermark-free works from Xiaohongshu, the script requires time to process the files. Please wait for a moment and do not click the download button multiple times.</li>
|
||||
<li>Watermark-free image files are in PNG format; watermark-free video files are larger and may take longer to process. Page redirects may cause download failures.</li>
|
||||
<li>When extracting links for posts, collects, likes, and board from an account, the script can automatically scroll the page until all works are loaded. The default scroll detection interval is 2.5 seconds.</li>
|
||||
<li>When extracting links to explore works, searching for works, and user links, the script can automatically scroll the page to load more content. The default number of page scrolls is 10.</li>
|
||||
<li>The automatic page scroll feature is turned off by default. Users can enable it and modify the scroll detection interval and the number of scrolls, with changes taking effect immediately.</li>
|
||||
<li>If the automatic page scroll feature is not enabled, users need to manually scroll the page to load more content before performing other actions.</li>
|
||||
<li>Using global proxy tools may cause script download failures. If there are issues, please try disabling the proxy tool. If necessary, contact the author for feedback.</li>
|
||||
<li>XHS-Downloader userscript only implements the data collection functionality for visible content and does not include any paid or cracked features.</li>
|
||||
</ul>
|
||||
<p><strong>The automatic page scroll feature has been refactored and is turned off by default! Enabling this feature may be detected as automated behavior by Xiaohongshu, potentially resulting in account risk control or banning.</strong></p>
|
||||
<h1>💻 Secondary Development</h1>
|
||||
<p>If you have other needs, you can perform code calls or modifications based on the comments in <code>main.py</code>!</p>
|
||||
<pre>
|
||||
|
||||
File diff suppressed because one or more lines are too long
101
static/自动滚动页面.js
Normal file
101
static/自动滚动页面.js
Normal file
@ -0,0 +1,101 @@
|
||||
// ==UserScript==
|
||||
// @name 自动滚动页面
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 0.1
|
||||
// @description 模拟自然滚动,测试页面滚动效果
|
||||
// @author ChatGPT, JoeanAmier
|
||||
// @match *://*/* // 匹配所有页面,也可以指定具体网站
|
||||
// @grant none
|
||||
// @run-at document-end // 在页面加载完毕后运行脚本
|
||||
// ==/UserScript==
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
// 配置滚动模式
|
||||
const scrollMode = 'limited'; // 'none'、'endless' 或 'limited'
|
||||
const maxScrollCount = 10; // 最大滚动次数(如果模式是 'limited')
|
||||
|
||||
// 随机整数生成函数
|
||||
const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
|
||||
// 判断是否需要暂停,模拟用户的停顿行为
|
||||
const shouldPause = () => Math.random() < 0.2; // 20%几率停顿
|
||||
|
||||
// 执行一次增量滚动
|
||||
const scrollOnce = () => {
|
||||
const scrollDistanceMin = 50; // 最小滚动距离
|
||||
const scrollDistanceMax = 200; // 最大滚动距离
|
||||
const scrollDistance = getRandomInt(scrollDistanceMin, scrollDistanceMax);
|
||||
console.log(`滚动距离: ${scrollDistance}px`); // 日志输出滚动距离
|
||||
window.scrollBy(0, scrollDistance); // 增量滚动
|
||||
};
|
||||
|
||||
// 检查是否已经滚动到底部
|
||||
const isAtBottom = () => {
|
||||
const docHeight = document.documentElement.scrollHeight;
|
||||
const winHeight = window.innerHeight;
|
||||
const scrollPos = window.scrollY;
|
||||
|
||||
return (docHeight - winHeight - scrollPos <= 10); // 如果距离底部小于10px,认为滚动到底部
|
||||
};
|
||||
|
||||
// 自动滚动主函数
|
||||
const scrollScreen = (callback, scrollCount = 0,) => {
|
||||
const timeoutMin = 100; // 最小滚动间隔
|
||||
const timeoutMax = 300; // 最大滚动间隔
|
||||
|
||||
console.log('开始滚动...');
|
||||
|
||||
const scrollInterval = setInterval(() => {
|
||||
if (shouldPause()) {
|
||||
// 停顿,模拟用户的休息
|
||||
clearInterval(scrollInterval);
|
||||
setTimeout(() => {
|
||||
scrollScreen(callback, scrollCount,); // 重新启动滚动
|
||||
}, getRandomInt(500, 1500)); // 随机停顿时间
|
||||
} else if (scrollMode === 'endless') {
|
||||
// 无限滚动至底部模式
|
||||
if (!isAtBottom()) {
|
||||
scrollOnce(); // 执行一次滚动
|
||||
} else {
|
||||
// 到达底部,停止滚动
|
||||
clearInterval(scrollInterval);
|
||||
callback(); // 调用回调函数
|
||||
console.log('已经到达页面底部,停止滚动');
|
||||
}
|
||||
} else if (scrollMode === 'limited') {
|
||||
// 滚动指定次数模式
|
||||
if (scrollCount < maxScrollCount && !isAtBottom()) {
|
||||
scrollOnce(); // 执行一次滚动
|
||||
scrollCount++;
|
||||
} else {
|
||||
// 如果到达底部或滚动次数已满,停止滚动
|
||||
clearInterval(scrollInterval);
|
||||
callback(); // 调用回调函数
|
||||
console.log(`已经滚动${scrollCount}次,停止滚动`);
|
||||
}
|
||||
} else if (scrollMode === 'none') {
|
||||
// 关闭滚动功能
|
||||
clearInterval(scrollInterval);
|
||||
console.log('自动滚动已关闭');
|
||||
}
|
||||
}, getRandomInt(timeoutMin, timeoutMax)); // 随机滚动间隔
|
||||
};
|
||||
|
||||
// 等待页面完全加载后执行滚动
|
||||
window.addEventListener('load', () => {
|
||||
console.log('页面加载完成');
|
||||
|
||||
// 检查页面是否足够长,以便滚动
|
||||
if (document.body.scrollHeight > window.innerHeight && scrollMode !== 'none') {
|
||||
// 执行自动滚动
|
||||
scrollScreen(() => {
|
||||
console.log('滚动完成');
|
||||
});
|
||||
} else {
|
||||
console.log('页面没有足够的内容进行滚动,或者自动滚动已关闭');
|
||||
}
|
||||
});
|
||||
|
||||
})();
|
||||
Loading…
x
Reference in New Issue
Block a user