Allow imports in custom CSS. Confirm import usage on theme adding.

This commit is contained in:
Cohee 2024-03-15 00:20:46 +02:00
parent 2369d35846
commit 60ea9df55e

View File

@ -1074,13 +1074,6 @@ async function applyThemeColor(type) {
async function applyCustomCSS() {
power_user.custom_css = String(localStorage.getItem(storage_keys.custom_css) ?? '');
if (power_user.custom_css.includes('@import')) {
var removeImport = /@import[^;]+;/gm;
power_user.custom_css = power_user.custom_css.replace(removeImport, '');
localStorage.setItem(storage_keys.custom_css, power_user.custom_css);
toastr.warning('@import not allowed in Custom CSS. @import lines removed.');
}
$('#customCSS').val(power_user.custom_css);
var styleId = 'custom-style';
var style = document.getElementById(styleId);
@ -2026,6 +2019,13 @@ async function importTheme(file) {
throw new Error('Theme with that name already exists');
}
if (parsed.custom_css.includes('@import')) {
const confirm = await callPopup('This theme contains @import lines in the Custom CSS. Press "Yes" to proceed.', 'confirm', '', { okButton: 'Yes' });
if (!confirm) {
throw new Error('Theme contains @import lines');
}
}
themes.push(parsed);
await applyTheme(parsed.name);
await saveTheme(parsed.name);