Skip to content

Commit 2363206

Browse files
committed
fix: 修复其他页面中关于是否新版 UI 的判断
比如像竞赛页面中没有 `#__next` 以及 `#app` 这两个元素, 会导致运行错误。
1 parent a7ab4e9 commit 2363206

1 file changed

Lines changed: 34 additions & 5 deletions

File tree

src/content/utils/utils.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,44 @@ export function getExtensionId(): string | undefined {
175175
*
176176
*/
177177
export const isBetaUI: () => Promise<boolean> = (() => {
178-
let beta: boolean | null = null
178+
let beta: boolean | null = null,
179+
promise: Promise<HTMLElement> | null = null
179180
return async function isBetaUI() {
180181
if (beta !== null) return beta
182+
if (!promise) {
183+
promise = Promise.race([
184+
findElement('#__next'), // 新版 UI
185+
findElement('#app'), // 旧版 UI
186+
findElement('body.pc-body'), // 祖传 UI
187+
])
188+
}
181189

182-
const root = await Promise.race([
183-
findElement('#__next'),
184-
findElement('#app'),
185-
])
190+
const root = await promise
186191
beta = root.id === '__next'
187192
return beta
188193
}
189194
})()
195+
196+
export interface ProblemRankData {
197+
Rating: number
198+
ID: number // questionFrontendId
199+
Title: string
200+
TitleZH: string
201+
TitleSlug: string
202+
ContestSlug: string
203+
ProblemIndex: string
204+
ContestID_en: string
205+
ContestID_zh: string
206+
}
207+
208+
export const getProblemRankData = async (): Promise<ProblemRankData[]> => {
209+
const data = await Promise.race([
210+
fetch(
211+
'https://cdn.jsdelivr.net/gh/zerotrac/leetcode_problem_rating/data.json'
212+
).then(res => res.json()),
213+
fetch(
214+
'https://raw.githubusercontent.com/zerotrac/leetcode_problem_rating/main/data.json'
215+
).then(res => res.json()),
216+
])
217+
return data
218+
}

0 commit comments

Comments
 (0)