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 |
Adrià Vilanova Martínez | c9daf85 | 2022-06-01 00:35:53 +0200 | [diff] [blame] | 14 | // @ts-ignore #!if ['chromium', 'chromium_mv3'].includes(browser_target) |
Adrià Vilanova Martínez | 2b50e91 | 2022-06-01 00:05:40 +0200 | [diff] [blame] | 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; |
Adrià Vilanova Martínez | 33ee9cd | 2022-06-01 01:06:53 +0200 | [diff] [blame] | 52 | 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ínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 55 | } |
avm99963 | 4a2a5d5 | 2016-06-04 16:17:29 +0200 | [diff] [blame] | 56 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 57 | #credits_container { |
| 58 | position: absolute; |
| 59 | top: 0px; |
| 60 | inset-inline-end: 50px; |
Adrià Vilanova Martínez | b9180ef | 2022-05-29 20:26:43 +0200 | [diff] [blame] | 61 | background: #e3f2fd; |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 62 | border: solid 1px rgb(139, 139, 139); |
| 63 | border-top: 0; |
| 64 | border-radius: 0px 0px 5px 5px; |
| 65 | } |
avm99963 | 4a2a5d5 | 2016-06-04 16:17:29 +0200 | [diff] [blame] | 66 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 67 | #credits_container button#credits { |
Adrià Vilanova Martínez | b9180ef | 2022-05-29 20:26:43 +0200 | [diff] [blame] | 68 | color: #1f649d!important; |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 69 | margin: 0 5px; |
| 70 | padding: 1px 3px; |
| 71 | text-decoration: underline; |
| 72 | cursor: pointer; |
| 73 | } |
| 74 | `, |
| 75 | ]; |
avm99963 | 5a57c41 | 2020-12-27 00:26:45 +0100 | [diff] [blame] | 76 | } |
avm99963 | 4a2a5d5 | 2016-06-04 16:17:29 +0200 | [diff] [blame] | 77 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 78 | 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ínez | 53f7a7f | 2022-05-30 13:59:59 +0200 | [diff] [blame] | 95 | 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ínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 105 | } |
| 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 | } |