1
0
Fork 0
UserScript/WebIDE/enhance.user.js

96 lines
3.1 KiB
JavaScript

// ==UserScript==
// @name WebIDE增强脚本
// @namespace http://ide.yumc.pw/
// @version 0.8.1
// @description Coding WebIDE 增强脚本
// @author MiaoWoo
// @include http*://ide.yumc.pw/ws/*
// @include http*://*.coding.net/ws/*
// @grant none
// @namespace yumc
// ==/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() }
}
}
document.onkeydown = function() {
var e = window.event;
if (!e.altKey || e.ctrlKey || e.shiftKey) { return; }
switch (e.keyCode) {
case 87:
// Alt + W 关闭Tab标签页
var activeTab = document.getElementsByClassName('tab-label active')[0];
if (activeTab) {
var nodes = activeTab.childNodes;
nodes[nodes.length - 1].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);
}
}
})();