aboutsummaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Buttons.hx57
-rw-r--r--src/client/ClientSettings.hx3
-rw-r--r--src/client/Main.hx18
3 files changed, 63 insertions, 15 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 -> {
diff --git a/src/client/ClientSettings.hx b/src/client/ClientSettings.hx
index 4e931d3..213d463 100644
--- a/src/client/ClientSettings.hx
+++ b/src/client/ClientSettings.hx
@@ -10,5 +10,6 @@ typedef ClientSettings = {
synchThreshold:Int,
isSwapped:Bool,
isUserListHidden:Bool,
- latestLinks:Array<String>
+ latestLinks:Array<String>,
+ hotkeysEnabled:Bool
}
diff --git a/src/client/Main.hx b/src/client/Main.hx
index 9ecae82..deeb2ec 100644
--- a/src/client/Main.hx
+++ b/src/client/Main.hx
@@ -22,10 +22,9 @@ using ClientTools;
class Main {
- static inline var SETTINGS_VERSION = 1;
+ static inline var SETTINGS_VERSION = 2;
public final settings:ClientSettings;
public var isSyncActive = true;
- public var synchThreshold(get, never):Int;
final clients:Array<Client> = [];
var pageTitle = document.title;
final host:String;
@@ -59,7 +58,8 @@ class Main {
synchThreshold: 2,
isSwapped: false,
isUserListHidden: false,
- latestLinks: []
+ latestLinks: [],
+ hotkeysEnabled: true
}
Settings.init(defaults, settingsPatcher);
settings = Settings.read();
@@ -76,18 +76,16 @@ class Main {
}
Lang.init("langs", () -> {
Buttons.initTextButtons(this);
+ Buttons.initHotkeys(this, player);
openWebSocket(host, port);
});
}
- inline function get_synchThreshold():Int {
- return settings.synchThreshold;
- }
-
function settingsPatcher(data:Any, version:Int):Any {
switch (version) {
- // case 1:
- // final data:ClientSettings = data;
+ case 1:
+ final data:ClientSettings = data;
+ data.hotkeysEnabled = true;
case SETTINGS_VERSION, _:
throw 'skipped version $version';
}
@@ -400,6 +398,7 @@ class Main {
player.setPlaybackRate(data.getTime.rate);
}
+ final synchThreshold = settings.synchThreshold;
final newTime = data.getTime.time;
final time = player.getTime();
if (isLeader()) {
@@ -416,6 +415,7 @@ class Main {
player.setTime(newTime);
case SetTime:
+ final synchThreshold = settings.synchThreshold;
final newTime = data.setTime.time;
final time = player.getTime();
if (Math.abs(time - newTime) < synchThreshold) return;
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage