Skip to content

Commit

Permalink
Add Api
Browse files Browse the repository at this point in the history
  • Loading branch information
Shurelol committed Jun 10, 2023
1 parent 618a5eb commit 83a2283
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 42 deletions.
33 changes: 33 additions & 0 deletions Emby.CustomCssJS/Api/CustomCssJSApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Services;
using Emby.CustomCssJS.Configuration;
using System;

namespace Emby.CustomCssJS.Api
{
[Route("/CustomCssJS/Scripts", "GET", Summary = "Gets CustomCssJS Scripts")]
[Authenticated(FeatureIds = new String[] { "customcssjs" })]
public class GetCustomCssJSscripts : IReturn<PluginConfiguration>

{

}

public class CustomCssJSApi : IService, IRequiresRequest
{
private readonly IHttpResultFactory _resultFactory;

public IRequest Request { get; set; }

public CustomCssJSApi(IHttpResultFactory resultFactory)
{
_resultFactory = resultFactory;
}

public object GET (GetCustomCssJSscripts request)
{
return Plugin.Instance.Configuration;
}

}
}
4 changes: 1 addition & 3 deletions Emby.CustomCssJS/Configuration/customcssjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ define([

function loadConfiguration() {
loading.show();
ApiClient.getPluginConfiguration(pluginUniqueId).then(function (config) {
ApiClient.getJSON(ApiClient.getUrl("CustomCssJS/Scripts", {})).then(function (config) {
let [customjsServer, customjsLocal] = getCustom("js", config);
let [customcssServer, customcssLocal] = getCustom("css", config);
renderConfiguration(customjsServer, "js", "Server");
Expand All @@ -221,8 +221,6 @@ define([
renderLoadBtn();
loading.hide();
}

let pluginUniqueId = "98F76C3D-695F-4082-9220-AD5752E0859D";

view.addEventListener("viewshow", function () {
renderView();
Expand Down
4 changes: 1 addition & 3 deletions Emby.CustomCssJS/Configuration/customcssjs_update.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
function loadConfiguration(type, source, name) {
if (name) {
if (source === "Server") {
ApiClient.getPluginConfiguration(pluginUniqueId).then(function (config) {
ApiClient.getJSON(ApiClient.getUrl("CustomCssJS/Scripts", {})).then(function (config) {
let detail = config[`custom${type}`].find(item => item.name === name);
let serverId = ApiClient.serverId();
let customServerConfig = JSON.parse(localStorage.getItem(`custom${type}ServerConfig_${serverId}`));
Expand Down Expand Up @@ -200,8 +200,6 @@
loading.hide();
}

let pluginUniqueId = "98F76C3D-695F-4082-9220-AD5752E0859D";

view.addEventListener("viewshow", function () {
loading.show();
renderView(params);
Expand Down
77 changes: 41 additions & 36 deletions src/CustomCssJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,51 +75,56 @@ define([
}

function loadConfiguration() {
window.serverId = ApiClient.serverId();
ApiClient.getPluginConfiguration(pluginUniqueId).then(function (config) {
let [customjsServer, customjsLocal] = getCustom("js", config);
let [customcssServer, customcssLocal] = getCustom("css", config);
loadCode(customcssServer, "css", "Server");
loadCode(customcssLocal, "css", "Local");
loadCode(customjsServer, "js", "Server");
loadCode(customjsLocal, "js", "Local");
ApiClient.getJSON(ApiClient.getUrl("CustomCssJS/Scripts", {})).then((config) => {
if (!window.isCustomCssJSLoad) {
window.isCustomCssJSLoad = true;
let [customjsServer, customjsLocal] = getCustom("js", config);
let [customcssServer, customcssLocal] = getCustom("css", config);
loadCode(customcssServer, "css", "Server");
loadCode(customcssLocal, "css", "Local");
loadCode(customjsServer, "js", "Server");
loadCode(customjsLocal, "js", "Local");
}
}, () => {
if (window.isCustomCssJSLoad) {
reload();
}
});
}

function reload() {
if (typeof MainActivity === "undefined") {
let href = window.location.href;
if (href.match(/autostart=false/i)) {
window.location.href = `index.html?autostart=false`;
} else if (href.match(/autostart=true/i)) {
window.location.href = `index.html?autostart=true`;
} else {
window.location.reload();
}
} else {
if (document.querySelector("#Carnival")) {
window.location.href = "index.html";
} else {
MainActivity.exitApp();
setTimeout(function () {
window.open("emby://items", "_blank")
}, 150);
}
}
}

function loadCustomCssJS() {
return function () {
let serverId = ApiClient.serverId();
switch (window.serverId) {
case serverId:
return;
case undefined:
loadConfiguration();
break;
default:
if (typeof MainActivity === "undefined") {
let href = window.location.href;
if (href.match(/autostart=false/i)) {
window.location.href = `index.html?autostart=false`;
} else if (href.match(/autostart=true/i)) {
window.location.href = `index.html?autostart=true`;
} else {
window.location.reload();
}
} else {
if (document.querySelector("#Carnival")) {
window.location.href = "index.html";
} else {
MainActivity.exitApp();
setTimeout(function () {
window.open("emby://items", "_blank")
}, 150);
}
}
break;
if (window.serverId && window.serverId !== serverId) {
reload();
} else {
window.serverId = serverId;
loadConfiguration();
}
}
}
let pluginUniqueId = "98F76C3D-695F-4082-9220-AD5752E0859D";

events.on(connectionManager, "localusersignedin", loadCustomCssJS());

Expand Down
Binary file modified src/Emby.CustomCssJS.dll
Binary file not shown.

0 comments on commit 83a2283

Please sign in to comment.