View discord-ws.ts
import { getPlatformInfo } from '../utils/platform'; | |
import { noop } from '../utils/util'; | |
import * as http from '../lib/http'; | |
import { GATEWAY_VERSION } from '../constants/endpoints'; | |
import { GATEWAY } from '../constants/api'; | |
import { GatewayOP, ConnectionStatus } from '../constants/gateway'; | |
import { Inflate } from '@intrnl/pako-esm/inflate'; | |
import { Z_SYNC_FLUSH } from '@intrnl/pako-esm/constants'; |
View queue.ts
export class Queue<V = any> { | |
head?: Node<V>; | |
tail?: Node<V>; | |
size!: number; | |
constructor () { | |
this.clear(); | |
} |
View lazy-promise.js
export function createLazyPromise (executor) { | |
let promise; | |
function ensure () { | |
return promise || (promise = new Promise(executor)); | |
} | |
return { | |
then (onfulfilled, onrejected) { | |
return ensure().then(onfulfilled, onrejected); |
View promise-queue.ts
// class Queue<V = any> | |
// function createDeferred<V> (): Deferred<V> | |
// function sleep (ms: number): Promise<void> | |
export class PromiseQueue { | |
queue = new Queue<Task<any>>(); | |
options: PromiseQueueOptions; | |
ongoing = 0; |
View deferred.ts
export function createDeferred<V> (): Deferred<V> { | |
let deferred: Deferred<V> = {} as any; | |
deferred.promise = new Promise((resolve, reject) => ( | |
Object.assign(deferred, { resolve, reject }) | |
)); | |
return deferred; | |
} |
View sleep.ts
function sleep (ms: number): Promise<void> { | |
return new Promise((resolve) => setTimeout(resolve, ms)); | |
} |
View findInTree.js
function isObject (value) { | |
return value && typeof value == 'object'; | |
} | |
function hasOwnProperty (object, key) { | |
return Object.prototoype.hasOwnProperty.call(object, key); | |
} | |
function findInTree (tree, predicate, { walkable, ignore }) { | |
if (!isObject(tree)) return; |
View handler.js
import * as ed from './noble-ed25519'; | |
let encoder = new TextEncoder(); | |
let commands = new Map(); | |
export function define (name, handler) { | |
commands.set(name, handler); | |
} |
View google-forms-get-url-with-filled-answer.js
// A teacher told us to submit the same form multiple times as sort of memory strengthening. | |
// I don't like that though, so here's a script that creates a Forms URL that contains the answers I've already filled. | |
location.origin + location.pathname + '?' + | |
Array.from(document.querySelectorAll('input[name^="entry."]')) | |
.filter((el) => el.value) | |
.map((el) => `${el.name}=${encodeURIComponent(el.value)}`) | |
.join('&'); |
View use-reactive.jsx
import { render } from 'preact'; | |
import { useRef, useState } from 'preact/hooks'; | |
function useReactive (initialState) { | |
let [, forceUpdate] = useState({}); | |
let reactive = useRef(null); | |
if (!reactive.current) { | |
reactive.current = new Proxy(initialState, { |
NewerOlder