style: fix timezone.ts indentation

This commit is contained in:
2026-04-21 01:22:00 +02:00
parent 435656a4cc
commit 1ceca3bd9e

View File

@@ -2,13 +2,13 @@ export {}
const jstOffsetMinutes = 9 * 60
type ParsedBroadcast = {
type ParsedBroadcast = {
day: string
hour: number
minute: number
}
}
const parseBroadcastTime = (value: string | null): { hour: number; minute: number } | null => {
const parseBroadcastTime = (value: string | null): { hour: number; minute: number } | null => {
if (!value || typeof value !== 'string') {
return null
}
@@ -25,18 +25,18 @@ const jstOffsetMinutes = 9 * 60
}
return { hour, minute }
}
}
const isJstTimezone = (timezone: string | null): boolean => {
const isJstTimezone = (timezone: string | null): boolean => {
if (!timezone) {
return true
}
const normalized = timezone.trim().toLowerCase()
return normalized === 'asia/tokyo' || normalized === 'jst'
}
}
const parseFromStructuredAttrs = (node: Element): ParsedBroadcast | null => {
const parseFromStructuredAttrs = (node: Element): ParsedBroadcast | null => {
const day = node.getAttribute('data-broadcast-day')
const time = node.getAttribute('data-broadcast-time')
const timezone = node.getAttribute('data-broadcast-timezone')
@@ -51,9 +51,9 @@ const jstOffsetMinutes = 9 * 60
}
return { day: day.trim(), hour: parsedTime.hour, minute: parsedTime.minute }
}
}
const parseBroadcast = (text: string | null): ParsedBroadcast | null => {
const parseBroadcast = (text: string | null): ParsedBroadcast | null => {
if (!text || typeof text !== 'string') {
return null
}
@@ -76,9 +76,9 @@ const jstOffsetMinutes = 9 * 60
}
return { day, hour, minute }
}
}
const normalizeDay = (day: string): number | null => {
const normalizeDay = (day: string): number | null => {
const key = day.trim().toLowerCase().replace(/s$/, '')
const days: Record<string, number> = {
mon: 1,
@@ -105,9 +105,9 @@ const jstOffsetMinutes = 9 * 60
}
return days[key]
}
}
const convertToLocal = (parsed: ParsedBroadcast, localOffsetMinutes: number): string | null => {
const convertToLocal = (parsed: ParsedBroadcast, localOffsetMinutes: number): string | null => {
const sourceMinutes = parsed.hour * 60 + parsed.minute
const diff = jstOffsetMinutes - localOffsetMinutes
const localTotal = sourceMinutes - diff
@@ -127,9 +127,9 @@ const jstOffsetMinutes = 9 * 60
const time = `${localHour.toString().padStart(2, '0')}:${localMinute.toString().padStart(2, '0')}`
return `${localDay} at ${time} (Local)`
}
}
const nextAiringUTC = (parsed: ParsedBroadcast): Date | null => {
const nextAiringUTC = (parsed: ParsedBroadcast): Date | null => {
const targetDay = normalizeDay(parsed.day)
if (targetDay === null) {
return null
@@ -149,9 +149,9 @@ const jstOffsetMinutes = 9 * 60
const minuteDelta = dayDelta * 1440 + (targetMinuteOfDay - currentMinuteOfDay)
return new Date(now.getTime() + minuteDelta * 60 * 1000)
}
}
const formatRelative = (value: number, unit: Intl.RelativeTimeFormatUnit): string => {
const formatRelative = (value: number, unit: Intl.RelativeTimeFormatUnit): string => {
if (typeof Intl !== 'undefined' && typeof Intl.RelativeTimeFormat === 'function') {
const formatter = new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' })
return formatter.format(value, unit)
@@ -159,9 +159,9 @@ const jstOffsetMinutes = 9 * 60
const suffix = value === 1 ? unit : `${unit}s`
return `in ${value} ${suffix}`
}
}
const relativeText = (target: Date): string => {
const relativeText = (target: Date): string => {
const diffMs = target.getTime() - Date.now()
if (diffMs <= 0) {
return 'soon'
@@ -179,18 +179,18 @@ const jstOffsetMinutes = 9 * 60
const days = Math.ceil(hours / 24)
return formatRelative(days, 'day')
}
}
const localDateTimeText = (date: Date): string => {
const localDateTimeText = (date: Date): string => {
const formatter = new Intl.DateTimeFormat(undefined, {
weekday: 'short',
hour: '2-digit',
minute: '2-digit',
})
return formatter.format(date)
}
}
const updateNextAiring = (node: Element, parsed: ParsedBroadcast): void => {
const updateNextAiring = (node: Element, parsed: ParsedBroadcast): void => {
const card = node.closest('[data-notification-content]')
if (!card) {
return
@@ -208,9 +208,9 @@ const jstOffsetMinutes = 9 * 60
}
nextNode.textContent = `Next episode ${relativeText(nextDate)} (${localDateTimeText(nextDate)})`
}
}
const updateNode = (node: Element, localOffsetMinutes: number): void => {
const updateNode = (node: Element, localOffsetMinutes: number): void => {
const card = node.closest('[data-notification-content]')
const nextNode = card ? card.querySelector('[data-next-airing]') : null
@@ -234,13 +234,13 @@ const jstOffsetMinutes = 9 * 60
node.textContent = converted
updateNextAiring(node, parsed)
}
}
const updateAll = (): void => {
const updateAll = (): void => {
const localOffsetMinutes = -new Date().getTimezoneOffset()
const nodes = document.querySelectorAll('[data-jst-text]')
nodes.forEach((node: Element): void => updateNode(node, localOffsetMinutes))
}
}
const initTimezoneConversion = (): void => {
document.addEventListener('DOMContentLoaded', updateAll)