Skip to content

Instantly share code, notes, and snippets.

View dragon-fish's full-sized avatar
🐱
Want to be an animal ear loli

机智的小鱼君 dragon-fish

🐱
Want to be an animal ear loli
View GitHub Profile
@dragon-fish
dragon-fish / koishi-plugin-qq-channel-patch.js
Last active December 10, 2021 14:11
Koishi plugin QQ Channel Patch
/**
* @name koishi-plugin-qq-channel-patch
* @author Dragon-Fish <dragon-fish@qq.com>
*
* @desc Temporary patch for QQ channel for koishi.js
*/
// Packages
const { CQBot } = require('koishi-adapter-onebot')
const { segment } = require('koishi-core')
@dragon-fish
dragon-fish / ipe-early-design-demo.ts
Created December 20, 2021 17:56
Early design of InPageEdit core architecture
/** Core types */
class InPageEdit {
constructor(options?: Partial<AppOptions>) {}
private plugins: Plugin[]
private pages: Page[]
fn: Record<string, any>
use: (payload: Plugin) => this
createPage: (title?: string) => Page
createPlugin: (name: string, apply: (ctx: Context) => VueInstance) => Plugin
}
@dragon-fish
dragon-fish / jsonp.ts
Last active February 3, 2023 02:08
A very simple JSONP package
/**
* A very simple JSONP package
* @author Dragon-Fish
* @license MIT
*/
/**
* jsonp
* @example
* ```ts
@dragon-fish
dragon-fish / createElement.ts
Last active February 15, 2023 08:21
DOM generator
/**
* DOM generator
* @author Dragon-Fish
* @license MIT
*/
export function createElement<K extends keyof ElementTagNameMap>(
tagName: K,
children?: ElementChildren
): ElementTagNameMap[K]
@dragon-fish
dragon-fish / ObjectStorage.ts
Last active March 10, 2023 18:01
ObjectStorage.ts
/**
* ObjectStorage
* @desc JSON localStorage with auto cache
*
* @author Dragon-Fish <dragon-fish@qq.com>
* @license MIT
*/
export class ObjectStorage<T extends any> {
constructor(readonly name: string, readonly maxAge = 0) {}
@dragon-fish
dragon-fish / loadScriptAsync.ts
Created March 13, 2023 15:12
loadScriptAsync.ts
function loadScriptAsync(src = '', { isModule = false, noCache = false }) {
return new Promise((resolve, reject) => {
const script = document.createElement('script')
script.async = true
if (noCache) {
src += `${src.includes('?') ? '&' : '?'}_=${Date.now()}`
}
script.src = src
isModule && (script.type = 'module')
script.addEventListener('load', resolve)
@dragon-fish
dragon-fish / animatedNumber.ts
Created March 20, 2023 17:58
Animated number
function animatedNumber({
from = 0,
to = 0,
duration = 0,
onUpdate,
onFinish,
}) {
const startTime = performance.now()
;(function tick() {
const current = performance.now()
@dragon-fish
dragon-fish / IpadCursor.ts
Last active April 13, 2023 06:52
An iPadOS cursor simulation for the browser
/**
* @author dragon-fish <dragon-fish@qq.com>
* @lisence MIT
* @refered https://github.com/hongkiulam/ipad-cursor-js by @hongkiulam
*/
const TEXT_ELEMENT_TAGS = ['P', 'SPAN', 'H1', 'H2', 'H3', 'H4', 'TEXTAREA']
export class IpadCursor {
public cursor = document.createElement('div')
@dragon-fish
dragon-fish / clickToSaveCanvas.js
Last active February 21, 2024 11:49
clickToSaveCanvas
;(() => {
if (window.clickToSaveCanvas) {
return window.clickToSaveCanvas()
}
/**
* @param {HTMLCanvasElement} canvas
*/
async function canvasToBlob(canvas) {
return new Promise((resolve) => {