Skip to content

Commit

Permalink
fix: 修复智慧树倍速不能立刻改变的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed May 10, 2022
1 parent 3078385 commit 39d7402
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
19 changes: 14 additions & 5 deletions packages/core/src/components/zhs/StudySettingPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineComponent } from 'vue';
import { defineComponent, ref } from 'vue';
import { store } from '../../script';
import { autoClose } from '../../script/zhs/study';
import { autoClose, switchPlaybackRate } from '../../script/zhs/study';
import { Tooltip } from '../Tooltip';

export const StudySettingPanel = defineComponent({
Expand All @@ -10,6 +10,9 @@ export const StudySettingPanel = defineComponent({
closeDate.setMinutes(closeDate.getMinutes() + settings.watchTime * 60);
settings.closeDate = closeDate;

// 切换倍速防抖
const switching = ref(false);

return () => (
<div class="ocs-setting-panel">
<div class="ocs-setting-items">
Expand Down Expand Up @@ -55,8 +58,10 @@ export const StudySettingPanel = defineComponent({
<label>视频倍速 </label>
<div>
<Tooltip title="学分课不允许倍速!">
<input type="number"
value="1">
<input
type="number"
value="1"
>
</input>
</Tooltip>
</div>
Expand All @@ -70,8 +75,12 @@ export const StudySettingPanel = defineComponent({
max="1.5"
min="1"
value={settings.playbackRate}
onChange={(e: any) => {
disabled={switching.value}
onChange={async (e:any) => {
switching.value = true;
settings.playbackRate = e.target.valueAsNumber;
await switchPlaybackRate(settings.playbackRate);
switching.value = false;
}}></input>
</Tooltip>
</div>
Expand Down
22 changes: 15 additions & 7 deletions packages/core/src/script/zhs/study.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function study(setting?: ScriptSettings['zhs']['video']) {
* @returns
*/
export async function watch(setting?: Pick<ScriptSettings['zhs']['video'], 'playbackRate' | 'volume'>) {
const { volume = 0, playbackRate } = setting || {};
const { volume = 0, playbackRate = 1 } = setting || {};
return new Promise<void>((resolve, reject) => {
try {
const video = document.querySelector('video') as HTMLVideoElement;
Expand All @@ -82,12 +82,7 @@ export async function watch(setting?: Pick<ScriptSettings['zhs']['video'], 'play

video.play();

await sleep(1000);
const { btn, rate } = domSearch({ btn: '.speedBox', rate: `[rate="${playbackRate}"]` });
console.log({ btn, rate });
btn?.click();
await sleep(1000);
rate?.click();
await switchPlaybackRate(playbackRate);

video.onpause = function () {
if (!video.ended) {
Expand All @@ -112,6 +107,19 @@ export async function watch(setting?: Pick<ScriptSettings['zhs']['video'], 'play
});
}

/**
* 切换播放速度
* @param playbackRate 播放速度
*/
export async function switchPlaybackRate(playbackRate: number) {
await sleep(500);
const { btn } = domSearch({ btn: '.speedBox' });
btn?.click();
await sleep(500);
const { rate } = domSearch({ rate: `[rate="${playbackRate === 1 ? '1.0' : playbackRate}"]` });
rate?.click();
}

/**
* 关闭zhs共享课测验弹窗
*/
Expand Down

0 comments on commit 39d7402

Please sign in to comment.