mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 19:09:59 +02:00
Merge pull request #17 from JosueGalRe/main
feature: add string type theme property
This commit is contained in:
commit
64fa2931eb
1 changed files with 41 additions and 15 deletions
|
@ -146,6 +146,12 @@ var gZenThemeImporter = new (class {
|
||||||
|
|
||||||
for (const theme of Object.values(await this.getThemes())) {
|
for (const theme of Object.values(await this.getThemes())) {
|
||||||
const { preferences, areOldPreferences } = await this._getThemePreferences(theme);
|
const { preferences, areOldPreferences } = await this._getThemePreferences(theme);
|
||||||
|
|
||||||
|
if (areOldPreferences) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const filteredPreferences = preferences.filter(({ type }) => type !== 'checkbox');
|
||||||
const sanitizedName = `theme-${theme.name?.replaceAll(/\s/g, '-')?.replaceAll(/[^A-z_-]+/g, '')}`;
|
const sanitizedName = `theme-${theme.name?.replaceAll(/\s/g, '-')?.replaceAll(/[^A-z_-]+/g, '')}`;
|
||||||
|
|
||||||
if (!theme.enabled) {
|
if (!theme.enabled) {
|
||||||
|
@ -155,18 +161,23 @@ var gZenThemeImporter = new (class {
|
||||||
element.remove();
|
element.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const { property } of filteredPreferences) {
|
||||||
|
const sanitizedProperty = property?.replaceAll(/\./g, '-');
|
||||||
|
|
||||||
|
if (document.querySelector(':root').style.hasProperty(`--${sanitizedProperty}`)) {
|
||||||
|
document.querySelector(':root').style.removeProperty(`--${sanitizedProperty}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (areOldPreferences) {
|
for (const { property, type } of preferences) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const themePreferences = preferences.filter(({ type }) => type === 'dropdown');
|
|
||||||
|
|
||||||
for (const { property } of themePreferences) {
|
|
||||||
const value = Services.prefs.getStringPref(property, '');
|
const value = Services.prefs.getStringPref(property, '');
|
||||||
|
const sanitizedProperty = property?.replaceAll(/\./g, '-');
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 'dropdown': {
|
||||||
if (value !== '') {
|
if (value !== '') {
|
||||||
let element = browser.document.getElementById(sanitizedName);
|
let element = browser.document.getElementById(sanitizedName);
|
||||||
|
|
||||||
|
@ -179,7 +190,22 @@ var gZenThemeImporter = new (class {
|
||||||
browser.document.body.appendChild(element);
|
browser.document.body.appendChild(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
element.setAttribute(property?.replaceAll(/\./g, '-'), value);
|
element.setAttribute(sanitizedProperty, value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'string': {
|
||||||
|
if (value === '') {
|
||||||
|
document.querySelector(':root').style.removeProperty(`--${sanitizedProperty}`);
|
||||||
|
} else {
|
||||||
|
document.querySelector(':root').style.setProperty(`--${sanitizedProperty}`, value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue