blob: 4ee6e35eb80c2c01ac828a23ced379e96e806b2b [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íneza197d862022-05-27 17:33:20 +02004
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +02005import CreditsDialog from './elements/credits-dialog/credits-dialog.js';
6import OptionsEditor from './elements/options-editor/options-editor.js';
Adrià Vilanova Martínez915e15a2022-05-27 19:14:25 +02007
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íneze5263f12022-05-29 19:22:13 +020010export class OptionsPage extends LitElement {
11 static properties = {
12 _storageData: {type: Object, state: true},
avm999630f961162020-12-27 13:12:27 +010013 }
14
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020015 constructor() {
16 super();
17 this._storageData = undefined;
18 this.updateStorageData();
19 chrome.storage.onChanged.addListener((changes, areaName) => {
20 if (areaName == 'sync') this.updateStorageData();
avm99963a0036412020-12-29 13:39:05 +010021 });
avm999635a57c412020-12-27 00:26:45 +010022 }
avm999634a2a5d52016-06-04 16:17:29 +020023
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020024 static get styles() {
25 return [
26 SHARED_STYLES,
27 css`
28 :host {
29 display: block;
30 padding: 10px;
31 margin: 14px 17px;
32 font-family: "Roboto", "Arial", sans-serif!important;
33 }
avm999634a2a5d52016-06-04 16:17:29 +020034
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020035 #credits_container {
36 position: absolute;
37 top: 0px;
38 inset-inline-end: 50px;
Adrià Vilanova Martínezb9180ef2022-05-29 20:26:43 +020039 background: #e3f2fd;
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020040 border: solid 1px rgb(139, 139, 139);
41 border-top: 0;
42 border-radius: 0px 0px 5px 5px;
43 }
avm999634a2a5d52016-06-04 16:17:29 +020044
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020045 #credits_container button#credits {
Adrià Vilanova Martínezb9180ef2022-05-29 20:26:43 +020046 color: #1f649d!important;
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020047 margin: 0 5px;
48 padding: 1px 3px;
49 text-decoration: underline;
50 cursor: pointer;
51 }
52 `,
53 ];
avm999635a57c412020-12-27 00:26:45 +010054 }
avm999634a2a5d52016-06-04 16:17:29 +020055
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020056 render() {
57 return html`
58 <div id="credits_container">
59 <button
60 @click="${this.showCredits}" id="credits"
61 class="notbtn" tabindex="0" role="button">
62 ${msg('options_credits')}
63 </button>
64 </div>
65 <h1 id="welcome">${msg('options_welcome')}</h1>
66 <p id="introduction">${msg('options_introduction')}</p>
67 <options-editor .storageData=${this._storageData}></options-editor>
68 <credits-dialog></credits-dialog>
69 `;
70 }
71
72 updateStorageData() {
73 chrome.storage.sync.get(null, items => {
74 // If no settings are set
75 if (Object.keys(items).length === 0) {
76 items = {
77 translateinto: {},
78 uniquetab: 'popup',
79 };
80 chrome.storage.sync.set(items);
81 }
82 this._storageData = items;
83 });
84 }
85
86 showCredits() {
87 const e =
88 new CustomEvent('show-credits-dialog', {bubbles: true, composed: true});
89 this.renderRoot.querySelector('credits-dialog').dispatchEvent(e);
90 }
91}
92customElements.define('options-page', OptionsPage);