Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 1 | import {css, html, LitElement} from 'lit'; |
| 2 | import {map} from 'lit/directives/map.js'; |
| 3 | |
| 4 | import {msg} from '../../../common/i18n.js'; |
Adrià Vilanova Martínez | 53f7a7f | 2022-05-30 13:59:59 +0200 | [diff] [blame^] | 5 | import {TAB_OPTIONS} from '../../../common/options.js'; |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 6 | import {SHARED_STYLES} from '../../shared/shared-styles.js'; |
| 7 | |
| 8 | import LanguagesEditor from './languages-editor.js'; |
| 9 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 10 | export class OptionsEditor extends LitElement { |
| 11 | static properties = { |
| 12 | storageData: {type: Object}, |
| 13 | }; |
| 14 | |
| 15 | static get styles() { |
| 16 | return [ |
| 17 | SHARED_STYLES, |
| 18 | css` |
| 19 | #otheroptions p { |
| 20 | margin-top: 0; |
| 21 | margin-bottom: 8px; |
| 22 | } |
| 23 | `, |
| 24 | ]; |
| 25 | } |
| 26 | |
| 27 | constructor() { |
| 28 | super(); |
| 29 | this.addEventListener('show-credits-dialog', this.showDialog); |
| 30 | } |
| 31 | |
| 32 | render() { |
| 33 | let currentTabOption = this.storageData?.uniquetab; |
| 34 | |
| 35 | let otherOptions = map(TAB_OPTIONS, (option, i) => { |
| 36 | let checked = option.value == currentTabOption || |
| 37 | option.deprecatedValues.includes(currentTabOption); |
| 38 | return html` |
| 39 | <p> |
| 40 | <input type="radio" name="uniquetab" id="uniquetab_${i}" |
Adrià Vilanova Martínez | 53f7a7f | 2022-05-30 13:59:59 +0200 | [diff] [blame^] | 41 | value="${option?.value}" .checked="${checked}" |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 42 | @change="${() => this.changeTabOption(option.value)}"> |
| 43 | <label for="uniquetab_${i}">${msg(option.labelMsg)}</label></p> |
| 44 | `; |
| 45 | }); |
| 46 | |
| 47 | return html` |
| 48 | <languages-editor .languages="${this.storageData?.translateinto}"> |
| 49 | </languages-editor> |
| 50 | |
| 51 | <h2 id="otheroptionsheader">${msg('options_otheroptionsheader')}</h2> |
| 52 | |
| 53 | <div id="otheroptions"> |
| 54 | ${otherOptions} |
| 55 | </div> |
| 56 | `; |
| 57 | } |
| 58 | |
| 59 | changeTabOption(value) { |
| 60 | chrome.storage.sync.set({uniquetab: value}, function() { |
| 61 | var background = chrome.extension.getBackgroundPage(); |
| 62 | |
| 63 | background.translator_tab = false; |
| 64 | background.translator_window = false; |
| 65 | }); |
| 66 | } |
| 67 | } |
| 68 | customElements.define('options-editor', OptionsEditor); |