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 | a197d86 | 2022-05-27 17:33:20 +0200 | [diff] [blame] | 4 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 5 | import CreditsDialog from './elements/credits-dialog/credits-dialog.js'; |
| 6 | import OptionsEditor from './elements/options-editor/options-editor.js'; |
Adrià Vilanova Martínez | 915e15a | 2022-05-27 19:14:25 +0200 | [diff] [blame] | 7 | |
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 | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 10 | export class OptionsPage extends LitElement { |
| 11 | static properties = { |
| 12 | _storageData: {type: Object, state: true}, |
avm99963 | 0f96116 | 2020-12-27 13:12:27 +0100 | [diff] [blame] | 13 | } |
| 14 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 15 | constructor() { |
| 16 | super(); |
| 17 | this._storageData = undefined; |
| 18 | this.updateStorageData(); |
| 19 | chrome.storage.onChanged.addListener((changes, areaName) => { |
| 20 | if (areaName == 'sync') this.updateStorageData(); |
avm99963 | a003641 | 2020-12-29 13:39:05 +0100 | [diff] [blame] | 21 | }); |
avm99963 | 5a57c41 | 2020-12-27 00:26:45 +0100 | [diff] [blame] | 22 | } |
avm99963 | 4a2a5d5 | 2016-06-04 16:17:29 +0200 | [diff] [blame] | 23 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 24 | 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 | } |
avm99963 | 4a2a5d5 | 2016-06-04 16:17:29 +0200 | [diff] [blame] | 34 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 35 | #credits_container { |
| 36 | position: absolute; |
| 37 | top: 0px; |
| 38 | inset-inline-end: 50px; |
Adrià Vilanova Martínez | b9180ef | 2022-05-29 20:26:43 +0200 | [diff] [blame] | 39 | background: #e3f2fd; |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 40 | border: solid 1px rgb(139, 139, 139); |
| 41 | border-top: 0; |
| 42 | border-radius: 0px 0px 5px 5px; |
| 43 | } |
avm99963 | 4a2a5d5 | 2016-06-04 16:17:29 +0200 | [diff] [blame] | 44 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 45 | #credits_container button#credits { |
Adrià Vilanova Martínez | b9180ef | 2022-05-29 20:26:43 +0200 | [diff] [blame] | 46 | color: #1f649d!important; |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 47 | margin: 0 5px; |
| 48 | padding: 1px 3px; |
| 49 | text-decoration: underline; |
| 50 | cursor: pointer; |
| 51 | } |
| 52 | `, |
| 53 | ]; |
avm99963 | 5a57c41 | 2020-12-27 00:26:45 +0100 | [diff] [blame] | 54 | } |
avm99963 | 4a2a5d5 | 2016-06-04 16:17:29 +0200 | [diff] [blame] | 55 | |
Adrià Vilanova Martínez | e5263f1 | 2022-05-29 19:22:13 +0200 | [diff] [blame] | 56 | 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 | } |
| 92 | customElements.define('options-page', OptionsPage); |