blob: 6c3004a9a1fa21214157acb1b8ea27264b38f579 [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
Adrià Vilanova Martínezc9daf852022-06-01 00:35:53 +020014// @ts-ignore #!if ['chromium', 'chromium_mv3'].includes(browser_target)
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +020015const 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;
Adrià Vilanova Martínez33ee9cd2022-06-01 01:06:53 +020052 font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI',
53 Helvetica, Arial, sans-serif, 'Apple Color Emoji',
54 'Segoe UI Emoji', 'Segoe UI Symbol'!important;
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020055 }
avm999634a2a5d52016-06-04 16:17:29 +020056
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020057 #credits_container {
58 position: absolute;
59 top: 0px;
60 inset-inline-end: 50px;
Adrià Vilanova Martínezb9180ef2022-05-29 20:26:43 +020061 background: #e3f2fd;
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020062 border: solid 1px rgb(139, 139, 139);
63 border-top: 0;
64 border-radius: 0px 0px 5px 5px;
65 }
avm999634a2a5d52016-06-04 16:17:29 +020066
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020067 #credits_container button#credits {
Adrià Vilanova Martínezb9180ef2022-05-29 20:26:43 +020068 color: #1f649d!important;
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020069 margin: 0 5px;
70 padding: 1px 3px;
71 text-decoration: underline;
72 cursor: pointer;
73 }
74 `,
75 ];
avm999635a57c412020-12-27 00:26:45 +010076 }
avm999634a2a5d52016-06-04 16:17:29 +020077
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020078 render() {
79 return html`
80 <div id="credits_container">
81 <button
82 @click="${this.showCredits}" id="credits"
83 class="notbtn" tabindex="0" role="button">
84 ${msg('options_credits')}
85 </button>
86 </div>
87 <h1 id="welcome">${msg('options_welcome')}</h1>
88 <p id="introduction">${msg('options_introduction')}</p>
89 <options-editor .storageData=${this._storageData}></options-editor>
90 <credits-dialog></credits-dialog>
91 `;
92 }
93
94 updateStorageData() {
Adrià Vilanova Martínez53f7a7f2022-05-30 13:59:59 +020095 Options.getOptions(/* readOnly = */ true)
96 .then(options => {
97 this._storageData = {
98 translateinto: options.targetLangs,
99 uniquetab: options.uniqueTab,
100 };
101 })
102 .catch(err => {
103 console.error('Error retrieving user options.', err);
104 });
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +0200105 }
106
107 showCredits() {
108 const e =
109 new CustomEvent('show-credits-dialog', {bubbles: true, composed: true});
110 this.renderRoot.querySelector('credits-dialog').dispatchEvent(e);
111 }
112}