// ├───bin
// ├───models
// └───output
// module clitoy/upscale
// go 1.20
// require (
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// adds an event listener to ab element that will ibly run the callback the first time the event is triggered. | |
// - use EventTarget.addEventListener() to add an event listener to an element. | |
// - use {once:true} as options to only run the given callback once. | |
const listenOnce = (el, e, fn) => { | |
el.addEventListener(e, fn, { once: true }); | |
}; | |
listenOnce(document.getElementById("test"), "click", () => | |
console.log("Hello world") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generatePassword(length) { | |
let charset = | |
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-+={}[]|\\:;\"'<>,.?/"; | |
let password = ""; | |
for (let i = 0; i < length; i++) { | |
let randomIndex = Math.floor(Math.random() * charset.length); | |
password += charset[randomIndex]; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 对Date的扩展,将 Date 转化为指定格式的String | |
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符, | |
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) | |
// 例子: | |
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 | |
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 | |
Date.prototype.Format = function (fmt) { | |
var o = { | |
"M+": this.getMonth() + 1, // 月份 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
pkg_fetch_version, | |
node_version, | |
pkg_cache_path, | |
icon, | |
version, | |
description, | |
company, | |
name, | |
copyright, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
async (e: Event) => { | |
const chunkSize = 2 * 1024 * 1024; | |
const target = e.target as HTMLInputElement; | |
const targetFile = target.files![0]; | |
const { type, name, size } = targetFile; | |
checkType(type); | |
let [index, start] = [0, 0]; | |
while (start < size) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from "react"; | |
export function useSafeLocalStorage(key: string, initialValue: any) { | |
const [valueProxy, setValueProxy] = useState(() => { | |
try { | |
const value = window.localStorage.getItem(key); | |
return value ? JSON.parse(value) : initialValue; | |
} catch { | |
return initialValue; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from "react"; | |
export default function usePrefersDarkMode(defaultValue: boolean) { | |
const [value, setValue] = useState(() => defaultValue); | |
useEffect(() => { | |
if (typeof window !== "undefined") { | |
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)"); | |
setValue(mediaQuery.matches); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect } from "react"; | |
import usePrefersDarkMode from "./usePrefersDarkMode"; | |
import { useSafeLocalStorage } from "./useSafeLocalStorage"; | |
export function useDarkMode(isDark: boolean) { | |
const prefersDarkMode = usePrefersDarkMode(isDark); | |
const [isEnabled, setIsEnabled] = useSafeLocalStorage("dark-mode", isDark); | |
const enabled = isEnabled === undefined ? prefersDarkMode : isEnabled; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @description Get file tree by a mtp device parent path. | |
* @param parentPath The root address can be passed in the string `/`. | |
* @returns `Array<FileInfo>` File info array | |
* @example | |
* | |
* [{ | |
* name: '1', | |
* size: 0, | |
* type: 'FOLDER', |
OlderNewer