v1.1 added customizeable keybinds
This commit is contained in:
parent
f20f2d89f0
commit
d2068ee023
|
@ -1,13 +1,17 @@
|
||||||
// author: joakimoa
|
// author: joakimoa
|
||||||
// keyboard navigation option
|
// keyboard navigation option
|
||||||
// v1.0
|
// v1.1
|
||||||
|
|
||||||
// adding checkbox for turning on/off
|
// adding checkbox for turning on/off
|
||||||
if (window.Options && Options.get_tab('general')) {
|
if (window.Options && Options.get_tab('general')) {
|
||||||
Options.extend_tab("general",
|
Options.extend_tab("general",
|
||||||
"<fieldset><legend> Keyboard Navigation </legend>" +
|
"<fieldset><legend> Keyboard Navigation </legend>" +
|
||||||
("<label class='keyboardnav' id='keyboardnav' style='padding:0px;'><input type='checkbox' /> Enable Keyboard Navigation (jk: up/down, e: expand) </label>") +
|
("<label class='keyboardnav' id='keyboardnav' style='padding:0px;'><input type='checkbox' /> Enable Keyboard Navigation</label>") +
|
||||||
"</fieldset>");
|
"<table><tr><td>Action</td><td>Key</td></tr>" +
|
||||||
|
"<tr><td>Next Reply</td><td><input class='field' name='next-reply' spellcheck='false'></td></tr>" +
|
||||||
|
"<tr><td>Previous Reply</td><td><input class='field' name='previous-reply' spellcheck='false'></td></tr>" +
|
||||||
|
"<tr><td>Expand File</td><td><input class='field' name='expando' spellcheck='false'></td></tr>" +
|
||||||
|
"</table></fieldset>");
|
||||||
}
|
}
|
||||||
|
|
||||||
$('.keyboardnav').on('change', function(){
|
$('.keyboardnav').on('change', function(){
|
||||||
|
@ -20,13 +24,81 @@ $('.keyboardnav').on('change', function(){
|
||||||
if (!localStorage.keyboardnav) {
|
if (!localStorage.keyboardnav) {
|
||||||
localStorage.keyboardnav = 'false';
|
localStorage.keyboardnav = 'false';
|
||||||
}
|
}
|
||||||
|
if (!localStorage["next.reply.key"]) {
|
||||||
|
localStorage["next.reply.key"] = 74;
|
||||||
|
}
|
||||||
|
if (!localStorage["previous.reply.key"]) {
|
||||||
|
localStorage["previous.reply.key"] = 75;
|
||||||
|
}
|
||||||
|
if (!localStorage["expando.key"]) {
|
||||||
|
localStorage["expando.key"] = 69;
|
||||||
|
}
|
||||||
|
|
||||||
// getting locally stored setting
|
// getting locally stored setting
|
||||||
function getSetting(key) {
|
function getSetting(key) {
|
||||||
return (localStorage[key] == 'true');
|
return (localStorage[key] == 'true');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isKeySet(key) {
|
||||||
|
return (localStorage[key] !== false);
|
||||||
|
}
|
||||||
|
|
||||||
|
var nextReplyInput = document.getElementsByName("next-reply")[0];
|
||||||
|
var previousReplyInput = document.getElementsByName("previous-reply")[0];
|
||||||
|
var expandoInput = document.getElementsByName("expando")[0];
|
||||||
|
|
||||||
|
var nextReplyKeycode = 74;
|
||||||
|
var previousReplyKeycode = 75;
|
||||||
|
var expandoKeycode = 69;
|
||||||
|
|
||||||
if (getSetting('keyboardnav')) $('#keyboardnav>input').prop('checked', 'checked');
|
if (getSetting('keyboardnav')) $('#keyboardnav>input').prop('checked', 'checked');
|
||||||
|
if (isKeySet('next.reply.key')) {
|
||||||
|
nextReplyKeycode = localStorage["next.reply.key"];
|
||||||
|
nextReplyInput.value = nextReplyKeycode;
|
||||||
|
} // need to add so it loads the settings if there are any, to both the vars and to the text fields
|
||||||
|
if (isKeySet('previous.reply.key')) {
|
||||||
|
previousReplyKeycode = localStorage["previous.reply.key"];
|
||||||
|
previousReplyInput.value = previousReplyKeycode;
|
||||||
|
}
|
||||||
|
if (isKeySet('expando.key')) {
|
||||||
|
expandoKeycode = localStorage["expando.key"];
|
||||||
|
expandoInput.value = expandoKeycode;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementsByName("next-reply")[0].value = String.fromCharCode(nextReplyKeycode);
|
||||||
|
document.getElementsByName("previous-reply")[0].value = String.fromCharCode(previousReplyKeycode);
|
||||||
|
document.getElementsByName("expando")[0].value = String.fromCharCode(expandoKeycode);
|
||||||
|
|
||||||
|
nextReplyInput.addEventListener("keyup", changeNextReplyKey, false);
|
||||||
|
previousReplyInput.addEventListener("keyup", changePreviousReplyKey, false);
|
||||||
|
expandoInput.addEventListener("keyup", changeExpandoKey, false);
|
||||||
|
|
||||||
|
function changeNextReplyKey(e) {
|
||||||
|
//console.log(String.fromCharCode(e.keyCode));
|
||||||
|
nextReplyInput.value = "";
|
||||||
|
if (e.keyCode >= 65 && e.keyCode <= 90) {
|
||||||
|
nextReplyInput.value = String.fromCharCode(e.keyCode);
|
||||||
|
localStorage["next.reply.key"] = e.keyCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function changePreviousReplyKey(e) {
|
||||||
|
//console.log(String.fromCharCode(e.keyCode));
|
||||||
|
previousReplyInput.value = "";
|
||||||
|
if (e.keyCode >= 65 && e.keyCode <= 90) {
|
||||||
|
previousReplyInput.value = String.fromCharCode(e.keyCode);
|
||||||
|
localStorage["previous.reply.key"] = e.keyCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeExpandoKey(e) {
|
||||||
|
//console.log(String.fromCharCode(e.keyCode));
|
||||||
|
expandoInput.value = "";
|
||||||
|
if (e.keyCode >= 65 && e.keyCode <= 90) {
|
||||||
|
expandoInput.value = String.fromCharCode(e.keyCode);
|
||||||
|
localStorage["expando.key"] = e.keyCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// loads the main function
|
// loads the main function
|
||||||
function loadKeyboardNav() {
|
function loadKeyboardNav() {
|
||||||
|
@ -68,11 +140,11 @@ function loadKeyboardNav() {
|
||||||
window.addEventListener("keydown", checkKeyPressed, false);
|
window.addEventListener("keydown", checkKeyPressed, false);
|
||||||
|
|
||||||
function checkKeyPressed(e) {
|
function checkKeyPressed(e) {
|
||||||
if (e.keyCode == "74") {
|
if (e.keyCode == nextReplyKeycode) {
|
||||||
scrollDown();
|
scrollDown();
|
||||||
} else if (e.keyCode == "75") {
|
} else if (e.keyCode == previousReplyKeycode) {
|
||||||
scrollUp();
|
scrollUp();
|
||||||
} else if (e.keyCode == "69") {
|
} else if (e.keyCode == expandoKeycode && k > -1) {
|
||||||
expandFile();
|
expandFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,6 +152,5 @@ function loadKeyboardNav() {
|
||||||
|
|
||||||
// loads main function if checkbox toggled and in a thread
|
// loads main function if checkbox toggled and in a thread
|
||||||
if (getSetting('keyboardnav') && document.getElementsByClassName("thread").length === 1) {
|
if (getSetting('keyboardnav') && document.getElementsByClassName("thread").length === 1) {
|
||||||
console.log("test");
|
|
||||||
loadKeyboardNav();
|
loadKeyboardNav();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue