blob: 9e32dfab3644e2dc5336554265791d46ab9d05a5 [file] [log] [blame]
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +02001import {css, html, LitElement} from 'lit';
2import {map} from 'lit/directives/map.js';
3
4import {msg} from '../../../common/i18n.js';
5import {SHARED_STYLES} from '../../shared/shared-styles.js';
6
7import LanguagesEditor from './languages-editor.js';
8
9const TAB_OPTIONS = [
10 // Open in new tab for each translation
11 {
12 value: '',
13 labelMsg: 'options_tabsoption_1',
14 deprecatedValues: [],
15 },
16 // Open in a unique tab
17 {
18 value: 'yep',
19 labelMsg: 'options_tabsoption_2',
20 deprecatedValues: [],
21 },
22 // Open in a popup
23 {
24 value: 'popup',
25 labelMsg: 'options_tabsoption_3',
26 deprecatedValues: ['panel'],
27 },
28];
29
30export class OptionsEditor extends LitElement {
31 static properties = {
32 storageData: {type: Object},
33 };
34
35 static get styles() {
36 return [
37 SHARED_STYLES,
38 css`
39 #otheroptions p {
40 margin-top: 0;
41 margin-bottom: 8px;
42 }
43 `,
44 ];
45 }
46
47 constructor() {
48 super();
49 this.addEventListener('show-credits-dialog', this.showDialog);
50 }
51
52 render() {
53 let currentTabOption = this.storageData?.uniquetab;
54
55 let otherOptions = map(TAB_OPTIONS, (option, i) => {
56 let checked = option.value == currentTabOption ||
57 option.deprecatedValues.includes(currentTabOption);
58 return html`
59 <p>
60 <input type="radio" name="uniquetab" id="uniquetab_${i}"
61 value="${option?.value}" ?checked="${checked}"
62 @change="${() => this.changeTabOption(option.value)}">
63 <label for="uniquetab_${i}">${msg(option.labelMsg)}</label></p>
64 `;
65 });
66
67 return html`
68 <languages-editor .languages="${this.storageData?.translateinto}">
69 </languages-editor>
70
71 <h2 id="otheroptionsheader">${msg('options_otheroptionsheader')}</h2>
72
73 <div id="otheroptions">
74 ${otherOptions}
75 </div>
76 `;
77 }
78
79 changeTabOption(value) {
80 chrome.storage.sync.set({uniquetab: value}, function() {
81 var background = chrome.extension.getBackgroundPage();
82
83 background.translator_tab = false;
84 background.translator_window = false;
85 });
86 }
87}
88customElements.define('options-editor', OptionsEditor);