LeetCode Contest: Open at leetcode.cn

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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();