|
| 1 | +// @ts-check |
| 2 | + |
| 3 | +import {country, isHCountry} from './locales.js'; |
| 4 | +import { |
| 5 | + createHTMLElement as html, |
| 6 | + $, |
| 7 | +} from './utils.js'; |
| 8 | +import {clicker} from './stats.js'; |
| 9 | + |
| 10 | +const safariURL = 'https://apps.apple.com/us/app/dark-reader-for-safari/id1438243180'; |
| 11 | + |
| 12 | +const htmlText = ` |
| 13 | +<section class="container"> |
| 14 | + <i class="safari-icon"></i> |
| 15 | + <section class="content"> |
| 16 | + <div class="label"><span class="dark-reader">Dark Reader</span> for Safari</div> |
| 17 | + <div class="description"> |
| 18 | + Get access to the latest features<br> |
| 19 | + on macOS, iOS and iPadOS. |
| 20 | + </div> |
| 21 | + <div class="links"> |
| 22 | + <a class="badge-link" href="${safariURL}" target="_blank" rel="noopener" data-s="drsafari-top-badge"> |
| 23 | + <img src="/images/app-store-badge.svg"> |
| 24 | + </a> |
| 25 | + <a class="text-link" href="${safariURL}" target="_blank" rel="noopener" data-s="drsafari-top-text"> |
| 26 | + Learn more |
| 27 | + </a> |
| 28 | + </div> |
| 29 | + </section> |
| 30 | +</section>`; |
| 31 | + |
| 32 | +const cssText = ` |
| 33 | +.container { |
| 34 | + align-items: flex-start; |
| 35 | + display: flex; |
| 36 | + flex-direction: row; |
| 37 | + gap: 1rem; |
| 38 | + justify-content: center; |
| 39 | + padding-top: 0; |
| 40 | +} |
| 41 | +:host { |
| 42 | + container-type: inline-size; |
| 43 | + width: 100%; |
| 44 | +} |
| 45 | +.safari-icon { |
| 46 | + background-image: url(/images/icon-safari-66x66.svg); |
| 47 | + background-position: center; |
| 48 | + background-repeat: no-repeat; |
| 49 | + background-size: cover; |
| 50 | + display: inline-block; |
| 51 | + height: 7rem; |
| 52 | + margin-top: 0.5rem; |
| 53 | + width: 7rem; |
| 54 | +} |
| 55 | +.content { |
| 56 | + color: var(--color-text); |
| 57 | + display: flex; |
| 58 | + flex-direction: column; |
| 59 | + gap: 0.5rem; |
| 60 | +} |
| 61 | +.label { |
| 62 | + color: var(--color-highlight); |
| 63 | + font-size: 1.35rem; |
| 64 | + font-weight: bold; |
| 65 | + line-height: 1; |
| 66 | + -webkit-text-stroke: 0.0625rem; |
| 67 | +} |
| 68 | +.links { |
| 69 | + align-items: center; |
| 70 | + display: flex; |
| 71 | + flex-direction: row; |
| 72 | + gap: 0.75rem; |
| 73 | +} |
| 74 | +.badge-link { |
| 75 | + display: inline-block; |
| 76 | +} |
| 77 | +.badge-link img { |
| 78 | + display: inline-block; |
| 79 | + width: 8rem; |
| 80 | +} |
| 81 | +.text-link { |
| 82 | + color: var(--color-text); |
| 83 | + transition: color 250ms; |
| 84 | +} |
| 85 | +.text-link:hover { |
| 86 | + color: white; |
| 87 | +} |
| 88 | +@container (width >= 28rem) { |
| 89 | +} |
| 90 | +`; |
| 91 | + |
| 92 | +class SafariTopShortElement extends HTMLElement { |
| 93 | + constructor() { |
| 94 | + super(); |
| 95 | + const shadowRoot = this.attachShadow({mode: 'open'}); |
| 96 | + |
| 97 | + const style = html('style', {}, cssText); |
| 98 | + shadowRoot.append(style); |
| 99 | + style.insertAdjacentHTML('afterend', htmlText); |
| 100 | + |
| 101 | + if (this.hasAttribute('side')) { |
| 102 | + shadowRoot.querySelectorAll('[data-s]').forEach((node) => { |
| 103 | + const s = node.getAttribute('data-s') ?? ''; |
| 104 | + node.setAttribute('data-s', s.replace('-top-', '-side-')); |
| 105 | + }); |
| 106 | + } |
| 107 | + |
| 108 | + $(shadowRoot).find('[data-s]').each((node) => clicker(node, node.getAttribute('data-s') ?? '')); |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +customElements.define('darkreader-safari-top-short', SafariTopShortElement); |
0 commit comments