@@ -175,15 +175,44 @@ export function getExtensionId(): string | undefined {
175175 *
176176 */
177177export 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