| 60 | } |
| 61 | |
| 62 | class StudyVideoH5 implements ZHSProcessor { |
| 63 | remotePage: RemotePage | undefined = undefined; |
| 64 | async init() { |
| 65 | this.remotePage = await BackgroundProject.scripts.dev.methods.getRemotePlaywrightCurrentPage(); |
| 66 | // 检查是否为软件环境 |
| 67 | if (!this.remotePage) { |
| 68 | throw $playwright.showError(); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | getCourseName() { |
| 73 | return $el('.source-name')?.textContent || '无名称'; |
| 74 | } |
| 75 | |
| 76 | getChapterName(root: HTMLElement): string { |
| 77 | return root.querySelector('.catalogue_title')?.textContent || '未知章节'; |
| 78 | } |
| 79 | |
| 80 | getNext(opts: { next: boolean; restudy: boolean }) { |
| 81 | let videoItems = Array.from(document.querySelectorAll<HTMLElement>('.clearfix.video')); |
| 82 | // 如果不是复习模式,则排除掉已经完成的任务 |
| 83 | if (!opts.restudy) { |
| 84 | videoItems = videoItems.filter((el) => el.querySelector('.time_icofinish') === null); |
| 85 | } |
| 86 | |
| 87 | for (let i = 0; i < videoItems.length; i++) { |
| 88 | const item = videoItems[i]; |
| 89 | if (item.classList.contains('current_play')) { |
| 90 | return videoItems[i + (opts.next ? 1 : 0)]; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | return videoItems[0]; |
| 95 | } |
| 96 | |
| 97 | async switchPlaybackRate(rate: number) { |
| 98 | const controlsBar = $el('.controlsBar'); |
| 99 | const sl = $el('.speedList'); |
| 100 | if (controlsBar && sl) { |
| 101 | controlsBar.style.display = 'block'; |
| 102 | sl.style.display = 'block'; |
| 103 | /** |
| 104 | * 兼容 1.0 和 1 的两个属性值匹配 |
| 105 | */ |
| 106 | const rate_parsed = parseFloat(String(rate)); |
| 107 | const selector = `.speedList [rate="${rate_parsed === 1 ? '1.0' : rate}"],.speedList [rate="${ |
| 108 | rate_parsed === 1 ? '1' : rate |
| 109 | }"]`; |
| 110 | if (this.remotePage) { |
| 111 | await this.remotePage.click(selector); |
| 112 | } else { |
| 113 | document.querySelector<HTMLElement>(selector)?.click(); |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | async switchLine(definition: 'line1bq' | 'line1gq') { |
| 119 | const controlsBar = $el('.controlsBar'); |
nothing calls this directly
no outgoing calls
no test coverage detected