mirror of
https://github.com/ranaldsgift/KefinTweaks.git
synced 2026-11-05 15:52:47 +01:00
Fix JS Injector saving/loading
This commit is contained in:
+20
-88
@@ -191,7 +191,7 @@
|
||||
// Note: scriptRoot is no longer used - scripts are loaded from kefinTweaksRoot + '/scripts/'
|
||||
|
||||
// Save defaults to JS Injector for future use
|
||||
await saveConfigToJavaScriptInjector(defaultConfig);
|
||||
await KefinTweaksUtils.saveConfigToJavaScriptInjector(defaultConfig);
|
||||
|
||||
return defaultConfig;
|
||||
} catch (error) {
|
||||
@@ -2278,7 +2278,7 @@
|
||||
config.enabled = isEnabled;
|
||||
|
||||
// Save the updated config to the injector
|
||||
await saveConfigToJavaScriptInjector(config);
|
||||
await KefinTweaksUtils.saveConfigToJavaScriptInjector(config);
|
||||
|
||||
window.KefinTweaksConfigEnabled = isEnabled;
|
||||
console.log('[KefinTweaks Configuration] KefinTweaks', isEnabled ? 'enabled' : 'disabled');
|
||||
@@ -4684,7 +4684,7 @@
|
||||
// Apply imported configuration
|
||||
async function applyImportedConfig(importedConfig, modalInstance) {
|
||||
// Save to JavaScript Injector
|
||||
await saveConfigToJavaScriptInjector(importedConfig);
|
||||
await KefinTweaksUtils.saveConfigToJavaScriptInjector(importedConfig);
|
||||
|
||||
// Reload the modal with new config
|
||||
modalInstance.close();
|
||||
@@ -4707,20 +4707,7 @@
|
||||
throw new Error('ApiClient not available');
|
||||
}
|
||||
|
||||
const server = ApiClient._serverAddress;
|
||||
const token = ApiClient.accessToken();
|
||||
|
||||
const response = await fetch(`${server}/Plugins`, {
|
||||
headers: {
|
||||
'X-Emby-Token': token
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const plugins = await response.json();
|
||||
const plugins = await apiHelper.getPlugins();
|
||||
console.log('[KefinTweaks Configuration] Active Plugins:', plugins);
|
||||
|
||||
// Handle both array and object with Items property
|
||||
@@ -4752,10 +4739,22 @@
|
||||
|
||||
const server = ApiClient._serverAddress;
|
||||
const token = ApiClient.accessToken();
|
||||
const client = typeof ApiClient.applicationName === 'function' ? ApiClient.applicationName() : 'Jellyfin Web';
|
||||
const device = typeof ApiClient.deviceName === 'function' ? ApiClient.deviceName() : (navigator.userAgent.includes('Chrome') ? 'Chrome' : 'Browser');
|
||||
const deviceId = typeof ApiClient.deviceId === 'function' ? ApiClient.deviceId() : '';
|
||||
const version = ApiClient._appVersion || ApiClient._serverVersion || '';
|
||||
const parts = [
|
||||
`Client="${encodeURIComponent(client)}"`,
|
||||
`Device="${encodeURIComponent(device)}"`,
|
||||
`DeviceId="${encodeURIComponent(deviceId)}"`,
|
||||
`Version="${encodeURIComponent(version)}"`,
|
||||
`Token="${encodeURIComponent(token)}"`
|
||||
];
|
||||
const auth = `MediaBrowser ${parts.join(', ')}`;
|
||||
|
||||
const response = await fetch(`${server}/Plugins/${pluginId}/Configuration`, {
|
||||
headers: {
|
||||
'X-Emby-Token': token
|
||||
'Authorization': auth
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4772,73 +4771,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Save configuration to JavaScript Injector plugin
|
||||
async function saveConfigToJavaScriptInjector(config) {
|
||||
try {
|
||||
// Find the plugin
|
||||
const pluginId = await findJavaScriptInjectorPlugin();
|
||||
|
||||
// Get fresh configuration data
|
||||
const injectorConfig = await getJavaScriptInjectorConfig(pluginId);
|
||||
|
||||
// Ensure CustomJavaScripts array exists
|
||||
if (!injectorConfig.CustomJavaScripts) {
|
||||
injectorConfig.CustomJavaScripts = [];
|
||||
}
|
||||
|
||||
// Create the script content
|
||||
const scriptContent = `// KefinTweaks Configuration
|
||||
// This file is automatically generated by KefinTweaks Configuration UI
|
||||
// Do not edit manually unless you know what you're doing
|
||||
|
||||
window.KefinTweaksConfig = ${JSON.stringify(config, null, 2)};`;
|
||||
|
||||
// Check if KefinTweaks-Config already exists
|
||||
const existingScriptIndex = injectorConfig.CustomJavaScripts.findIndex(
|
||||
script => script.Name === 'KefinTweaks-Config'
|
||||
);
|
||||
|
||||
if (existingScriptIndex !== -1) {
|
||||
// Update existing script
|
||||
console.log('[KefinTweaks Configuration] Updating existing KefinTweaks-Config script');
|
||||
injectorConfig.CustomJavaScripts[existingScriptIndex].Script = scriptContent;
|
||||
// Keep existing Enabled and RequiresAuthentication settings
|
||||
} else {
|
||||
// Add new script
|
||||
console.log('[KefinTweaks Configuration] Adding new KefinTweaks-Config script');
|
||||
injectorConfig.CustomJavaScripts.push({
|
||||
Name: 'KefinTweaks-Config',
|
||||
Script: scriptContent,
|
||||
Enabled: true,
|
||||
RequiresAuthentication: false
|
||||
});
|
||||
}
|
||||
|
||||
// POST the updated configuration back
|
||||
const server = ApiClient._serverAddress;
|
||||
const token = ApiClient.accessToken();
|
||||
|
||||
const response = await fetch(`${server}/Plugins/${pluginId}/Configuration`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Emby-Token': token,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(injectorConfig)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
||||
}
|
||||
|
||||
console.log('[KefinTweaks Configuration] Configuration saved successfully');
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('[KefinTweaks Configuration] Error saving configuration:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function getSectionConfigFromUI(rootElement, prefix, sectionIndex) {
|
||||
const scope = rootElement || document;
|
||||
const sectionItem = scope.querySelector(`.${prefix}_section_item[data-section-index="${sectionIndex}"]`);
|
||||
@@ -5404,7 +5336,7 @@ window.KefinTweaksConfig = ${JSON.stringify(config, null, 2)};`;
|
||||
|
||||
// Save to JavaScript Injector plugin
|
||||
try {
|
||||
await saveConfigToJavaScriptInjector(config);
|
||||
await KefinTweaksUtils.saveConfigToJavaScriptInjector(config);
|
||||
|
||||
// Update global config objects so dropdown changes reflect saved values
|
||||
window.KefinTweaksConfig = config;
|
||||
@@ -5448,7 +5380,7 @@ window.KefinTweaksConfig = ${JSON.stringify(config, null, 2)};`;
|
||||
defaultConfig.kefinTweaksRoot = existingConfig.kefinTweaksRoot;
|
||||
// Note: scriptRoot is no longer used - scripts are loaded from kefinTweaksRoot + '/scripts/'
|
||||
|
||||
await saveConfigToJavaScriptInjector(defaultConfig);
|
||||
await KefinTweaksUtils.saveConfigToJavaScriptInjector(defaultConfig);
|
||||
|
||||
if (window.KefinTweaksToaster && window.KefinTweaksToaster.toast) {
|
||||
window.KefinTweaksToaster.toast('Configuration reset to defaults.');
|
||||
@@ -5488,7 +5420,7 @@ window.KefinTweaksConfig = ${JSON.stringify(config, null, 2)};`;
|
||||
// This will trigger the reset logic in injector.js for all clients
|
||||
config.configVersion = Date.now();
|
||||
|
||||
await saveConfigToJavaScriptInjector(config);
|
||||
await KefinTweaksUtils.saveConfigToJavaScriptInjector(config);
|
||||
|
||||
if (window.KefinTweaksToaster && window.KefinTweaksToaster.toast) {
|
||||
window.KefinTweaksToaster.toast('Reset signal sent. All users will be reset on next load.');
|
||||
|
||||
Reference in New Issue
Block a user