LeetCode Contest: Open at leetcode.cn

Add an "Open at LeetCode.cn" button on the LeetCode Contest page.

Verze ze dne 22. 08. 2022. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        LeetCode Contest: Open at leetcode.cn
// @namespace   JohnZhu04
// @match       https://leetcode.com/contest/*/problems/*
// @grant       none
// @version     1.0
// @author      JohnZhu04
// @license     MIT
// @supportURL  https://github.com/JohnZhu04/LeetScript/issues
// @icon        https://www.google.com/s2/favicons?sz=64&domain=leetcode.com
// @description Add an "Open at LeetCode.cn" button on the LeetCode Contest page.
// ==/UserScript==

const openCNURL = () => {
  const url = window.location.href.replace("leetcode.com", "leetcode.cn");
  window.open(url);
};

const main = () => {
  const whichDiv = ".question-title";
  const buttonClass = "btn btn-default panel-hover";
  const buttonText = "Open at LeetCode.cn";
  if (!document.querySelector(whichDiv)) {
    window.setTimeout(main, 2000);
  }
  const button = document.createElement("button");
  button.innerText = buttonText;
  button.addEventListener("click", openCNURL);
  button.className = buttonClass;
  document.querySelector(whichDiv).appendChild(button);
};

main();