Skip to content

A tiny library for userscripts that waits for elements to arrive in the DOM.

Notifications You must be signed in to change notification settings

vaaski/spawncamp

Repository files navigation

spawncamp

A tiny library for userscripts that waits for elements to arrive in the DOM.

Installing

npm i spawncamp

Usage

import { Spawncamp } from "spawncamp"

const camp = new Spawncamp()

// Awaits the button element to arrive in the DOM once
const button = await camp.once("button")

button.addEventListener("click", () => {
	console.log("Clicked!")
})

// Calls the callback every time an element matching the selector arrives in the DOM
const remove = camp.on("button", (element) => {
	console.log("New button just dropped", element)
})

// Removes the observer for that selector
remove()

// Stops observing the DOM entirely
camp.stop()

Development

To install dependencies:

bun install

Run tests:

bun test

Build:

bun run build.ts

This project was created using bun init with bun v1.1.27.

It uses Biome for formatting and linting.

About

A tiny library for userscripts that waits for elements to arrive in the DOM.

Topics

Resources

Stars

Watchers

Forks