Allow disabling of shortcuts

This commit is contained in:
Tamius Han 2019-06-02 23:54:32 +02:00
parent ebea657f8c
commit b8a6e9e0b3
9 changed files with 125 additions and 28 deletions

View File

@ -180,6 +180,32 @@ var ActionList = {
global: true,
site: true,
}
},
'set-keyboard': {
name: 'Keyboard shortcuts',
args: [{
name: 'Enable',
arg: ExtensionMode.Enabled,
},{
name: 'On whitelisted only',
arg: ExtensionMode.Whitelist,
scopes: {
global: true,
}
},{
name: 'Default',
arg: ExtensionMode.Default,
scopes: {
page: true,
}
},{
name: 'Disable',
arg: ExtensionMode.Disabled
}],
scopes: {
global: true,
site: true,
}
}
};

View File

@ -7,10 +7,10 @@ var Debug = {
init: true,
debug: true,
// debug: false,
// keyboard: true,
debugResizer: true,
debugArDetect: true,
scaler: true,
keyboard: true,
// debugResizer: true,
// debugArDetect: true,
// scaler: true,
// debugStorage: false,
// debugStorage: true,
// comms: false,
@ -18,15 +18,15 @@ var Debug = {
// showArDetectCanvas: true,
// flushStoredSettings: true,
// flushStoredSettings: false,
playerDetectDebug: true,
periodic: true,
videoRescan: true,
// playerDetectDebug: true,
// periodic: true,
// videoRescan: true,
// mousemove: true,
arDetect: {
// arDetect: {
// edgeDetect: true
},
// },
canvas: {
debugDetection: true
// debugDetection: true
},
debugCanvas: {
// enabled: true,

View File

@ -1,5 +1,6 @@
import Debug from '../conf/Debug';
import PlayerData from './video-data/PlayerData';
import ExtensionMode from '../../common/enums/extension-mode.enum';
class ActionHandler {
@ -8,6 +9,7 @@ class ActionHandler {
this.settings = pageInfo.settings;
this.inputs = ['input', 'select', 'button', 'textarea'];
this.keyboardLocalDisabled = false;
}
init() {
@ -119,6 +121,15 @@ class ActionHandler {
}
setKeyboardLocal(state) {
if (state === ExtensionMode.Enabled) {
this.keyboardLocalDisabled = false;
} else if (state === ExtensionMode.Disabled) {
this.keyboardLocalDisabled = true;
}
// don't do shit on invalid value of state
}
preventAction() {
var activeElement = document.activeElement;
@ -130,6 +141,8 @@ class ActionHandler {
"\nis tag one of defined inputs? (yes->prevent):", this.inputs.indexOf(activeElement.tagName.toLocaleLowerCase()) !== -1,
"\nis role = textbox? (yes -> prevent):", activeElement.getAttribute("role") === "textbox",
"\nis type === 'text'? (yes -> prevent):", activeElement.getAttribute("type") === "text",
"\nis keyboard local disabled? (yes -> prevent):", this.keyboardLocalDisabled,
"\nis keyboard enabled in settings? (no -> prevent)", this.settings.keyboardShortcutsEnabled(window.location.hostname),
"\nwill the action be prevented? (yes -> prevent)", this.preventAction(),
"\n-----------------{ extra debug info }-------------------",
"\ntag name? (lowercase):", activeElement.tagName, activeElement.tagName.toLocaleLowerCase(),
@ -146,6 +159,13 @@ class ActionHandler {
// if (PlayerData.isFullScreen()) {
// return false;
// }
if (this.keyboardLocalDisabled) {
return true;
}
if (!this.settings.keyboardShortcutsEnabled(window.location.hostname)) {
return true;
}
if (this.inputs.indexOf(activeElement.tagName.toLocaleLowerCase()) !== -1) {
return true;
}
@ -193,27 +213,22 @@ class ActionHandler {
if (videoData) {
videoData.panHandler(event, true);
}
} else if (cmd.action === 'set-keyboard') {
this.setKeyboardLocal(cmd.arg);
}
} else if (action.scope === 'site') {
} else {
let site = action.scope === 'site' ? window.location.host : '@global';
if (cmd.action === "set-stretch") {
this.settings.active.sites[window.location.host].stretch = cmd.arg;
this.settings.active.sites[site].stretch = cmd.arg;
} else if (cmd.action === "set-alignment") {
this.settings.active.sites[window.location.host].videoAlignment = cmd.arg;
this.settings.active.sites[site].videoAlignment = cmd.arg;
} else if (cmd.action === "set-extension-mode") {
this.settings.active.sites[window.location.host].status = cmd.arg;
this.settings.active.sites[site].status = cmd.arg;
} else if (cmd.action === "set-autoar-mode") {
this.settings.active.sites[window.location.host].arStatus = cmd.arg;
}
this.settings.save();
} else if (action.scope === 'global') {
if (cmd.action === "set-stretch") {
this.settings.active.stretch.initialMode = cmd.arg;
} else if (cmd.action === "set-alignment") {
this.settings.active.miscSettings.videoAlignment = cmd.arg;
} else if (cmd.action === "set-extension-mode") {
this.settings.active.sites['@global'] = cmd.arg;
} else if (cmd.action === "set-autoar-mode") {
this.settings.active.arDetect.mode.arStatus = cmd.arg;
this.settings.active.sites[site].arStatus = cmd.arg;
} else if (cmd.action === 'set-keyboard') {
this.settings.active.sites[site].keyboardShortcutsEnabled = cmd.arg;
}
this.settings.save();
}

View File

@ -297,6 +297,30 @@ class Settings {
}
}
keyboardShortcutsEnabled(site) {
if (!site) {
site = window.location.hostname;
}
if (!site) {
return false;
}
try {
if (!this.active.sites[site]
|| this.active.sites[site].keyboardShortcutsEnabled === undefined
|| this.active.sites[site].keyboardShortcutsEnabled === ExtensionMode.Default) {
return this.keyboardShortcutsEnabled('@global');
} else {
return this.active.sites[site].keyboardShortcutsEnabled === ExtensionMode.Enabled;
}
} catch (e) {
if (Debug.debug) {
console.error("[Settings.js::keyboardDisabled] something went wrong:", e);
}
return false;
}
}
extensionEnabled(){
return this.active.sites['@global'] !== ExtensionMode.Disabled
}

View File

@ -71,6 +71,8 @@ class CommsClient {
this.pageInfo.restoreAr();
} else if (message.cmd === "set-stretch") {
this.pageInfo.setStretchMode(message.arg, message.playing);
} else if (message.cmd === 'set-keyboard') {
this.pageInfo.setKeyboardShortcutsEnabled(message.arg)
} else if (message.cmd === "autoar-start") {
if (message.enabled !== false) {
this.pageInfo.initArDetection(message.playing);

View File

@ -479,6 +479,10 @@ class PageInfo {
requestCurrentZoom() {
this.comms.announceZoom(this.currentZoomScale);
}
setKeyboardShortcutsEnabled(state) {
this.actionHandler.setKeybordLocal(state);
}
}
export default PageInfo;

View File

@ -46,7 +46,7 @@ class ExecAction {
this.settings.active.sites[site].mode = cmd.arg;
} else if (cmd.action === "set-autoar-mode") {
this.settings.active.sites[site].autoar = cmd.arg;
}
} else if (cmd.action === 'set-keyboard') {
this.settings.active.sites[site].keyboardShortcutsEnabled = cmd.arg;
}
this.settings.save();

View File

@ -57,6 +57,19 @@
</ShortcutButton>
</div>
</div>
<div v-if="keyboardActions.length">
<div class="label experimental">Enable/disable keyboard shortcuts</div>
<div class="flex flex-row flex-wrap">
<ShortcutButton v-for="(action, index) of keyboardActions"
class="flex b3 flex-grow button"
:class="{'setting-selected': getCurrent('keyboardShortcutsEnabled') === action.cmd[0].arg}"
:key="index"
:label="(action.scopes[scope] && action.scopes[scope].label) ? action.scopes[scope].label : action.label"
:shortcut="parseShortcut(action)"
@click.native="execAction(action)"
>
</ShortcutButton>
</div>
</div>

View File

@ -65,8 +65,21 @@
</ShortcutButton>
</div>
</div>
<!-- <div v-if="keyboardActions.length">
<div class="label">Keyboard shortcuts:</div>
<div class="flex flex-row flex-wrap">
<ShortcutButton v-for="(action, index) of keyboardActions"
class="flex b3 button"
:key="index"
:label="(action.scopes.page && action.scopes.page.label) ? action.scopes.page.label : action.label"
:shortcut="parseShortcut(action)"
@click.native="execAction(action)"
>
</ShortcutButton>
</div>
</div> -->
<div v-if="true">
<div v-if="alignmentActions.length">
<div class="label">Video alignment:</div>
<div class="flex flex-row flex-wrap">