aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/Buttons.hx
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2020-05-13 06:44:54 +0300
committerRblSb <msrblsb@gmail.com>2020-05-13 06:44:54 +0300
commit2d82ca5f1049fb332b521691c29b9d789d08f690 (patch)
tree829e2c8a22c00fd9bf3c222e8f8a1cfcef372432 /src/client/Buttons.hx
parent28a1d1c271dd722dc36cebc5b61f87d80138dba3 (diff)
Add hotkeys
Diffstat (limited to 'src/client/Buttons.hx')
-rw-r--r--src/client/Buttons.hx57
1 files changed, 52 insertions, 5 deletions
diff --git a/src/client/Buttons.hx b/src/client/Buttons.hx
index a04b444..769cb25 100644
--- a/src/client/Buttons.hx
+++ b/src/client/Buttons.hx
@@ -288,13 +288,54 @@ class Buttons {
public static function initTextButtons(main:Main):Void {
final synchThresholdBtn = ge("#synchThresholdBtn");
synchThresholdBtn.onclick = e -> {
- var secs = main.synchThreshold + 1;
+ var secs = settings.synchThreshold + 1;
if (secs > 5) secs = 1;
main.setSynchThreshold(secs);
- updateSynchThresholdBtn(main);
+ updateSynchThresholdBtn();
synchThresholdBtn.blur();
}
- updateSynchThresholdBtn(main);
+ updateSynchThresholdBtn();
+
+ final hotkeysBtn = ge("#hotkeysBtn");
+ hotkeysBtn.onclick = e -> {
+ settings.hotkeysEnabled = !settings.hotkeysEnabled;
+ Settings.write(settings);
+ updateHotkeysBtn();
+ hotkeysBtn.blur();
+ }
+ updateHotkeysBtn();
+ }
+
+ public static function initHotkeys(main:Main, player:Player):Void {
+ ge("#mediarefresh").title += " (Alt-R)";
+ ge("#voteskip").title += " (Alt-S)";
+ ge("#getplaylist").title += " (Alt-C)";
+ ge("#fullscreenbtn").title += " (Alt-F)";
+ ge("#leader_btn").title += " (Alt-L)";
+ window.onkeydown = function(e:KeyboardEvent) {
+ if (!settings.hotkeysEnabled) return;
+ final target:Element = cast e.target;
+ if (target.isContentEditable) return;
+ final tagName = target.tagName;
+ if (tagName == "INPUT" || tagName == "TEXTAREA") return;
+ final key:KeyCode = cast e.keyCode;
+ if (key == Backspace) e.preventDefault();
+ if (!e.altKey) return;
+ switch (key) {
+ case R: ge("#mediarefresh").onclick();
+ case S: ge("#voteskip").onclick();
+ case C: ge("#getplaylist").onclick();
+ case F: ge("#fullscreenbtn").onclick();
+ case L: ge("#leader_btn").onclick();
+ case P:
+ if (!main.isLeader()) {
+ Timer.delay(() -> player.pause(), 500);
+ }
+ ge("#leader_btn").onclick();
+ default: return;
+ }
+ e.preventDefault();
+ }
}
static function hideMenus():Void {
@@ -302,12 +343,18 @@ class Buttons {
for (menu in menus) menu.style.display = "";
}
- static function updateSynchThresholdBtn(main:Main):Void {
+ static function updateSynchThresholdBtn():Void {
final text = Lang.get("synchThreshold");
- final secs = main.synchThreshold;
+ final secs = settings.synchThreshold;
ge("#synchThresholdBtn").innerText = '$text: ${secs}s';
}
+ static function updateHotkeysBtn():Void {
+ final text = Lang.get("hotkeys");
+ final state = settings.hotkeysEnabled ? Lang.get("on") : Lang.get("off");
+ ge("#hotkeysBtn").innerText = '$text: $state';
+ }
+
static function initChatInput(main:Main):Void {
final guestName:InputElement = cast ge("#guestname");
guestName.onkeydown = e -> {
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage