blob: 7a16ef9aedcd888c9d777d1da39921644fb80a11 [file] [log] [blame]
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +02001import {css, html, LitElement} from 'lit';
Adrià Vilanova Martíneza197d862022-05-27 17:33:20 +02002
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +02003import {msg} from '../common/i18n.js';
Adrià Vilanova Martínez53f7a7f2022-05-30 13:59:59 +02004import Options from '../common/options.js';
Adrià Vilanova Martíneza197d862022-05-27 17:33:20 +02005
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +02006import CreditsDialog from './elements/credits-dialog/credits-dialog.js';
7import OptionsEditor from './elements/options-editor/options-editor.js';
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +02008import {SHARED_STYLES} from './shared/shared-styles.js';
Adrià Vilanova Martíneza197d862022-05-27 17:33:20 +02009
Adrià Vilanova Martínez8b63fb32022-05-29 23:26:50 +020010let bodyStyles = document.createElement('style');
11// #!if browser_target == 'chromium'
12let widthProperty = 'width: 470px;';
13// #!else
14let widthProperty = '';
15// #!endif
16bodyStyles.textContent = `
17 body {
18 margin: 0;
19 padding: 0;
20 font-size: 90%;
21 ${widthProperty}
22 }
23`;
24
25document.head.append(bodyStyles);
26
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020027export class OptionsPage extends LitElement {
28 static properties = {
29 _storageData: {type: Object, state: true},
avm999630f961162020-12-27 13:12:27 +010030 }
31
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020032 constructor() {
33 super();
34 this._storageData = undefined;
35 this.updateStorageData();
36 chrome.storage.onChanged.addListener((changes, areaName) => {
37 if (areaName == 'sync') this.updateStorageData();
avm99963a0036412020-12-29 13:39:05 +010038 });
avm999635a57c412020-12-27 00:26:45 +010039 }
avm999634a2a5d52016-06-04 16:17:29 +020040
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020041 static get styles() {
42 return [
43 SHARED_STYLES,
44 css`
45 :host {
46 display: block;
47 padding: 10px;
48 margin: 14px 17px;
49 font-family: "Roboto", "Arial", sans-serif!important;
50 }
avm999634a2a5d52016-06-04 16:17:29 +020051
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020052 #credits_container {
53 position: absolute;
54 top: 0px;
55 inset-inline-end: 50px;
Adrià Vilanova Martínezb9180ef2022-05-29 20:26:43 +020056 background: #e3f2fd;
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020057 border: solid 1px rgb(139, 139, 139);
58 border-top: 0;
59 border-radius: 0px 0px 5px 5px;
60 }
avm999634a2a5d52016-06-04 16:17:29 +020061
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020062 #credits_container button#credits {
Adrià Vilanova Martínezb9180ef2022-05-29 20:26:43 +020063 color: #1f649d!important;
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020064 margin: 0 5px;
65 padding: 1px 3px;
66 text-decoration: underline;
67 cursor: pointer;
68 }
69 `,
70 ];
avm999635a57c412020-12-27 00:26:45 +010071 }
avm999634a2a5d52016-06-04 16:17:29 +020072
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020073 render() {
74 return html`
75 <div id="credits_container">
76 <button
77 @click="${this.showCredits}" id="credits"
78 class="notbtn" tabindex="0" role="button">
79 ${msg('options_credits')}
80 </button>
81 </div>
82 <h1 id="welcome">${msg('options_welcome')}</h1>
83 <p id="introduction">${msg('options_introduction')}</p>
84 <options-editor .storageData=${this._storageData}></options-editor>
85 <credits-dialog></credits-dialog>
86 `;
87 }
88
89 updateStorageData() {
Adrià Vilanova Martínez53f7a7f2022-05-30 13:59:59 +020090 Options.getOptions(/* readOnly = */ true)
91 .then(options => {
92 this._storageData = {
93 translateinto: options.targetLangs,
94 uniquetab: options.uniqueTab,
95 };
96 })
97 .catch(err => {
98 console.error('Error retrieving user options.', err);
99 });
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +0200100 }
101
102 showCredits() {
103 const e =
104 new CustomEvent('show-credits-dialog', {bubbles: true, composed: true});
105 this.renderRoot.querySelector('credits-dialog').dispatchEvent(e);
106 }
107}
108customElements.define('options-page', OptionsPage);