95 lines
3.0 KiB
JavaScript
95 lines
3.0 KiB
JavaScript
// ==UserScript==
|
|
// @name WebIDE增强脚本
|
|
// @namespace http://ide.yumc.pw/
|
|
// @version 0.7
|
|
// @description Coding WebIDE 增强脚本
|
|
// @author MiaoWoo
|
|
// @match http*://ide.yumc.pw/ws/*
|
|
// @match http*://*.coding.net/ws/*
|
|
// @grant none
|
|
// ==/UserScript==
|
|
|
|
(function() {
|
|
'use strict';
|
|
var id = setInterval(function (){
|
|
if (document.getElementsByClassName('ide-container')[0]) {
|
|
window.onbeforeunload = function () { return false; }
|
|
console.log('已阻止 Ctrl + W 关闭页面...')
|
|
clearInterval(id);
|
|
}
|
|
}, 300)
|
|
var keyMapList = {
|
|
// Alt + ` 开关终端 (注意 光标在终端时 快捷键失效)
|
|
"192": {
|
|
type: 'normal',
|
|
class: "icon octicon octicon-terminal"
|
|
},
|
|
// Alt + U 拉取代码
|
|
"85": {
|
|
type: 'menu',
|
|
menu: 'menuBarItems.git.main',
|
|
class: "menu-item-icon octicon octicon-repo-pull"
|
|
},
|
|
// Alt + P 推送代码
|
|
"80": {
|
|
type: 'menu',
|
|
menu: 'menuBarItems.git.main',
|
|
class: "menu-item-icon octicon octicon-repo-push"
|
|
},
|
|
// Alt + C 项目网络
|
|
"67": {
|
|
type: 'normal',
|
|
class: "icon octicon octicon-git-commit"
|
|
},
|
|
// Alt + 1 工作树
|
|
"49": {
|
|
type: 'normal',
|
|
class: "icon octicon octicon-file-submodule"
|
|
},
|
|
// Alt + 2 工作文件
|
|
"50": {
|
|
type: 'normal',
|
|
class: "icon fa fa-folder-open-o"
|
|
}
|
|
};
|
|
function findAndClick(key) {
|
|
var keyMap = keyMapList[key];
|
|
if (keyMap) {
|
|
if (keyMap.type === "menu") { document.getElementById(keyMap.menu).click(); }
|
|
var item = document.getElementsByClassName(keyMap.class)[0];
|
|
if (item) { item.click() }
|
|
} else {
|
|
console.log(key);
|
|
}
|
|
}
|
|
document.onkeydown = function() {
|
|
var e = window.event;
|
|
switch (e.keyCode) {
|
|
case 87:
|
|
// Alt + W 关闭Tab标签页
|
|
var activeTab = document.getElementsByClassName('tab-label active')[0];
|
|
if (activeTab && activeTab.childNodes[2]) {
|
|
activeTab.childNodes[2].childNodes[0].click();
|
|
}
|
|
break;
|
|
case 81:
|
|
// Alt + Q 切换Tab标签页
|
|
var currectTab = document.getElementsByClassName('tab-label active')[0];
|
|
if (currectTab) {
|
|
var tab;
|
|
if (currectTab.nextElementSibling) {
|
|
tab = currectTab.nextElementSibling;
|
|
} else {
|
|
tab = document.getElementsByClassName('tab-label')[0];
|
|
}
|
|
if (tab) {
|
|
tab.click();
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
findAndClick(e.keyCode);
|
|
}
|
|
}
|
|
})();
|