mirror of
https://github.com/ranaldsgift/KefinTweaks.git
synced 2026-11-05 15:52:47 +01:00
156 lines
6.3 KiB
JavaScript
156 lines
6.3 KiB
JavaScript
// KefinTweaks Search Configuration UI
|
|
// Modular configuration modal for managing search settings
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
const LOG = (...args) => console.log('[KefinTweaks Search Config]', ...args);
|
|
const ERR = (...args) => console.error('[KefinTweaks Search Config]', ...args);
|
|
|
|
const MODAL_ID = 'kefin-search-config';
|
|
|
|
/**
|
|
* Load configuration from window.KefinTweaksConfig
|
|
*/
|
|
async function loadConfig() {
|
|
const config = window.KefinTweaksConfig || {};
|
|
return config.search || {};
|
|
}
|
|
|
|
/**
|
|
* Save configuration to JS Injector
|
|
*/
|
|
async function saveConfig(searchConfig) {
|
|
try {
|
|
// Ensure window.KefinTweaksConfig exists
|
|
if (!window.KefinTweaksConfig) {
|
|
window.KefinTweaksConfig = {};
|
|
}
|
|
|
|
// Update search config
|
|
window.KefinTweaksConfig.search = searchConfig;
|
|
|
|
// Save to JS Injector using utils
|
|
if (window.KefinTweaksUtils && window.KefinTweaksUtils.saveConfigToJavaScriptInjector) {
|
|
await window.KefinTweaksUtils.saveConfigToJavaScriptInjector();
|
|
LOG('Configuration saved to JS Injector');
|
|
return true;
|
|
} else {
|
|
// Fallback: use findJavaScriptInjectorPlugin and saveConfigToJavaScriptInjector from configuration.js
|
|
if (window.KefinTweaksConfiguration && window.KefinTweaksConfiguration.findJavaScriptInjectorPlugin) {
|
|
const pluginId = await window.KefinTweaksConfiguration.findJavaScriptInjectorPlugin();
|
|
if (pluginId) {
|
|
await window.KefinTweaksConfiguration.saveConfigToJavaScriptInjector(window.KefinTweaksConfig);
|
|
LOG('Configuration saved to JS Injector (fallback)');
|
|
return true;
|
|
}
|
|
}
|
|
ERR('saveConfigToJavaScriptInjector not available');
|
|
return false;
|
|
}
|
|
} catch (error) {
|
|
ERR('Error saving config:', error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Build configuration HTML
|
|
*/
|
|
function buildConfigHTML(config) {
|
|
return `
|
|
<div style="max-width: 800px;">
|
|
<div class="listItem" style="border: 1px solid rgba(255,255,255,0.1); border-radius: 4px; padding: 0.75em; margin-bottom: 1em;">
|
|
<div class="listItemContent">
|
|
<div class="listItemBodyText" style="margin-bottom: 0.5em;">Enable Seerr results from JellyfinEnhanced</div>
|
|
<div class="listItemBodyText secondary" style="margin-bottom: 0.75em; font-size: 0.9em;">If you are using Seerr from Jellyfin Enhanced, you can enable this to add an additional search toggle for Requests</div>
|
|
<label class="checkboxContainer" style="display: flex; align-items: center; gap: 0.5em;">
|
|
<input type="checkbox" id="search_enableJellyseerr" ${config.enableJellyseerr === true ? 'checked' : ''}>
|
|
<span class="listItemBodyText">Enabled</span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
/**
|
|
* Collect configuration from form
|
|
*/
|
|
function collectConfig() {
|
|
const enableJellyseerr = document.getElementById('search_enableJellyseerr')?.checked === true;
|
|
return {
|
|
enableJellyseerr: enableJellyseerr
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Open configuration modal
|
|
*/
|
|
async function openConfigModal() {
|
|
try {
|
|
// Load config
|
|
const config = await loadConfig();
|
|
|
|
// Build content
|
|
const content = document.createElement('div');
|
|
content.innerHTML = buildConfigHTML(config);
|
|
|
|
// Build footer
|
|
const footer = document.createElement('div');
|
|
footer.style.display = 'flex';
|
|
footer.style.gap = '0.75em';
|
|
footer.style.justifyContent = 'flex-end';
|
|
footer.innerHTML = `
|
|
<button class="emby-button raised" onclick="window.ModalSystem.close('${MODAL_ID}')">Close</button>
|
|
<button class="emby-button raised block button-submit" id="save-search-config-btn">Save</button>
|
|
`;
|
|
|
|
// Create modal
|
|
window.ModalSystem.create({
|
|
id: MODAL_ID,
|
|
title: 'Search Configuration',
|
|
content: content,
|
|
footer: footer,
|
|
closeOnBackdrop: true,
|
|
closeOnEscape: true,
|
|
showCloseButton: true,
|
|
dialogStyle: window.innerWidth >= 900
|
|
? { maxWidth: '90vw', width: '1400px', height: '90vh' }
|
|
: undefined,
|
|
onOpen: (modal) => {
|
|
// Save button
|
|
const saveBtn = modal.dialogFooter.querySelector('#save-search-config-btn');
|
|
if (saveBtn) {
|
|
saveBtn.addEventListener('click', async () => {
|
|
const searchConfig = collectConfig();
|
|
const success = await saveConfig(searchConfig);
|
|
if (success) {
|
|
if (window.KefinTweaksToaster && window.KefinTweaksToaster.toast) {
|
|
window.KefinTweaksToaster.toast('Search configuration saved!');
|
|
}
|
|
window.ModalSystem.close(MODAL_ID);
|
|
} else {
|
|
alert('Error saving configuration. Please ensure the JavaScript Injector plugin is installed and you have administrator permissions.');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
LOG('Search configuration modal opened');
|
|
} catch (error) {
|
|
ERR('Error opening search config modal:', error);
|
|
alert('Error opening configuration: ' + error.message);
|
|
}
|
|
}
|
|
|
|
// Export
|
|
window.KefinTweaksFeatureConfigs = window.KefinTweaksFeatureConfigs || {};
|
|
window.KefinTweaksFeatureConfigs.search = { openConfigModal };
|
|
|
|
console.log('[KefinTweaks Search Config] Script loaded');
|
|
|
|
})();
|
|
|