From 45080aa1f6d80f2ef64983904acbe1645c312d25 Mon Sep 17 00:00:00 2001 From: RblSb Date: Sat, 23 May 2020 22:06:31 +0300 Subject: Improve history inputs --- src/client/InputWithHistory.hx | 12 +++++++++--- src/client/Main.hx | 2 +- src/client/players/Raw.hx | 14 +++++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/client/InputWithHistory.hx b/src/client/InputWithHistory.hx index 9c5b615..ecba43a 100644 --- a/src/client/InputWithHistory.hx +++ b/src/client/InputWithHistory.hx @@ -23,12 +23,18 @@ class InputWithHistory { element.onkeydown = onKeyDown; } + public static function pushIfNotLast(arr:Array, item:String):Void { + final len = arr.length; + if (len == 0 || arr[len - 1] != item) arr.push(item); + } + function onKeyDown(e:KeyboardEvent) { switch (e.keyCode) { case 13: // Enter - if (element.value.length == 0) return; - final isAdd = onEnter(element.value); - if (isAdd) history.push(element.value); + final value = element.value; + if (value.length == 0) return; + final isAdd = onEnter(value); + if (isAdd) pushIfNotLast(history, value); if (history.length > maxItems) history.shift(); historyId = -1; element.value = ""; diff --git a/src/client/Main.hx b/src/client/Main.hx index 846acf6..7e3a3be 100644 --- a/src/client/Main.hx +++ b/src/client/Main.hx @@ -202,7 +202,7 @@ class Main { final url = mediaUrl.value; if (url.length == 0) return; mediaUrl.value = ""; - settings.latestLinks.push(url); + InputWithHistory.pushIfNotLast(settings.latestLinks, url); Settings.write(settings); final url = ~/, ?(https?)/g.replace(url, "|$1"); final links = url.split("|"); diff --git a/src/client/players/Raw.hx b/src/client/players/Raw.hx index dacf45c..57dd9b3 100644 --- a/src/client/players/Raw.hx +++ b/src/client/players/Raw.hx @@ -33,12 +33,16 @@ class Raw implements IPlayer { public function getVideoData(url:String, callback:(data:VideoData)->Void):Void { final decodedUrl = url.urlDecode(); var title = decodedUrl.substr(decodedUrl.lastIndexOf("/") + 1); - if (matchName.match(title)) title = matchName.matched(1); + final isNameMatched = matchName.match(title); + if (isNameMatched) title = matchName.matched(1); else title = Lang.get("rawVideo"); - final isHls = matchName.matched(2).contains("m3u8"); - if (isHls && !isHlsLoaded) { - loadHlsPlugin(() -> getVideoData(url, callback)); - return; + var isHls = false; + if (isNameMatched) { + isHls = matchName.matched(2).contains("m3u8"); + if (isHls && !isHlsLoaded) { + loadHlsPlugin(() -> getVideoData(url, callback)); + return; + } } final video = document.createVideoElement(); -- cgit v1.2.3