Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame^] | 1 | import './elements/credits-dialog/credits-dialog'; |
| 2 | import './elements/options-editor/options-editor'; |
| 3 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 4 | import {css, html, LitElement} from 'lit'; |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame^] | 5 | import {customElement, property} from 'lit/decorators.js'; |
Adrià Vilanova Martínez | a197d86 | 2022-05-27 17:33:20 +0200 | [diff] [blame] | 6 | |
Adrià Vilanova Martínez | 5bdc473 | 2022-05-31 20:12:21 +0200 | [diff] [blame] | 7 | import {msg} from '../common/i18n'; |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame^] | 8 | import {default as Options, OptionsV0} from '../common/options'; |
Adrià Vilanova Martínez | a197d86 | 2022-05-27 17:33:20 +0200 | [diff] [blame] | 9 | |
Adrià Vilanova Martínez | 5bdc473 | 2022-05-31 20:12:21 +0200 | [diff] [blame] | 10 | import {SHARED_STYLES} from './shared/shared-styles'; |
Adrià Vilanova Martínez | a197d86 | 2022-05-27 17:33:20 +0200 | [diff] [blame] | 11 | |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame^] | 12 | const bodyStyles = document.createElement('style'); |
| 13 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 14 | // @ts-ignore #!if browser_target == 'chromium' |
| 15 | const widthProperty = 'width: 470px;'; |
| 16 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 17 | // @ts-ignore #!else |
| 18 | const widthProperty = ''; |
Adrià Vilanova Martínez | 8b63fb3 | 2022-05-29 23:26:50 +0200 | [diff] [blame] | 19 | // #!endif |
| 20 | bodyStyles.textContent = ` |
| 21 | body { |
| 22 | margin: 0; |
| 23 | padding: 0; |
| 24 | font-size: 90%; |
| 25 | ${widthProperty} |
| 26 | } |
| 27 | `; |
| 28 | |
| 29 | document.head.append(bodyStyles); |
| 30 | |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame^] | 31 | @customElement('options-page') |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 32 | export class OptionsPage extends LitElement { |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame^] | 33 | @property({type: Object, state: true}) _storageData: OptionsV0; |
avm99963 | 0f96116 | 2020-12-27 13:12:27 +0100 | [diff] [blame] | 34 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 35 | constructor() { |
| 36 | super(); |
| 37 | this._storageData = undefined; |
| 38 | this.updateStorageData(); |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame^] | 39 | chrome.storage.onChanged.addListener((_changes, areaName) => { |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 40 | if (areaName == 'sync') this.updateStorageData(); |
avm99963 | a003641 | 2020-12-29 13:39:05 +0100 | [diff] [blame] | 41 | }); |
avm99963 | 5a57c41 | 2020-12-27 00:26:45 +0100 | [diff] [blame] | 42 | } |
avm99963 | 4a2a5d5 | 2016-06-04 16:17:29 +0200 | [diff] [blame] | 43 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 44 | 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 | } |
avm99963 | 4a2a5d5 | 2016-06-04 16:17:29 +0200 | [diff] [blame] | 54 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 55 | #credits_container { |
| 56 | position: absolute; |
| 57 | top: 0px; |
| 58 | inset-inline-end: 50px; |
Adrià Vilanova Martínez | b9180ef | 2022-05-29 20:26:43 +0200 | [diff] [blame] | 59 | background: #e3f2fd; |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 60 | border: solid 1px rgb(139, 139, 139); |
| 61 | border-top: 0; |
| 62 | border-radius: 0px 0px 5px 5px; |
| 63 | } |
avm99963 | 4a2a5d5 | 2016-06-04 16:17:29 +0200 | [diff] [blame] | 64 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 65 | #credits_container button#credits { |
Adrià Vilanova Martínez | b9180ef | 2022-05-29 20:26:43 +0200 | [diff] [blame] | 66 | color: #1f649d!important; |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 67 | margin: 0 5px; |
| 68 | padding: 1px 3px; |
| 69 | text-decoration: underline; |
| 70 | cursor: pointer; |
| 71 | } |
| 72 | `, |
| 73 | ]; |
avm99963 | 5a57c41 | 2020-12-27 00:26:45 +0100 | [diff] [blame] | 74 | } |
avm99963 | 4a2a5d5 | 2016-06-04 16:17:29 +0200 | [diff] [blame] | 75 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 76 | 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ínez | 53f7a7f | 2022-05-30 13:59:59 +0200 | [diff] [blame] | 93 | 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ínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 103 | } |
| 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 | } |