// ==UserScript== // @name LeetCode - Bring back Submit Code shortcut (Ctrl/Cmd + Enter) // @name:zh-CN LeetCode - 加回提交代码快捷键(Ctrl/Cmd + Enter) // @name:zh-HK LeetCode - 加回提交代碼快捷鍵(Ctrl/Cmd + Enter) // @name:zh-TW LeetCode - 加回提交代碼快捷鍵(Ctrl/Cmd + Enter) // @description See: https://leetcode.com/discuss/general-discussion/136588/Is-there-any-keyboard-shortcut-to-run-code-and-submit-solution/346347 // @description:zh-CN 参考:https://leetcode.com/discuss/general-discussion/136588/Is-there-any-keyboard-shortcut-to-run-code-and-submit-solution/346347 // @description:zh-HK 參考:https://leetcode.com/discuss/general-discussion/136588/Is-there-any-keyboard-shortcut-to-run-code-and-submit-solution/346347 // @description:zh-TW 參考:https://leetcode.com/discuss/general-discussion/136588/Is-there-any-keyboard-shortcut-to-run-code-and-submit-solution/346347 // @namespace RainSlide // @author RainSlide // @icon https://assets.leetcode.com/static_assets/public/icons/favicon-192x192.png // @version 1.0 // @match *://leetcode.com/problems/* // @grant none // @downloadURL https://update.greasyfork.icu/scripts/424233/LeetCode%20-%20Bring%20back%20Submit%20Code%20shortcut%20%28CtrlCmd%20%2B%20Enter%29.user.js // @updateURL https://update.greasyfork.icu/scripts/424233/LeetCode%20-%20Bring%20back%20Submit%20Code%20shortcut%20%28CtrlCmd%20%2B%20Enter%29.meta.js // ==/UserScript== "use strict"; const debug = msg => console.debug("[LeetCode - Submit Code shortcut] ".conact(msg)); const addShortcut = () => { const codeArea = document.querySelector('div[data-cy="code-area"]'); if (codeArea !== null) { // see: https://developer.mozilla.org/en-US/docs/Web/CSS/%3Ascope const selectInCodeArea = selector => codeArea.querySelector(':scope '.concat(selector)); const submitButton = selectInCodeArea('button[data-cy="submit-code-btn"]'); if (submitButton !== null) { // see: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent document.addEventListener( "keydown", event => { if ( event.key === "Enter" && ( event.ctrlKey === true || event.metaKey === true ) ) { event.preventDefault(); submitButton.click(); } } ); const shortcutsButton = selectInCodeArea('button[icon="information"]'); if (shortcutsButton !== null) { const addShortcutEntry = () => { // select div[class^="shortcut__"] which is: // in a Ant modal titled with "Editor Shortcuts" /* has div[class^="shortcut-description__"] and div[class^="shortcut-keystrokes__"] as 1st & 2nd child */ // see: https://devhints.io/xpath const result = new XPathEvaluator().createExpression( `//div[@class="ant-modal-content"][ ./div[@class="ant-modal-header"] //span[text()="Editor Shortcuts"] ]/div[@class="ant-modal-body"] //div[starts-with(@class,"shortcut__")][ ./div[1][starts-with(@class,"shortcut-description__")] and ./div[2][starts-with(@class,"shortcut-keystrokes__")] ]` // .replace(/\n\s+/g, "") ).evaluate( document.body, XPathResult.FIRST_ORDERED_NODE_TYPE ); /*