LeetCode Rating Helper

LeetCode.com - 显示题目 zerotrac rating,一键跳转国服

Verze ze dne 27. 01. 2023. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name LeetCode Rating Helper
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description LeetCode.com - 显示题目 zerotrac rating,一键跳转国服
  6. // @author github.com/Lance1o7
  7. // @icon https://www.google.com/s2/favicons?sz=64&domain=greatest.deepsurf.us
  8. // @grant none
  9. // @match *://leetcode.com/problems/*
  10. // @license The Unlicense
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. "use strict";
  15. let url = window.location.href;
  16. url = url.replace("leetcode.com", "leetcode.cn");
  17. url = url.replace("/description", "/solution");
  18. let assistant = document.createElement("a");
  19. assistant.href = url;
  20. assistant.target = "_blank";
  21. assistant.innerHTML =
  22. '<div class="flex flex-1 select-none justify-center whitespace-nowrap rounded-t-[5px] px-4 py-[10px] text-xs cursor-pointer text-label-2 dark:text-dark-label-2 px-5">Solutions (CN) ↗</div>';
  23. let elements = document.querySelector(
  24. "#qd-content > div.h-full.flex-col.ssg__qd-splitter-primary-w > div > div > div > div:nth-child(1) > div > div"
  25. );
  26. elements.appendChild(assistant);
  27. let a = url.split("/");
  28. let titleSlug = a[4];
  29. fetch("https://zerotrac.github.io/leetcode_problem_rating/data.json")
  30. .then((response) => response.json())
  31. .then((data) => {
  32. for (let i = 0; i < data.length; i++) {
  33. if (data[i].TitleSlug === titleSlug) {
  34. let rating = Math.round(data[i].Rating);
  35. let contestSlug = data[i].ContestSlug;
  36. let contestLink = "https://leetcode.com/contest/" + contestSlug;
  37. let contestID_en = data[i].ContestID_en;
  38. console.log(rating);
  39. let sel = document.querySelector(
  40. "#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"
  41. );
  42. let zerotrac = document.createElement("a");
  43. zerotrac.href = contestLink;
  44. zerotrac.target = "_blank";
  45. zerotrac.innerHTML =
  46. '<div class="flex flex-1 select-none justify-center whitespace-nowrap rounded-t-[5px] px-4 py-[10px] text-xs cursor-pointer text-label-2 dark:text-dark-label-2 px-5">' +
  47. " Rating: " +
  48. rating +
  49. " ↗</div>";
  50. elements.appendChild(zerotrac);
  51. }
  52. }
  53. });
  54. })();