LeetCodeRating|English

LeetCodeRating The score of the weekly competition is displayed, and currently supports the tag page, question bank page, problem_list page and question page

当前为 2023-01-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name LeetCodeRating|English
  3. // @namespace https://github.com/zhang-wangz
  4. // @version 1.1.2
  5. // @license MIT
  6. // @description LeetCodeRating The score of the weekly competition is displayed, and currently supports the tag page, question bank page, problem_list page and question page
  7. // @author 小东是个阳光蛋(Leetcode Nickname of chinese site
  8. // @leetcodehomepage https://leetcode.cn/u/runonline/
  9. // @homepageURL https://github.com/zhang-wangz/LeetCodeRating
  10. // @contributionURL https://www.showdoc.com.cn/2069209189620830
  11. // @match *://*leetcode.com/*
  12. // @grant GM_xmlhttpRequest
  13. // @grant GM_setValue
  14. // @grant GM_getValue
  15. // @grant GM_addStyle
  16. // @grant GM_getResourceText
  17. // @connect zerotrac.github.io
  18. // @connect raw.staticdn.net
  19. // @connect raw.githubusercontents.com
  20. // @connect raw.githubusercontent.com
  21. // @require https://gcore.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js
  22. // @require https://gcore.jsdelivr.net/gh/andywang425/BLTH@4368883c643af57c07117e43785cd28adcb0cb3e/assets/js/library/layer.min.js
  23. // @resource css https://gcore.jsdelivr.net/gh/andywang425/BLTH@d25aa353c8c5b2d73d2217b1b43433a80100c61e/assets/css/layer.css
  24. // @grant unsafeWindow
  25. // @run-at document-end
  26. // @note 2022-12-29 1.1.0 add english site support
  27. // @note 2022-12-29 1.1.1 fix when the dark mode is turned on, the prompt display is abnormal
  28. // @note 2023-01-05 1.1.2 modify the cdn access address
  29. // ==/UserScript==
  30.  
  31. (function () {
  32. 'use strict';
  33. let t2rate = {}
  34. let latestpb = {}
  35. let id1 = ""
  36. let id2 = ""
  37. let id3 = ""
  38. let id4 = ""
  39. let id5 = ""
  40. let id6 = ""
  41. let version = "1.1.2"
  42. let preDate
  43. let allUrl = "https://leetcode.com/problemset"
  44. let tagUrl = "https://leetcode.com/tag"
  45. let pblistUrl = "https://leetcode.com/problem-list"
  46. let pbUrl = "https://leetcode.com/problems"
  47. GM_addStyle(GM_getResourceText("css"));
  48.  
  49. // 深拷贝
  50. function deepclone(obj) {
  51. let str = JSON.stringify(obj);
  52. return JSON.parse(str);
  53. }
  54.  
  55. // 获取数字
  56. function getcontestNumber(url) {
  57. return parseInt(url.substr(15));
  58. }
  59.  
  60. // 获取时间
  61. function getCurrentDate(format) {
  62. let now = new Date();
  63. let year = now.getFullYear(); //得到年份
  64. let month = now.getMonth(); //得到月份
  65. let date = now.getDate(); //得到日期
  66. let hour = now.getHours(); //得到小时
  67. let minu = now.getMinutes(); //得到分钟
  68. let sec = now.getSeconds(); //得到秒
  69. month = month + 1;
  70. if (month < 10) month = "0" + month;
  71. if (date < 10) date = "0" + date;
  72. if (hour < 10) hour = "0" + hour;
  73. if (minu < 10) minu = "0" + minu;
  74. if (sec < 10) sec = "0" + sec;
  75. let time = "";
  76. // 精确到天
  77. if (format == 1) {
  78. time = year + "年" + month + "月" + date + "日";
  79. }
  80. // 精确到分
  81. else if (format == 2) {
  82. time = year + "-" + month + "-" + date + " " + hour + ":" + minu + ":" + sec;
  83. }
  84. return time;
  85. }
  86.  
  87.  
  88.  
  89. let t // all and tag
  90. let t1, le // pb
  91. function getData() {
  92. try {
  93. let arr = document.querySelector("#__next > div > div > div.grid.grid-cols-4.gap-4.md\\:grid-cols-3.lg\\:grid-cols-4.lg\\:gap-6 > div.col-span-4.z-base.md\\:col-span-2.lg\\:col-span-3 > div:nth-child(7) > div.-mx-4.md\\:mx-0 > div > div > div:nth-child(2)")
  94. // pb页面加载时直接返回
  95. if (arr == undefined) {
  96. return
  97. }
  98.  
  99. // 防止过多的无效操作
  100. if (t != undefined && t == arr.lastChild.innerHTML) {
  101. return
  102. }
  103.  
  104. let childs = arr.childNodes
  105. for (let idx = 0; idx < childs.length; idx++) {
  106. let v = childs[idx]
  107. let length = v.childNodes.length
  108. let t = v.childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].innerText
  109. let data = t.split(".")
  110. let id = data[0].trim()
  111. let nd = v.childNodes[length - 2].childNodes[0].innerHTML
  112. if (t2rate[id] != undefined) {
  113. nd = t2rate[id]["Rating"]
  114. v.childNodes[length - 2].childNodes[0].innerHTML = nd
  115. } else {
  116. let nd2ch = { "text-olive dark:text-dark-olive": "Easy", "text-yellow dark:text-dark-yellow": "Medium", "text-pink dark:text-dark-pink": "Hard" }
  117. let cls = v.childNodes[length - 2].childNodes[0].getAttribute("class")
  118. v.childNodes[length - 2].childNodes[0].innerHTML = nd2ch[cls]
  119. }
  120. }
  121. t = deepclone(arr.lastChild.innerHTML)
  122. } catch (e) {
  123. return
  124. }
  125. }
  126.  
  127. function getTagData() {
  128. if (!window.location.href.startsWith(tagUrl)) {
  129. clearInterval(id2)
  130. id3 = setInterval(getpb, 1)
  131. GM_setValue("pb", id3)
  132. return
  133. }
  134. try {
  135. let arr = document.querySelector("#app > div > div.ant-row.content__xk8m > div > div > div > table > tbody")
  136. if (t != undefined && t == arr.lastChild.innerHTML) {
  137. return
  138. }
  139. let childs = arr.childNodes
  140. for (const element of childs) {
  141. let v = element
  142. let length = v.childNodes.length
  143. let idText = v.childNodes[1].innerText
  144. let id = idText.trim()
  145. let nd = v.childNodes[length - 2].childNodes[0].innerHTML
  146. if (t2rate[id] != undefined) {
  147. nd = t2rate[id]["Rating"]
  148. v.childNodes[length - 2].childNodes[0].innerHTML = nd
  149. } else {
  150. let nd2ch = { "label label-success round": "Easy", "label label-warning round": "Medium", "label label-danger round": "Hard" }
  151. let clr = v.childNodes[length - 2].childNodes[0].getAttribute("class")
  152. v.childNodes[length - 2].childNodes[0].innerHTML = nd2ch[clr]
  153. }
  154. }
  155. t = deepclone(arr.lastChild.innerHTML)
  156. } catch (e) {
  157. return
  158. }
  159. }
  160.  
  161.  
  162. function getPblistData() {
  163. if (!window.location.href.startsWith(pblistUrl)) {
  164. clearInterval(id5)
  165. id3 = setInterval(getpb, 1)
  166. GM_setValue("pb", id3)
  167. return
  168. }
  169. try {
  170. let arr = document.querySelector("#__next > div > div.mx-auto.mt-\\[50px\\].w-full.grow.p-4.md\\:mt-0.md\\:max-w-\\[888px\\].md\\:p-6.lg\\:max-w-screen-xl.bg-overlay-1.dark\\:bg-dark-overlay-1.md\\:bg-paper.md\\:dark\\:bg-dark-paper > div > div.col-span-4.md\\:col-span-2.lg\\:col-span-3 > div:nth-child(2) > div.-mx-4.md\\:mx-0 > div > div > div:nth-child(2)")
  171. if (t != undefined && t == arr.lastChild.innerHTML) {
  172. return
  173. }
  174. let childs = arr.childNodes
  175. for (const element of childs) {
  176. let v = element
  177. let length = v.childNodes.length
  178. let t = v.childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].innerText
  179. let data = t.split(".")
  180. let id = data[0].trim()
  181. let nd = v.childNodes[length - 2].childNodes[0].innerHTML
  182.  
  183. if (t2rate[id] != undefined) {
  184. nd = t2rate[id]["Rating"]
  185. v.childNodes[length - 2].childNodes[0].innerHTML = nd
  186. } else {
  187. let nd2ch = { "text-olive dark:text-dark-olive": "Easy", "text-yellow dark:text-dark-yellow": "Medium", "text-pink dark:text-dark-pink": "Hard" }
  188. let cls = v.childNodes[length - 2].childNodes[0].getAttribute("class")
  189. v.childNodes[length - 2].childNodes[0].innerHTML = nd2ch[cls]
  190. }
  191. }
  192. t = deepclone(arr.lastChild.innerHTML)
  193. } catch (e) {
  194. return
  195. }
  196. }
  197.  
  198. function getpb() {
  199. if (!window.location.href.startsWith(pbUrl)) {
  200. clearInterval(id3)
  201. if (window.location.href.startsWith(allUrl)){
  202. id1 = setInterval(getData, 1)
  203. GM_setValue("all", id1)
  204. }else if (window.location.href.startsWith(tagUrl)) {
  205. id2 = setInterval(getTagData, 1)
  206. GM_setValue("tag", id2)
  207. } else if (window.location.href.startsWith(pblistUrl)) {
  208. id5 = setInterval(getPblistData, 1)
  209. GM_setValue("pblist", id5)
  210. }
  211. return
  212. }
  213.  
  214. try {
  215.  
  216. // 旧版的标题位置
  217. let t = document.querySelector("#app > div > div.main__2_tD > div.content__3fR6 > div > div.side-tools-wrapper__1TS9 > div > div.css-1gd46d6-Container.e5i1odf0 > div.css-jtoecv > div > div.tab-pane__ncJk.css-1eusa4c-TabContent.e5i1odf5 > div > div.css-101rr4k > div.css-v3d350")
  218. if (t == undefined){
  219. // 新版逻辑
  220. t = document.querySelector("#qd-content > div.h-full.flex-col.ssg__qd-splitter-primary-w > div > div > div > div.flex.h-full.w-full.overflow-y-auto > div > div > div.w-full.px-5.pt-4 > div > div:nth-child(1) > div.flex-1 > div > div > span")
  221. if (t == undefined) {
  222. t1 = "unknown"
  223. return
  224. }
  225. let data = t.innerText.split(".")
  226. let id = data[0].trim()
  227. let colorSpan = document.querySelector("#qd-content > div.h-full.flex-col.ssg__qd-splitter-primary-w > div > div > div > div.flex.h-full.w-full.overflow-y-auto > div > div > div.w-full.px-5.pt-4 > div > div.mt-3.flex.space-x-4 > div:nth-child(1) > div")
  228. let pa = colorSpan.parentNode.parentNode
  229. if (t1 != undefined && t1 == id) {
  230. return
  231. }
  232. // 新版统计难度分数并且修改
  233. let nd = colorSpan.getAttribute("class")
  234. let nd2ch = { "dark:text-dark-olive text-olive": "Easy", "dark:bg-dark-yellow text-yellow": "Medium", "dark:text-dark-pink text-pink": "Hard" }
  235. if (t2rate[id] != undefined) {
  236. colorSpan.innerHTML = t2rate[id]["Rating"]
  237. } else {
  238. for (let item in nd2ch) {
  239. if (nd.toString().includes(item)) {
  240. colorSpan.innerHTML = nd2ch[item]
  241. break
  242. }
  243. }
  244. }
  245. // 新版逻辑,准备做周赛链接,如果已经不存在组件就执行操作
  246. let url = "https://leetcode.com/contest/"
  247. let zhUrl = "https://leetcode.com/contest/"
  248. let q = pa.lastChild
  249. let le = pa.childNodes.length
  250. if (q.textContent == "") {
  251. let abody = document.createElement("a")
  252. abody.setAttribute("data-small-spacing", "true")
  253. abody.setAttribute("class", "css-nabodd-Button e167268t1")
  254.  
  255. let abody2 = document.createElement("a")
  256. abody2.setAttribute("data-small-spacing", "true")
  257. abody2.setAttribute("class", "css-nabodd-Button e167268t1")
  258.  
  259. let span = document.createElement("span")
  260. let span2 = document.createElement("span")
  261. // ContestID_en ContestSlug
  262. if (t2rate[id] != undefined) {
  263. let contestUrl;
  264. let num = getcontestNumber(t2rate[id]["ContestSlug"])
  265. if (num < 83) { contestUrl = zhUrl } else { contestUrl = url }
  266. span.innerText = t2rate[id]["ContestID_en"]
  267. span2.innerText = t2rate[id]["ProblemIndex"]
  268.  
  269. abody.setAttribute("href", contestUrl + t2rate[id]["ContestSlug"])
  270. abody.setAttribute("target", "_blank")
  271. abody.removeAttribute("hidden")
  272.  
  273. abody2.setAttribute("href", contestUrl + t2rate[id]["ContestSlug"] + "/problems/" + t2rate[id]["TitleSlug"])
  274. abody2.setAttribute("target", "_blank")
  275. abody2.removeAttribute("hidden")
  276. } else {
  277. span.innerText = "对应周赛未知"
  278. abody.setAttribute("href", "")
  279. abody.setAttribute("target", "_self")
  280. abody.setAttribute("hidden", "true")
  281.  
  282. span2.innerText = "未知"
  283. abody2.setAttribute("href", "")
  284. abody2.setAttribute("target", "_self")
  285. abody2.setAttribute("hidden", "true")
  286. }
  287. abody.appendChild(span)
  288. abody2.appendChild(span2)
  289. pa.appendChild(abody)
  290. pa.appendChild(abody2)
  291. } else if(q.textContent.charAt(0) == "Q" || q.textContent == "未知") { // 存在就直接替换
  292. if (t2rate[id] != undefined) {
  293. let contestUrl;
  294. let num = getcontestNumber(t2rate[id]["ContestSlug"])
  295. if (num < 83) { contestUrl = zhUrl } else { contestUrl = url }
  296. pa.childNodes[le - 2].childNodes[0].innerText = t2rate[id]["ContestID_en"]
  297. pa.childNodes[le - 2].setAttribute("href", contestUrl + t2rate[id]["ContestSlug"])
  298. pa.childNodes[le - 2].setAttribute("target", "_blank")
  299. pa.childNodes[le - 2].removeAttribute("hidden")
  300.  
  301. pa.childNodes[le - 1].childNodes[0].innerText = t2rate[id]["ProblemIndex"]
  302. pa.childNodes[le - 1].setAttribute("href", contestUrl + t2rate[id]["ContestSlug"] + "/problems/" + t2rate[id]["TitleSlug"])
  303. pa.childNodes[le - 1].setAttribute("target", "_blank")
  304. pa.childNodes[le - 1].removeAttribute("hidden")
  305. } else {
  306. pa.childNodes[le - 2].childNodes[0].innerText = "对应周赛未知"
  307. pa.childNodes[le - 2].setAttribute("href", "")
  308. pa.childNodes[le - 2].setAttribute("target", "_self")
  309. pa.childNodes[le - 2].setAttribute("hidden", "true")
  310.  
  311. pa.childNodes[le - 1].childNodes[0].innerText = "未知"
  312. pa.childNodes[le - 1].setAttribute("href", "")
  313. pa.childNodes[le - 1].setAttribute("target", "_self")
  314. pa.childNodes[le - 1].setAttribute("hidden", "true")
  315. }
  316. }
  317. t1 = deepclone(id)
  318.  
  319. }else {
  320. // 旧版逻辑,使用参数t和t1,分别代表标题的html和标题id
  321.  
  322. // 旧版题目左侧列表里面所有分数
  323. let pbAll = document.querySelector("body > div.question-picker-detail__2A9V.show__GfjG > div.question-picker-detail-menu__3NQq.show__3hiR > div.lc-theme-dark.question-picker-questions-wrapper__13qM > div")
  324. if (pbAll != undefined) {
  325. let childs = pbAll.childNodes
  326. for (const element of childs) {
  327. let v = element
  328. let length = v.childNodes.length
  329. let t = v.childNodes[0].childNodes[1].innerText
  330. let data = t.split(" ")[0]
  331. let id = data.slice(1)
  332. let nd = v.childNodes[length - 1].childNodes[0].innerText
  333. if (t2rate[id] != undefined) {
  334. nd = t2rate[id]["Rating"]
  335. v.childNodes[length - 1].childNodes[0].innerText = nd
  336. }
  337. }
  338. }
  339. // 旧版标题修改位置
  340. let data = t.innerText.split(".")
  341. let id = data[0].trim()
  342. let colorSpan = document.querySelector("#app > div > div.main__2_tD > div.content__3fR6 > div > div.side-tools-wrapper__1TS9 > div > div.css-1gd46d6-Container.e5i1odf0 > div.css-jtoecv > div > div.tab-pane__ncJk.css-1eusa4c-TabContent.e5i1odf5 > div > div.css-101rr4k > div.css-10o4wqw > div")
  343. let pa = colorSpan.parentNode
  344. if ((t1 != undefined && t1 == id) && (le != undefined && le <= pa.childNodes.length)) {
  345. return
  346. }
  347. // 统计难度分数
  348. let nd = colorSpan.getAttribute("diff")
  349. let nd2ch = { "easy": "Easy", "medium": "Medium", "hard": "Hard" }
  350. if (t2rate[id] != undefined) {
  351. colorSpan.innerHTML = t2rate[id]["Rating"]
  352. } else {
  353. colorSpan.innerHTML = nd2ch[nd]
  354. }
  355. // 准备做周赛链接,如果已经不存在组件就执行操作
  356. let url = "https://leetcode.com/contest/"
  357. let zhUrl = "https://leetcode.com/contest/"
  358. if (le == undefined || le != pa.childNodes.length) {
  359.  
  360. let button = document.createElement("button")
  361. button.setAttribute("class", "btn__r7r7 css-1rdgofi")
  362. let abody = document.createElement("a")
  363. abody.setAttribute("style", "color: #546E7A;")
  364.  
  365. let button2 = document.createElement("button")
  366. button2.setAttribute("class", "btn__r7r7 css-1rdgofi")
  367. let abody2 = document.createElement("a")
  368. abody2.setAttribute("style", "color: #546E7A;")
  369.  
  370. // ContestID_en ContestSlug
  371. if (t2rate[id] != undefined) {
  372. let contestUrl;
  373. let num = getcontestNumber(t2rate[id]["ContestSlug"])
  374. if (num < 83) { contestUrl = zhUrl } else { contestUrl = url }
  375. abody.innerText = t2rate[id]["ContestID_en"]
  376. abody2.innerText = t2rate[id]["ProblemIndex"]
  377.  
  378. abody.setAttribute("href", contestUrl + t2rate[id]["ContestSlug"])
  379. abody.setAttribute("target", "_blank")
  380. abody.removeAttribute("hidden")
  381.  
  382. abody2.setAttribute("href", contestUrl + t2rate[id]["ContestSlug"] + "/problems/" + t2rate[id]["TitleSlug"])
  383. abody2.setAttribute("target", "_blank")
  384. abody2.removeAttribute("hidden")
  385. } else {
  386. span.innerText = "对应周赛未知"
  387. abody.setAttribute("href", "")
  388. abody.setAttribute("target", "_self")
  389. abody.setAttribute("hidden", "true")
  390.  
  391. span2.innerText = "未知"
  392. abody2.setAttribute("href", "")
  393. abody2.setAttribute("target", "_self")
  394. abody2.setAttribute("hidden", "true")
  395. }
  396.  
  397. button.appendChild(abody)
  398. button2.appendChild(abody2)
  399. pa.appendChild(button)
  400. pa.appendChild(button2)
  401. } else if (le == pa.childNodes.length) { // 存在就直接替换
  402. if (t2rate[id] != undefined) {
  403. let contestUrl;
  404. let num = getcontestNumber(t2rate[id]["ContestSlug"])
  405. if (num < 83) { contestUrl = zhUrl } else { contestUrl = url }
  406. pa.childNodes[le - 2].childNodes[0].innerText = t2rate[id]["ContestID_en"]
  407. pa.childNodes[le - 2].setAttribute("href", contestUrl + t2rate[id]["ContestSlug"])
  408. pa.childNodes[le - 2].setAttribute("target", "_blank")
  409. pa.childNodes[le - 2].removeAttribute("hidden")
  410.  
  411. pa.childNodes[le - 1].childNodes[0].childNodes[0].innerText = t2rate[id]["ProblemIndex"]
  412. pa.childNodes[le - 1].childNodes[0].setAttribute("href", contestUrl + t2rate[id]["ContestSlug"] + "/problems/" + t2rate[id]["TitleSlug"])
  413. pa.childNodes[le - 1].childNodes[0].setAttribute("target", "_blank")
  414. pa.childNodes[le - 1].childNodes[0].removeAttribute("hidden")
  415. } else {
  416. pa.childNodes[le - 2].childNodes[0].innerText = "对应周赛未知"
  417. pa.childNodes[le - 2].setAttribute("href", "")
  418. pa.childNodes[le - 2].setAttribute("target", "_self")
  419. pa.childNodes[le - 2].setAttribute("hidden", "true")
  420.  
  421. pa.childNodes[le - 1].childNodes[0].childNodes[0].innerText = "未知"
  422. pa.childNodes[le - 1].childNodes[0].setAttribute("href", "")
  423. pa.childNodes[le - 1].childNodes[0].setAttribute("target", "_self")
  424. pa.childNodes[le - 1].childNodes[0].setAttribute("hidden", "true")
  425. }
  426. }
  427. le = pa.childNodes.length
  428. t1 = deepclone(id)
  429. }
  430. } catch (e) {
  431. return
  432. }
  433. }
  434.  
  435. t2rate = JSON.parse(GM_getValue("t2ratedb", "{}").toString())
  436. latestpb = JSON.parse(GM_getValue("latestpb", "{}").toString())
  437. preDate = GM_getValue("preDate", "")
  438. let now = getCurrentDate(1)
  439. if (t2rate["tagVersion"] == undefined || (preDate == "" || preDate != now)) {
  440. GM_xmlhttpRequest({
  441. method: "get",
  442. url: 'https://raw.githubusercontents.com/zerotrac/leetcode_problem_rating/main/data.json' + "?timeStamp=" + new Date().getTime(),
  443. headers: {
  444. "Content-Type": "application/x-www-form-urlencoded"
  445. },
  446. onload: function (res) {
  447. if (res.status === 200) {
  448. // 保留唯一标识
  449. t2rate = {}
  450. let dataStr = res.response
  451. let json = eval(dataStr)
  452. for (const element of json) {
  453. t2rate[element.ID] = element
  454. t2rate[element.ID]["Rating"] = Number.parseInt(Number.parseFloat(element["Rating"]) + 0.5)
  455. }
  456. t2rate["tagVersion"] = {}
  457. console.log("everyday getdate once...")
  458. preDate = now
  459. GM_setValue("preDate", preDate)
  460. GM_setValue("t2ratedb", JSON.stringify(t2rate))
  461. }
  462. },
  463. onerror: function (err) {
  464. console.log('error')
  465. console.log(err)
  466. }
  467. });
  468. }
  469. function clearAndStart(start, func, timeout) {
  470. let lst = ['all', 'tag', 'pb', 'company', 'pblist', 'search']
  471. lst.forEach(each => {
  472. if (each !== start) {
  473. let tmp = GM_getValue(each, -1)
  474. clearInterval(tmp)
  475. }
  476. })
  477. if (start !== "") {
  478. let cnt = lst.indexOf(start) + 1
  479. switch (cnt) {
  480. case 1:
  481. id1 = setInterval(func, timeout)
  482. GM_setValue(start, id1)
  483. break
  484. case 2:
  485. id2 = setInterval(func, timeout)
  486. GM_setValue(start, id2)
  487. break
  488. case 3:
  489. id3 = setInterval(func, timeout)
  490. GM_setValue(start, id3)
  491. break
  492. case 4:
  493. id4 = setInterval(func, timeout)
  494. GM_setValue(start, id4)
  495. break
  496. case 5:
  497. id5 = setInterval(func, timeout)
  498. GM_setValue(start, id5)
  499. break
  500. case 6:
  501. id6 = setInterval(func, timeout)
  502. GM_setValue(start, id6)
  503. break
  504. }
  505. }
  506. }
  507.  
  508. [...document.querySelectorAll('*')].forEach(item => {
  509. item.oncopy = function (e) {
  510. e.stopPropagation();
  511. }
  512. });
  513.  
  514. if (window.location.href.startsWith(allUrl)) {
  515. // 版本更新机制
  516. GM_xmlhttpRequest({
  517. method: "get",
  518. url: 'https://raw.githubusercontents.com/zhang-wangz/LeetCodeRating/english/version.json' + "?timeStamp=" + new Date().getTime(),
  519. headers: {
  520. "Content-Type": "application/x-www-form-urlencoded"
  521. },
  522. onload: function (res) {
  523. if (res.status === 200) {
  524. console.log("enter home page check version once...")
  525. let dataStr = res.response
  526. let json = JSON.parse(dataStr)
  527. let v = json["version"]
  528. let upcontent = json["content"]
  529. if (v != version) {
  530. layer.open({
  531. content: '<pre style="color:#000">Update notice: <br/>leetcodeRating difficulty plugin has a new version, please go to update ~ <br/>' + "update content: <br/>" + upcontent + "</pre>",
  532. yes: function (index, layer0) {
  533. let c = window.open("https://raw.githubusercontents.com/zhang-wangz/LeetCodeRating/english/leetcodeRating_greasyfork.user.js" + "?timeStamp=" + new Date().getTime())
  534. c.close()
  535. layer.close(index)
  536. }
  537. });
  538. } else {
  539. console.log("leetcodeRating难度分插件当前已经是最新版本~")
  540. }
  541. }
  542. },
  543. onerror: function (err) {
  544. console.log('error')
  545. console.log(err)
  546. }
  547. });
  548.  
  549. clearAndStart('all', getData, 1)
  550. } else if (window.location.href.startsWith(tagUrl)) {
  551. clearAndStart('tag', getTagData, 1)
  552. } else if (window.location.href.startsWith(pbUrl)) {
  553. clearAndStart('pb', getpb, 1)
  554. let id = setInterval(getData, 1)
  555. GM_setValue("all", id)
  556. } else if (window.location.href.startsWith(pblistUrl)) {
  557. clearAndStart('pblist', getPblistData, 1)
  558. } else {
  559. clearAndStart('', undefined, 1)
  560. }
  561. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址