A tiny library for userscripts that waits for elements to arrive in the DOM.
npm i spawncamp
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()
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.