aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/JsApi.hx49
-rw-r--r--src/client/Player.hx1
2 files changed, 50 insertions, 0 deletions
diff --git a/src/client/JsApi.hx b/src/client/JsApi.hx
new file mode 100644
index 0000000..810e2f2
--- /dev/null
+++ b/src/client/JsApi.hx
@@ -0,0 +1,49 @@
+package client;
+
+import Types.VideoItem;
+import js.Browser.document;
+
+private typedef VideoChangeFunc = (item:VideoItem)->Void;
+
+
+class JsApi {
+
+ static final videoChange:Array<VideoChangeFunc> = [];
+
+ @:expose
+ public static function addPlugin(id:String, ?onLoaded:()->Void):Void {
+ addScriptToHead('/plugins/$id/index.js', onLoaded);
+ }
+
+ @:expose
+ public static function addScriptToHead(url:String, ?onLoaded:()->Void):Void {
+ var script = document.createScriptElement();
+ script.type = "text/javascript";
+ script.onload = onLoaded;
+ script.src = url;
+ document.getElementsByTagName("head")[0].appendChild(script);
+ }
+
+ @:expose
+ public static function hasScriptInHead(url:String):Bool {
+ for (child in document.getElementsByTagName("head")[0].children) {
+ if ((child : Dynamic).src == url) return true;
+ }
+ return false;
+ }
+
+ @:expose
+ public static function notifyOnVideoChange(func:VideoChangeFunc):Void {
+ videoChange.push(func);
+ }
+
+ @:expose
+ public static function removeFromVideoChange(func:VideoChangeFunc):Void {
+ videoChange.remove(func);
+ }
+
+ public static function fireVideoChangeEvents(item:VideoItem):Void {
+ for (func in videoChange) func(item);
+ }
+
+}
diff --git a/src/client/Player.hx b/src/client/Player.hx
index 92cee1c..780f8cc 100644
--- a/src/client/Player.hx
+++ b/src/client/Player.hx
@@ -120,6 +120,7 @@ class Player {
currentSrc = item.url;
isLoaded = false;
player.loadVideo(item);
+ JsApi.fireVideoChangeEvents(item);
ge("#currenttitle").textContent = item.title;
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage