[refactor] improve keyboard bind

This commit is contained in:
zombieFox 2019-07-15 20:03:13 +01:00
parent 5f7b83dd34
commit 41ee9dee86
4 changed files with 40 additions and 8 deletions

View File

@ -1,6 +1,8 @@
var keyboard = (function() { var keyboard = (function() {
var _bind = function() { var bind = {};
bind.esc = function() {
window.addEventListener("keydown", function(event) { window.addEventListener("keydown", function(event) {
// esc // esc
if (event.keyCode == 27) { if (event.keyCode == 27) {
@ -25,6 +27,11 @@ var keyboard = (function() {
}; };
data.save(); data.save();
}; };
}, false);
};
bind.ctrAltA = function() {
window.addEventListener("keydown", function(event) {
// ctrl+alt+a // ctrl+alt+a
if (event.ctrlKey && event.altKey && event.keyCode == 65) { if (event.ctrlKey && event.altKey && event.keyCode == 65) {
if (state.get().link.show) { if (state.get().link.show) {
@ -32,6 +39,11 @@ var keyboard = (function() {
link.add(); link.add();
}; };
}; };
}, false);
};
bind.ctrAltD = function() {
window.addEventListener("keydown", function(event) {
// ctrl+alt+d // ctrl+alt+d
if (event.ctrlKey && event.altKey && event.keyCode == 68) { if (event.ctrlKey && event.altKey && event.keyCode == 68) {
theme.toggle(); theme.toggle();
@ -39,12 +51,22 @@ var keyboard = (function() {
control.update(); control.update();
data.save(); data.save();
}; };
}, false);
};
bind.ctrAltM = function() {
window.addEventListener("keydown", function(event) {
// ctrl+alt+m // ctrl+alt+m
if (event.ctrlKey && event.altKey && event.keyCode == 77) { if (event.ctrlKey && event.altKey && event.keyCode == 77) {
shade.destroy(); shade.destroy();
modal.destroy(); modal.destroy();
menu.toggle(); menu.toggle();
}; };
}, false);
};
bind.ctrAltE = function() {
window.addEventListener("keydown", function(event) {
// ctrl+alt+e // ctrl+alt+e
if (event.ctrlKey && event.altKey && event.keyCode == 69) { if (event.ctrlKey && event.altKey && event.keyCode == 69) {
if (state.get().link.show && bookmarks.get().length > 0) { if (state.get().link.show && bookmarks.get().length > 0) {
@ -66,10 +88,15 @@ var keyboard = (function() {
data.save(); data.save();
}; };
}; };
}, false);
};
bind.ctrAltR = function() {
window.addEventListener("keydown", function(event) {
// ctrl+alt+r // ctrl+alt+r
if (state.get().theme.accent.random.active && event.ctrlKey && event.altKey && event.keyCode == 82) { if (state.get().theme.accent.random.active && event.ctrlKey && event.altKey && event.keyCode == 82) {
accent.random(); theme.render.accent.random();
accent.render(); theme.render.accent.color();
link.clear(); link.clear();
link.render.item.all(); link.render.item.all();
sortable(".link-area"); sortable(".link-area");
@ -79,11 +106,17 @@ var keyboard = (function() {
}; };
var init = function() { var init = function() {
_bind(); bind.esc();
bind.ctrAltA();
bind.ctrAltD();
bind.ctrAltM();
bind.ctrAltE();
bind.ctrAltR();
}; };
return { return {
init: init init: init,
bind: bind
}; };
})(); })();

View File

@ -98,7 +98,6 @@ var theme = (function() {
} }
}; };
var init = function() { var init = function() {
render.theme(); render.theme();
render.accent.random(); render.accent.random();

View File

@ -1,6 +1,6 @@
var version = (function() { var version = (function() {
var current = "3.39.0"; var current = "3.40.0";
var compare = function(a, b) { var compare = function(a, b) {
var pa = a.split("."); var pa = a.split(".");

View File

@ -2,7 +2,7 @@
"name": "nightTab", "name": "nightTab",
"short_name": "nightTab", "short_name": "nightTab",
"description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.", "description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.",
"version": "3.39.0", "version": "3.40.0",
"manifest_version": 2, "manifest_version": 2,
"chrome_url_overrides": { "chrome_url_overrides": {
"newtab": "index.html" "newtab": "index.html"