diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/JsApi.hx | 32 | ||||
| -rw-r--r-- | src/client/Main.hx | 12 | ||||
| -rw-r--r-- | src/client/Player.hx | 6 |
3 files changed, 43 insertions, 7 deletions
diff --git a/src/client/JsApi.hx b/src/client/JsApi.hx index b97c0f0..a236570 100644 --- a/src/client/JsApi.hx +++ b/src/client/JsApi.hx @@ -66,6 +66,24 @@ class JsApi { } @:expose + static function getVideoItems():VideoList { + final items = player.getItems(); + return [ + for (item in items) Reflect.copy(item) + ]; + } + + @:expose + static function addVideoItem(url:String, atEnd:Bool, isTemp:Bool, ?callback:() -> Void):Void { + main.addVideo(url, atEnd, isTemp, callback); + } + + @:expose + static function removeVideoItem(url:String):Void { + main.removeVideoItem(url); + } + + @:expose static function getTime():Float { return player.getTime(); } @@ -102,6 +120,13 @@ class JsApi { return main.globalIp; } + /** + * If plugin adds any subtitle format (like `ass`), + * you will see subtitle input below video url input on client page. + * Plugins can listen to `notifyOnVideoChange(item => {...}` + * for raw videos and load that input data from `item.subs` url to do something. + * See `https://github.com/RblSb/SyncTube-octosubs` as example. + */ @:expose static function addSubtitleSupport(format:String):Void { format = format.trim().toLowerCase(); @@ -115,6 +140,13 @@ class JsApi { return subtitleFormats.contains(format); } + /** + * Listen to server event once before that event is parsed by client. + * Example: + * `JsApi.once("RemoveVideo", event => {` + * ` if (event.removeVideo.url == url) {...}` + * `});` + */ @:expose public static function once(type:WsEventType, func:OnceEventFunc):Void { onceListeners.push({type: type, func: func}); diff --git a/src/client/Main.hx b/src/client/Main.hx index b9c9892..1d9ac34 100644 --- a/src/client/Main.hx +++ b/src/client/Main.hx @@ -242,7 +242,7 @@ class Main { addVideo(link, atEnd, isTemp, () -> addVideoArray(links, atEnd, isTemp)); } - function addVideo(url:String, atEnd:Bool, isTemp:Bool, callback:()->Void):Void { + public function addVideo(url:String, atEnd:Bool, isTemp:Bool, ?callback:()->Void):Void { final protocol = Browser.location.protocol; if (url.startsWith("/")) { final host = Browser.location.hostname; @@ -275,7 +275,7 @@ class Main { }, atEnd: atEnd }}); - callback(); + if (callback != null) callback(); }); } @@ -316,6 +316,14 @@ class Main { }); } + public function removeVideoItem(url:String) { + send({ + type: RemoveVideo, removeVideo: { + url: url + } + }); + } + public function toggleVideoElement():Bool { if (player.hasVideo()) player.removeVideo(); else if (!player.isListEmpty()) { diff --git a/src/client/Player.hx b/src/client/Player.hx index 735f73c..c9b379c 100644 --- a/src/client/Player.hx +++ b/src/client/Player.hx @@ -64,11 +64,7 @@ class Player { }); } if (btn.classList.contains("qbtn-delete")) { - main.send({ - type: RemoveVideo, removeVideo: { - url: item.querySelector(".qe_title").getAttribute("href") - } - }); + main.removeVideoItem(item.querySelector(".qe_title").getAttribute("href")); } } } |
