'use strict'; // `any`: the page reads .value, .dataset and .onclick off whatever it looks up, and the // smoke test, not the type checker, is what makes sure a selector exists. const $ = (s: string, r: ParentNode = document): T => r.querySelector(s)!; const $$ = (s: string, r: ParentNode = document): T[] => [...r.querySelectorAll(s)]; /// What went wrong, from whatever a catch caught: the page throws Errors, but a catch cannot know. /// Two names in the order a shelf files them: a leading "The", "A" or "An" aside, so The Rest Is /// Science is under R (#481), with case and accents aside and 2 before 10. const ARTICLE=/^(the|an?)\s+/i; const nameOrder = (a: string, b: string): number => a.replace(ARTICLE,'').localeCompare(b.replace(ARTICLE,''),undefined,{sensitivity:'base',numeric:true}); const why = (e: unknown): string => e instanceof Error ? e.message : String(e); /// A row that opens a feed, a place or a show (the feed list, the Directory): a link to a screen /// reader, named by what it shows, the open one marked current. Not a button, whose contents a /// screen reader flattens, which would hide a folder's triangle inside it; as a bare div it read as /// text, nothing to press (#298). function asLink(el: HTMLElement, current: boolean){ const said=(s: string)=>el.querySelector(s)?.textContent?.trim(); const marks=$$('[role=img][aria-label],.subbed[aria-label]',el).map(m=>m.getAttribute('aria-label')); el.setAttribute('role','link'); el.setAttribute('aria-label',[said('b'),said('small'),...marks,el.querySelector('.badge:not(.zero)')?.title].filter(Boolean).join(', ')); if(current) el.setAttribute('aria-current','page'); } const ESCAPED: Record ={'&':'&','<':'<','>':'>','"':'"',"'":'''}; const esc = (s: string|null|undefined) => (s??'').replace(/[&<>"']/g,c=>ESCAPED[c]); /// Asks before something hard to take back, in a dialog of the page's own. Not confirm(): the iOS /// app answered that Cancel without showing it, so nothing that asked first went ahead there /// (#453, #462). A of its own, in the top layer, so it opens over a dialog already up and /// leaves it as it was; Escape or a tap on Cancel answers no. function ask(text: string, yes: string): Promise{ const d=document.createElement('dialog'); d.className='card ask'; d.innerHTML=`

`; d.querySelector('p')!.textContent=text; d.querySelector('[value="y"]')!.textContent=yes; document.body.append(d); return new Promise(done=>{ d.onclick=(e: MouseEvent)=>{ const b=(e.target as Element).closest('button'); if(b) d.close(b.value); }; // Escape answers this dialog alone, not the one under it too. d.onkeydown=(e: KeyboardEvent)=>{ if(e.key==='Escape') e.stopPropagation(); }; d.onclose=()=>{ d.remove(); done(d.returnValue==='y'); }; d.showModal(); }); } // A feed's link, only if it is a web address: esc() keeps a javascript: or data: one working (#326). const webUrl = (u: string|null|undefined): string|null => /^https?:\/\//i.test(u??'') ? u! : null; // Icons: Font Awesome Free 7.3.1 by @fontawesome - https://fontawesome.com // License - https://fontawesome.com/license/free (Icons: CC BY 4.0). Embedded as SVG, only the // ones used, so there is no font to download and nothing is fetched from anyone else. Each takes // the button's own colour. To add one, copy the path from svgs/