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 * as ed from './noble-ed25519'; | |
let encoder = new TextEncoder(); | |
let commands = new Map(); | |
export function define (name, handler) { | |
commands.set(name, handler); | |
} |
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 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; |
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 sleep (ms: number): Promise<void> { | |
return new Promise((resolve) => setTimeout(resolve, ms)); | |
} |
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
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; | |
} |
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
export function createLazyPromise (executor) { | |
let promise; | |
function ensure () { | |
return promise || (promise = new Promise(executor)); | |
} | |
return { | |
then (onfulfilled, onrejected) { | |
return ensure().then(onfulfilled, onrejected); |
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
export class Queue<V = any> { | |
head?: Node<V>; | |
tail?: Node<V>; | |
size!: number; | |
constructor () { | |
this.clear(); | |
} |
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 { 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'; |
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
let sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | |
let random = (min, max) => ~~(Math.random() * (max - min) + min); | |
let form_data = new FormData(); | |
form_data.append('csrf_token', document.querySelector('meta[name=csrf_token]').content); | |
let elements = Array.from(document.querySelectorAll('.animetitle')); | |
console.log(`${elements.length} to delete`); |
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
class EventEmitter { | |
#events = new EventTarget(); | |
#map = new WeakMap(); | |
on (type, listener, opts = {}) { | |
let { once = false } = opts; | |
let fn = this.#map.get(listener); | |
if (!fn) { | |
fn = (ev) => listener(...ev.detail); |
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
// monkey patches all class methods for tracing calls | |
// not made for async methods | |
function patch_trace (cl, depth = Infinity) { | |
let proto = cl.prototype; | |
do { | |
if (!depth-- || proto === Object.prototype) break; | |
let name = proto.constructor.name; |