Add optionsGroup

This commit is contained in:
redphx 2024-07-15 17:10:07 +07:00
parent 7409956616
commit 368a6f726a
3 changed files with 12 additions and 1 deletions

View File

@ -1,5 +1,6 @@
export type PreferenceSetting = {
default: any;
optionsGroup?: string;
options?: {[index: string]: string};
multipleOptions?: {[index: string]: string};
unsupported?: string | boolean;

View File

@ -130,6 +130,7 @@ export class Preferences {
label: t('bypass-region-restriction'),
note: '⚠️ ' + t('use-this-at-your-own-risk'),
default: 'off',
optionsGroup: t('region'),
options: Object.assign({
'off': t('off'),
}, BypassServers),

View File

@ -30,11 +30,20 @@ export class SettingElement {
// title: setting.label,
tabindex: 0,
}) as HTMLSelectElement;
let $parent: HTMLElement;
if (setting.optionsGroup) {
$parent = CE('optgroup', {'label': setting.optionsGroup});
$control.appendChild($parent);
} else {
$parent = $control;
}
for (let value in setting.options) {
const label = setting.options[value];
const $option = CE<HTMLOptionElement>('option', {value: value}, label);
$control.appendChild($option);
$parent.appendChild($option);
}
$control.value = currentValue;