LeetCode Problem Jumper

在 LeetCode 题目页面支持直接根据题号跳转到题目。Jump from one problem to another problem directly!

Verze ze dne 24. 10. 2024. Zobrazit nejnovější verzi.

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

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 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 Problem Jumper
// @namespace    https://github.com/ipdor/LeetCodeProblemJumper
// @version      1.0
// @description  在 LeetCode 题目页面支持直接根据题号跳转到题目。Jump from one problem to another problem directly!
// @author       ipdor
// @match        https://leetcode.com/problems/*
// @match        https://leetcode.cn/problems/*
// @grant        none
// @license      MIT 
// ==/UserScript==

(function(){"use strict";function getElementByXPath(xpath){const result=document.evaluate(xpath,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null);return result.singleNodeValue}function addJumpButton(){const targetDiv=getElementByXPath("/html/body/div[1]/div[2]/div/div/div[3]/nav/div/div/div[1]");if(targetDiv){if(!document.getElementById('problem_no')){const newDiv=document.createElement('div');newDiv.innerHTML='<input id="problem_no" type="text" placeholder="输入题号"><button id="jump_to_problem">跳转</button>';targetDiv.insertAdjacentElement('beforeend',newDiv);document.getElementById('jump_to_problem').addEventListener('click',function(){const problemNo=document.getElementById('problem_no').value.trim();if(problemNo&&!isNaN(problemNo)){window.location.href=`https://lcid.cc/${problemNo}`}else{alert('请输入有效的题号!')}})}}else{console.error('未找到指定的 XPath 位置。')}}const observer=new MutationObserver(function(mutations){mutations.forEach(function(mutation){if(mutation.addedNodes.length>0){addJumpButton()}})});observer.observe(document.body,{childList:true,subtree:true});addJumpButton()})();