* @description 读新闻或者看视频 * @param type :0为新闻,1为视频
(type)
| 4023 | * @param type :0为新闻,1为视频 |
| 4024 | */ |
| 4025 | async function reading(type) { |
| 4026 | let time = 30; |
| 4027 | // 文章选读 |
| 4028 | if (type === 0) { |
| 4029 | // 章节 |
| 4030 | const sections = $$('section'); |
| 4031 | // 最大字数 |
| 4032 | const maxTextCount = Math.max(...sections.map((s) => s.innerText.length), 200); |
| 4033 | // 预计时间 |
| 4034 | const predictTime = ~~((60 * maxTextCount) / 1000); |
| 4035 | // min(predictTime, maxWatch.value) 秒后关闭页面 |
| 4036 | time = Math.min(predictTime, maxRead.value); |
| 4037 | } |
| 4038 | // 视听学习 |
| 4039 | if (type === 1) { |
| 4040 | // 视频 |
| 4041 | const video = $$('video')[0]; |
| 4042 | // 预计时间 |
| 4043 | const predictTime = ~~video.duration; |
| 4044 | // min(predictTime, maxWatch.value) 秒后关闭页面 |
| 4045 | time = Math.min(predictTime, maxWatch.value); |
| 4046 | } |
| 4047 | // 随机 |
| 4048 | time = time - ~~(Math.random() * 10) + 5; |
| 4049 | // 第一次滚动时间 |
| 4050 | const firstTime = time - (~~(Math.random() * 4) + 4); |
| 4051 | // 第二次滚动时间 |
| 4052 | const secendTime = ~~(Math.random() * 4) + 8; |
| 4053 | // 窗口 |
| 4054 | const window = unsafeWindow; |
| 4055 | // 创建提示 |
| 4056 | const tip = createTip('距离关闭页面还剩', time, true, async (time) => { |
| 4057 | // 暂停锁 |
| 4058 | await studyPauseLock((flag) => { |
| 4059 | if (type === 1) { |
| 4060 | // 视频 |
| 4061 | const video = $$('video')[0]; |
| 4062 | // 排除反复设置 |
| 4063 | if (video.paused === !flag) { |
| 4064 | return; |
| 4065 | } |
| 4066 | // 设置播放状态 |
| 4067 | video[flag ? 'play' : 'pause'](); |
| 4068 | } |
| 4069 | }); |
| 4070 | // 第一次滚动 |
| 4071 | if (time === firstTime) { |
| 4072 | // 滚动 |
| 4073 | window.scrollTo(0, 400); |
| 4074 | // 模拟滚动 |
| 4075 | const scroll = new Event('scroll', { |
| 4076 | bubbles: true, |
| 4077 | }); |
| 4078 | document.dispatchEvent(scroll); |
| 4079 | // 模拟滑动 |
| 4080 | const mousemove = new MouseEvent('mousemove', { |
| 4081 | bubbles: true, |
| 4082 | }); |
no test coverage detected