UserScript/WebIDE/enhance.user.js

95 lines
3.0 KiB
JavaScript
Raw Normal View History

2018-05-15 09:21:03 +00:00
// ==UserScript==
// @name WebIDE增强脚本
// @namespace http://ide.yumc.pw/
2018-05-15 11:11:55 +00:00
// @version 0.7
2018-05-15 09:21:03 +00:00
// @description Coding WebIDE 增强脚本
// @author MiaoWoo
// @match http*://ide.yumc.pw/ws/*
2018-05-15 11:11:55 +00:00
// @match http*://*.coding.net/ws/*
2018-05-15 09:21:03 +00:00
// @grant none
// ==/UserScript==
(function() {
'use strict';
2018-05-15 09:34:39 +00:00
var id = setInterval(function (){
if (document.getElementsByClassName('ide-container')[0]) {
2018-05-15 09:54:42 +00:00
window.onbeforeunload = function () { return false; }
2018-05-15 09:34:39 +00:00
console.log('已阻止 Ctrl + W 关闭页面...')
clearInterval(id);
}
}, 300)
2018-05-15 10:36:50 +00:00
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);
}
}
2018-05-15 09:52:24 +00:00
document.onkeydown = function() {
2018-05-15 09:49:59 +00:00
var e = window.event;
2018-05-15 10:36:50 +00:00
switch (e.keyCode) {
case 87:
// Alt + W 关闭Tab标签页
var activeTab = document.getElementsByClassName('tab-label active')[0];
2018-05-15 11:11:55 +00:00
if (activeTab && activeTab.childNodes[2]) {
2018-05-15 10:36:50 +00:00
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];
2018-05-15 10:08:39 +00:00
}
2018-05-15 10:36:50 +00:00
if (tab) {
tab.click();
2018-05-15 10:08:39 +00:00
}
2018-05-15 10:36:50 +00:00
}
break;
default:
findAndClick(e.keyCode);
2018-05-15 09:21:03 +00:00
}
}
})();