// ==UserScript== // @name leetcode.cn中一键切换Vim模式 // @namespace https://leetcode.cn/ // @version 0.1 // @description leetcode.cn中的做题页面一键切换Vim模式 // @author pala // @match https://leetcode.cn/problems/* // @icon https://www.google.com/s2/favicons?sz=64&domain=leetcode.cn // @license GPL-3.0 // @downloadURL https://update.greasyfork.icu/scripts/459787/leetcodecn%E4%B8%AD%E4%B8%80%E9%94%AE%E5%88%87%E6%8D%A2Vim%E6%A8%A1%E5%BC%8F.user.js // @updateURL https://update.greasyfork.icu/scripts/459787/leetcodecn%E4%B8%AD%E4%B8%80%E9%94%AE%E5%88%87%E6%8D%A2Vim%E6%A8%A1%E5%BC%8F.meta.js // ==/UserScript== (function() { 'use strict'; var vim_div = document.createElement('div') vim_div.innerHTML = "" // 修改 css // https://blog.csdn.net/pangji0417/article/details/94029462 var style = document.createElement("style"); style.type = "text/css"; var text = document.createTextNode(".modal-container.css-sdt3ue-RootContainer.e117yaqi0{display: none;}"); var head = document.getElementsByTagName("head")[0]; head.appendChild(style); function trans() { style.appendChild(text) } function unTrans() { // https://blog.csdn.net/lilongsy/article/details/83039528 setTimeout(function(){ style.removeChild(text) }, 300) // 需要与防连击的时间间隙匹配 } // 不断尝试添加按钮 // https://tieba.baidu.com/p/4473101647 var myInterval = setInterval(function(){ if (document.getElementsByClassName('second-section-container__2cAh')[0] == null) { console.warn("vim-binding: 页面可能还未加载完成") return } // https://zhidao.baidu.com/question/1832390421308672020.html document.getElementsByClassName('second-section-container__2cAh')[0].appendChild(vim_div); // 防连击 https://www.jianshu.com/p/a0be7d2b4fd9 let last_click_time = new Date().getTime() let intervals = 500 document.getElementById('vim-button').onclick = function changeKeyBinding() { if (new Date().getTime() - last_click_time < intervals) { console.warn("vim-binding: 连击") return } trans() document.getElementsByClassName('tool-button__2YsS css-4n3zyb-transparent-sm-Btn e131m59q0')[4].click() document.getElementsByClassName('e19sweus0 css-1x1kwut-BaseButtonComponent-StyledButton ery7n2v0')[4].click() document.getElementsByClassName('css-1xmg8zz-hoverOverlayBg-OptionContainer e1c4ivjc0')[0].click() document.getElementsByClassName('eqff6b23 css-wfwmcl-BaseButtonComponent-CloseButton ery7n2v0')[0].click() unTrans() console.log("vim-binding: key binding changed") last_click_time = new Date().getTime() } console.info("vim-binding: 按钮添加成功") clearInterval(myInterval) }, 1000) })();