namespace Jellyfin.Plugin.JCoverXtremePro.Api;
using System;
using System.IO;
using System.Text.RegularExpressions;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Configuration;
using Microsoft.Extensions.Logging;
///
/// Utility for injecting a JavaScript script tag into the Jellyfin web frontend.
///
public static class ScriptInjector
{
public static void PerformInjection(
IApplicationPaths applicationPaths,
IServerConfigurationManager configurationManager
)
{
var indexHtmlFilePath = Path.Combine(applicationPaths.WebPath, "index.html");
if (!File.Exists(indexHtmlFilePath))
{
Plugin.Logger.LogWarning("Could not find index html file");
return;
}
var html = File.ReadAllText(indexHtmlFilePath);
var snippet = GetInjectedSnippet(GetHTTPBasePath(configurationManager));
if (html.Contains(snippet, StringComparison.InvariantCulture))
{
Plugin.Logger.LogInformation("Not injecting existing HTML snippet.");
return;
}
html = Regex.Replace(html, $"", string.Empty);
var bodyEnd = html.LastIndexOf("