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

96 lines
3.1 KiB
JavaScript
Raw Normal View History

2018-05-15 09:21:03 +00:00
// ==UserScript==
// @name WebIDE增强脚本
// @namespace http://ide.yumc.pw/
// @version 0.8.1
2018-05-15 09:21:03 +00:00
// @description Coding WebIDE 增强脚本
// @author MiaoWoo
2018-07-29 12:50:06 +00:00
// @include http*://ide.yumc.pw/ws/*
// @include http*://*.coding.net/ws/*
2018-05-15 09:21:03 +00:00
// @grant none
2018-07-29 12:50:06 +00:00
// @namespace yumc
2018-05-15 09:21:03 +00:00
// ==/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() }
}
}
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 13:46:01 +00:00
if (!e.altKey || e.ctrlKey || e.shiftKey) { return; }
2018-05-15 10:36:50 +00:00
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();
2018-05-15 10:36:50 +00:00
}
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
}
}
})();