diff --git a/script/gallery.ts b/script/gallery.ts index c1079a0..9e8cbdc 100644 --- a/script/gallery.ts +++ b/script/gallery.ts @@ -18,30 +18,30 @@ function fillSets(): [Set, Set] { } function updateItems() { - let [reqTags, excTags] = fillSets(); - let anyReq = reqTags.size > 0; + const [reqTags, excTags] = fillSets(); + const anyReq = reqTags.size > 0; - for (let [year, items] of itemsByYear) { + for (const [year, items] of itemsByYear) { let hide = true; - for (let item of items) { - let req = tags.get(item)?.some(x => reqTags.has(x)) ?? false; - let exc = tags.get(item)?.some(x => excTags.has(x)) ?? false; - let hidden = exc || (anyReq && !req); + for (const item of items) { + const req = tags.get(item)?.some(x => reqTags.has(x)) ?? false; + const exc = tags.get(item)?.some(x => excTags.has(x)) ?? false; + const hidden = exc || (anyReq && !req); item.hidden = hidden; hide &&= hidden; } - let marker = document.getElementById(`marker-${year}`); + const marker = document.getElementById(`marker-${year}`); if (marker !== null) marker.hidden = hide; } function disp(pfx: string, tags: Iterable) { return [...tags].map(x => pfx + x).join('\u2003'); // em space } - let plus = disp('+\u2009', Array.from(reqTags)); // thin space - let minus = disp('-\u2009', Array.from(excTags)); + const plus = disp('+\u2009', reqTags); // thin space + const minus = disp('-\u2009', excTags); document.getElementById('filters-details')!.dataset.filters = `${plus}\u2003${minus}`.trim(); } @@ -61,7 +61,7 @@ function converseId(id: string) { function toggle(checkbox: HTMLInputElement) { if (checkbox.checked) { - let converse = document.getElementById(converseId(checkbox.id)) as HTMLInputElement; + const converse = document.getElementById(converseId(checkbox.id)) as HTMLInputElement; converse.checked = false; } update(); @@ -81,10 +81,10 @@ function clear(e: Event) { function toggleSingles(e: Event) { showSingles = !showSingles; - let elems = Array.from(document.querySelectorAll('.filterlist li')); - for (let li of elems) { - let countStr = li.querySelector('label')?.dataset.count; - let count = countStr ? +countStr : 0; + const elems = Array.from(document.querySelectorAll('.filterlist li')) as HTMLElement[]; + for (const li of elems) { + const countStr = li.querySelector('label')?.dataset.count; + const count = countStr ? +countStr : 0; if (count <= 1 && li instanceof HTMLElement) { li.hidden = !showSingles; } @@ -95,8 +95,8 @@ function toggleSingles(e: Event) { function makeFragment() { - let allBoxesArr = Array.from(allBoxes); - let ids = allBoxesArr.filter(b => b.checked).map(b => b.id); + const allBoxesArr = Array.from(allBoxes); + const ids = allBoxesArr.filter(b => b.checked).map(b => b.id); if (ids.length == 0) { return '#all'; } else if (allBoxesArr.every(b => b.checked == b.defaultChecked)) { @@ -107,8 +107,8 @@ function makeFragment() { } function useFragment() { - let frag = decodeURIComponent(location.hash).replace(/^#/, ''); - let details = document.getElementById('filters-details') as HTMLDetailsElement; + const frag = decodeURIComponent(location.hash).replace(/^#/, ''); + const details = document.getElementById('filters-details') as HTMLDetailsElement; if (!frag) { clearForm(); @@ -116,8 +116,8 @@ function useFragment() { allBoxes.forEach(b => b.checked = false); details.open = false; } else { - let set = new Set(frag.split(';')); - let re = /^(require|exclude)_|hide_filters/; + const set = new Set(frag.split(';')); + const re = /^(require|exclude)_|hide_filters/; if (Array.from(set).every(x => re.test(x))) { allBoxes.forEach(b => b.checked = set.has(b.id)); details.open = !frag.match(/hide_filters|example\b/); @@ -130,12 +130,12 @@ function useFragment() { function sortFilters(cmp: (a: Node, b: Node) => number) { function sort1(id: string) { - let elt = document.getElementById(id); + const elt = document.getElementById(id); if (elt === null) return; - let children = Array.from(elt.childNodes); + const children = Array.from(elt.childNodes); children.sort(cmp); - for (let c of children) { + for (const c of children) { elt.removeChild(c); elt.appendChild(c); } @@ -175,15 +175,15 @@ function sortFiltersUses(e: Event) { function setup() { function inputs(id: string): Boxes { - let iter = document.getElementById(id)!.getElementsByTagName('input'); + const iter = document.getElementById(id)!.getElementsByTagName('input'); return new Set(Array.from(iter)); } - let items = Array.from(document.getElementsByClassName('post')) as HTMLElement[]; + const items = Array.from(document.getElementsByClassName('post')) as HTMLElement[]; itemsByYear = new Map; - for (let item of items) { - let year = item.dataset.year; + for (const item of items) { + const year = item.dataset.year; if (year !== undefined) { if (!itemsByYear.has(year)) { itemsByYear.set(year, new Set([item])); diff --git a/script/nsfw-warning.ts b/script/nsfw-warning.ts index ac901c5..fd1b369 100644 --- a/script/nsfw-warning.ts +++ b/script/nsfw-warning.ts @@ -5,7 +5,7 @@ function alreadyYes() { } function dismiss() { - let dialog = document.getElementById('nsfw-dialog')!; + const dialog = document.getElementById('nsfw-dialog')!; dialog.parentElement?.removeChild(dialog); } diff --git a/script/single.ts b/script/single.ts index 87195ae..2954f7d 100644 --- a/script/single.ts +++ b/script/single.ts @@ -4,7 +4,7 @@ let mainlink: HTMLAnchorElement; let altButtons: HTMLInputElement[]; let skipAll: HTMLInputElement; -let opened: Set = new Set; +const opened: Set = new Set; function openCW(id: string | null, caption: HTMLElement | null, focusLink = false) { @@ -27,13 +27,11 @@ function setImage(id: string | null, src: string, href: string, cw: string) { - let caption = document.getElementById('cw'); - let newCaption: HTMLElement | null = null; - - let checked = skipAll ? skipAll.checked : false; + const caption = document.getElementById('cw'); + const checked = skipAll ? skipAll.checked : false; if (!checked && !opened.has(id) && cw) { - let template = document.getElementById('cw-template') as HTMLTemplateElement; + const template = document.getElementById('cw-template') as HTMLTemplateElement; newCaption = template.content.firstElementChild!.cloneNode(true) as HTMLElement; newCaption.querySelector('#cw-text')!.innerHTML = cw; addCWListeners(id, newCaption); @@ -62,9 +60,9 @@ function activateButton(button: HTMLInputElement, doPush = true): void { function useFragment(firstLoad = false): void { let button = altButtons[0]; - let frag = decodeURIComponent(location.hash).replace(/^#/, ''); + const frag = decodeURIComponent(location.hash).replace(/^#/, ''); if (frag) { - let selected = document.getElementById(frag) as HTMLInputElement; + const selected = document.getElementById(frag) as HTMLInputElement; if (selected) button = selected; } @@ -85,21 +83,21 @@ function setup() { mainlink = document.getElementById('mainlink') as HTMLAnchorElement; skipAll = document.getElementById('skipAll') as HTMLInputElement; - let alts = document.getElementById('alts'); + const alts = document.getElementById('alts'); if (alts) { - let inputs = Array.from(alts.getElementsByTagName('input')); + const inputs = Array.from(alts.getElementsByTagName('input')); altButtons = inputs.filter(e => e.name == 'variant'); } else { altButtons = []; } - for (let button of altButtons) { + for (const button of altButtons) { button.onchange = _e => { if (button.checked) activateButton(button); }; } if (skipAll) { skipAll.onchange = _e => { if (skipAll.checked) { - let caption = document.getElementById('cw'); + const caption = document.getElementById('cw'); if (caption) { openCW(null, caption, false); } } }; }