|
1 | 1 | import { render, unmountComponentAtNode } from 'react-dom' |
2 | 2 |
|
3 | | -import { |
4 | | - autoMount, |
5 | | - awaitFn, |
6 | | - findElementByXPath, |
7 | | - pageIsLoad, |
8 | | - sleep, |
9 | | -} from '@/utils' |
| 3 | +import { autoMount, findElementByXPath, sleep } from '@/utils' |
10 | 4 |
|
11 | 5 | import App from './App' |
12 | 6 | import { fixRandom, removeFixRandom } from './fixRandom' |
13 | 7 | import RankApp from '../problemset/App' |
14 | 8 |
|
15 | 9 | let _root: HTMLDivElement | null = null, |
16 | 10 | rankTitle: HTMLDivElement | null = null |
17 | | - |
| 11 | +const xpath = |
| 12 | + '//*[@id="__next"]/div/div[2]/div/div[2]/div/*//span[text()="精选题单"]/../..' |
18 | 13 | function getListEl() { |
19 | | - return findElementByXPath( |
20 | | - '//*[@id="__next"]/*//span[text()="精选题单"]/../..' |
21 | | - ) |
| 14 | + return findElementByXPath(xpath) |
22 | 15 | } |
23 | 16 |
|
24 | 17 | const [mountProblemList, unmountProblemList] = autoMount( |
25 | | - '//*[@id="__next"]/*//span[text()="精选题单"]/../..', |
| 18 | + xpath, |
26 | 19 | async () => { |
27 | 20 | const el = await getListEl() |
| 21 | + if (!isProblemList()) return |
28 | 22 | if (_root) { |
29 | 23 | if (_root?.nextElementSibling === el) return |
30 | 24 | // 可能因为加载比较慢之类的原因,导致自定义题单的侧边栏已经加载而其他的一些元素还没加载, |
@@ -97,10 +91,10 @@ window.addEventListener('urlchange', async function () { |
97 | 91 | await getListEl() |
98 | 92 | await Promise.race([ |
99 | 93 | sleep(500), |
100 | | - findElementByXPath('//span[text()="分享"]'), |
| 94 | + findElementByXPath( |
| 95 | + '//*[@id="__next"]/div/div[2]/div/div[2]/div/*//span[text()="分享"]' |
| 96 | + ), |
101 | 97 | ]) |
102 | | - // 等待跳转到题单页,通过判断「导航栏的题单按钮是否取消高亮」 |
103 | | - await awaitFn(async () => !(await pageIsLoad('题库'))) |
104 | 98 | mount() |
105 | 99 | fixRandom() |
106 | 100 | } else { |
|
0 commit comments