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