aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2020-04-30 04:24:49 +0300
committerRblSb <msrblsb@gmail.com>2020-04-30 04:24:49 +0300
commitd751f4fb76d9e68d56d06b5d35aa0850def063e7 (patch)
tree0fc8665ecc0673633d948748d5b1523e4b34fa94
parentdcba207583b70426a4cf0e566241894a13911758 (diff)
Change addPlugin api
-rw-r--r--res/client.js22
-rw-r--r--src/client/JsApi.hx24
2 files changed, 42 insertions, 4 deletions
diff --git a/res/client.js b/res/client.js
index f19bebc..93639f4 100644
--- a/res/client.js
+++ b/res/client.js
@@ -858,14 +858,32 @@ client_InputWithHistory.prototype = {
var client_JsApi = function() { };
client_JsApi.__name__ = true;
client_JsApi.addPlugin = $hx_exports["client"]["JsApi"]["addPlugin"] = function(id,onLoaded) {
- client_JsApi.addScriptToHead("/plugins/" + id + "/index.js",onLoaded);
+ client_JsApi.initPluginsSpace();
+ client_JsApi.addScriptToHead("/plugins/" + id + "/index.js",function() {
+ var obj = { api : client_JsApi, id : id, path : "/plugins/" + id};
+ if(window.synctube[id] == null) {
+ window.console.error("Plugin \"" + id + "\" not found");
+ } else {
+ new synctube[id](obj);
+ if(onLoaded != null) {
+ onLoaded();
+ }
+ }
+ return;
+ });
+};
+client_JsApi.initPluginsSpace = function() {
+ var w = window;
+ if(w.synctube == null) {
+ w.synctube = { };
+ }
};
client_JsApi.addScriptToHead = $hx_exports["client"]["JsApi"]["addScriptToHead"] = function(url,onLoaded) {
var script = window.document.createElement("script");
script.type = "text/javascript";
script.onload = onLoaded;
script.src = url;
- window.document.getElementsByTagName("head")[0].appendChild(script);
+ window.document.head.appendChild(script);
};
client_JsApi.hasScriptInHead = $hx_exports["client"]["JsApi"]["hasScriptInHead"] = function(url) {
var _g = 0;
diff --git a/src/client/JsApi.hx b/src/client/JsApi.hx
index 2df9c57..8a6315c 100644
--- a/src/client/JsApi.hx
+++ b/src/client/JsApi.hx
@@ -2,6 +2,8 @@ package client;
import Types.VideoItem;
import js.Browser.document;
+import js.Browser.window;
+import js.Syntax;
private typedef VideoChangeFunc = (item:VideoItem)->Void;
@@ -12,7 +14,25 @@ class JsApi {
@:expose
static function addPlugin(id:String, ?onLoaded:()->Void):Void {
- addScriptToHead('/plugins/$id/index.js', onLoaded);
+ initPluginsSpace();
+ addScriptToHead('/plugins/$id/index.js', () -> {
+ final obj = {
+ api: JsApi,
+ id: id,
+ path: '/plugins/$id'
+ }
+ if (untyped window.synctube[id] == null) {
+ window.console.error('Plugin "$id" not found');
+ } else {
+ Syntax.code("new synctube[id]({0})", obj);
+ if (onLoaded != null) onLoaded();
+ }
+ });
+ }
+
+ static function initPluginsSpace():Void {
+ final w:Dynamic = window;
+ if (w.synctube == null) w.synctube = {};
}
@:expose
@@ -21,7 +41,7 @@ class JsApi {
script.type = "text/javascript";
script.onload = onLoaded;
script.src = url;
- document.getElementsByTagName("head")[0].appendChild(script);
+ document.head.appendChild(script);
}
@:expose
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage