mirror of
https://github.com/pionxzh/chatgpt-exporter.git
synced 2026-07-23 09:00:51 -05:00
35 lines
952 B
TypeScript
35 lines
952 B
TypeScript
export function noop() {}
|
|
|
|
export function onloadSafe(fn: () => void) {
|
|
if (document.readyState === 'complete') {
|
|
fn()
|
|
}
|
|
else {
|
|
window.addEventListener('load', fn)
|
|
}
|
|
}
|
|
|
|
export function sleep(ms: number) {
|
|
return new Promise(resolve => setTimeout(resolve, ms))
|
|
}
|
|
|
|
export function dateStr(date: Date = new Date()) {
|
|
const year = date.getFullYear()
|
|
const month = String(date.getMonth() + 1).padStart(2, '0')
|
|
const day = String(date.getDate()).padStart(2, '0')
|
|
return `${year}-${month}-${day}`
|
|
}
|
|
|
|
export function timestamp() {
|
|
return new Date().toISOString().replace(/:/g, '-').replace(/\..+/, '')
|
|
}
|
|
|
|
export function getColorScheme(): 'light' | 'dark' {
|
|
return document.documentElement.style.getPropertyValue('color-scheme') as 'light' | 'dark'
|
|
}
|
|
|
|
export function unixTimestampToISOString(timestamp: number) {
|
|
if (!timestamp) return ''
|
|
return (new Date(timestamp * 1000)).toISOString()
|
|
}
|