blob: 6cdcec9cf1dfdb8c466c57f7906eac2e307b8159 [file] [log] [blame]
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +02001import './elements/credits-dialog/credits-dialog';
2import './elements/options-editor/options-editor';
3
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +02004import {css, html, LitElement} from 'lit';
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +02005import {customElement, property} from 'lit/decorators.js';
Adrià Vilanova Martíneza197d862022-05-27 17:33:20 +02006
Adrià Vilanova Martínez5bdc4732022-05-31 20:12:21 +02007import {msg} from '../common/i18n';
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +02008import {default as Options, OptionsV0} from '../common/options';
Adrià Vilanova Martíneza197d862022-05-27 17:33:20 +02009
Adrià Vilanova Martínez5bdc4732022-05-31 20:12:21 +020010import {SHARED_STYLES} from './shared/shared-styles';
Adrià Vilanova Martíneza197d862022-05-27 17:33:20 +020011
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +020012const bodyStyles = document.createElement('style');
13// eslint-disable-next-line @typescript-eslint/ban-ts-comment
14// @ts-ignore #!if browser_target == 'chromium'
15const widthProperty = 'width: 470px;';
16// eslint-disable-next-line @typescript-eslint/ban-ts-comment
17// @ts-ignore #!else
18const widthProperty = '';
Adrià Vilanova Martínez8b63fb32022-05-29 23:26:50 +020019// #!endif
20bodyStyles.textContent = `
21 body {
22 margin: 0;
23 padding: 0;
24 font-size: 90%;
25 ${widthProperty}
26 }
27`;
28
29document.head.append(bodyStyles);
30
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +020031@customElement('options-page')
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020032export class OptionsPage extends LitElement {
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +020033 @property({type: Object, state: true}) _storageData: OptionsV0;
avm999630f961162020-12-27 13:12:27 +010034
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020035 constructor() {
36 super();
37 this._storageData = undefined;
38 this.updateStorageData();
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +020039 chrome.storage.onChanged.addListener((_changes, areaName) => {
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020040 if (areaName == 'sync') this.updateStorageData();
avm99963a0036412020-12-29 13:39:05 +010041 });
avm999635a57c412020-12-27 00:26:45 +010042 }
avm999634a2a5d52016-06-04 16:17:29 +020043
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020044 static get styles() {
45 return [
46 SHARED_STYLES,
47 css`
48 :host {
49 display: block;
50 padding: 10px;
51 margin: 14px 17px;
52 font-family: "Roboto", "Arial", sans-serif!important;
53 }
avm999634a2a5d52016-06-04 16:17:29 +020054
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020055 #credits_container {
56 position: absolute;
57 top: 0px;
58 inset-inline-end: 50px;
Adrià Vilanova Martínezb9180ef2022-05-29 20:26:43 +020059 background: #e3f2fd;
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020060 border: solid 1px rgb(139, 139, 139);
61 border-top: 0;
62 border-radius: 0px 0px 5px 5px;
63 }
avm999634a2a5d52016-06-04 16:17:29 +020064
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020065 #credits_container button#credits {
Adrià Vilanova Martínezb9180ef2022-05-29 20:26:43 +020066 color: #1f649d!important;
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020067 margin: 0 5px;
68 padding: 1px 3px;
69 text-decoration: underline;
70 cursor: pointer;
71 }
72 `,
73 ];
avm999635a57c412020-12-27 00:26:45 +010074 }
avm999634a2a5d52016-06-04 16:17:29 +020075
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020076 render() {
77 return html`
78 <div id="credits_container">
79 <button
80 @click="${this.showCredits}" id="credits"
81 class="notbtn" tabindex="0" role="button">
82 ${msg('options_credits')}
83 </button>
84 </div>
85 <h1 id="welcome">${msg('options_welcome')}</h1>
86 <p id="introduction">${msg('options_introduction')}</p>
87 <options-editor .storageData=${this._storageData}></options-editor>
88 <credits-dialog></credits-dialog>
89 `;
90 }
91
92 updateStorageData() {
Adrià Vilanova Martínez53f7a7f2022-05-30 13:59:59 +020093 Options.getOptions(/* readOnly = */ true)
94 .then(options => {
95 this._storageData = {
96 translateinto: options.targetLangs,
97 uniquetab: options.uniqueTab,
98 };
99 })
100 .catch(err => {
101 console.error('Error retrieving user options.', err);
102 });
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +0200103 }
104
105 showCredits() {
106 const e =
107 new CustomEvent('show-credits-dialog', {bubbles: true, composed: true});
108 this.renderRoot.querySelector('credits-dialog').dispatchEvent(e);
109 }
110}