Skip to content

Instantly share code, notes, and snippets.

View ashtonmeuser's full-sized avatar

Ashton Meuser ashtonmeuser

  • Dialpad
  • Vancouver, BC
View GitHub Profile
@ashtonmeuser
ashtonmeuser / Modal.ts
Last active February 12, 2025 22:32
A simple reusable modal
import css from './modal.css';
export class DuplicateModalError extends Error {}
export type ModalOptions = { content?: string | Node, loading?: string | Node | boolean, padding?: string, footer?: string | Node, style?: string, onClose?: () => void };
const node = (v: string | Node): Node => typeof v === 'string' ? document.createRange().createContextualFragment(v) : v;
export default class Modal {
dialogElement: HTMLDialogElement;
containerElement: HTMLDivElement;
// bookmarklet-title: ESM Imports
// bookmarklet-about: Test esbuild custom module resolution
// The following dependencies use static imports
// They are bundled with the bookmarklet (thereby increasing bundle size)
// Relative imports will resolve to files within the same gist
import { v4 as uuidRemoteStatic } from 'https://esm.sh/[email protected]';
console.log('UUID from remote static:', uuidRemoteStatic());
@ashtonmeuser
ashtonmeuser / DOOM.ts
Last active March 5, 2025 22:43
DOOM in a bookmarklet
// bookmarklet-title: DOOM
// bookmarklet-about: Take a break. Kill some demons. The entirety of the 1993 classic DOOM shoehorned into a bookmarklet. Some browsers are snobby about executing nearly 10 MB of raw JS from the favorites bar 🙄 in which case you can opt to fetch the DOOM binary rather than embed it.
import Modal from '/ashtonmeuser/0613e3aeff5a4692d8c148d7fcd02f34/raw/d6dd01eaab665a14bded5487a8c03b6bb7197388/Modal.ts';
import binary from 'https://cdn.jsdelivr.net/gh/ashtonmeuser/godot-wasm-doom/doom.wasm';
const embed = false; // bookmarklet-var(boolean): embed
const uuid: string = ''; // bookmarklet-var(uuid): uuid
type Size = { x: number, y: number };
@ashtonmeuser
ashtonmeuser / _summarize.ts
Last active January 21, 2025 03:54
A simple bookmarklet that uses OpenAI ChatGPT to summarize the current webpage
// bookmarklet-title: Summarize
// bookmarklet-about: A simple bookmarklet that uses OpenAI’s ChatGPT to summarize the current webpage. Note that an OpenAI API key is required. Please inspect the bookmarklet source (via the “show editor” or “view gist” buttons) and the bookmarkl.ink project source (github.com/ashtonmeuser/bookmarklet-platform) to ensure that your private data is neither logged nor stored and does not leave your browser.
import Modal from '/ashtonmeuser/0613e3aeff5a4692d8c148d7fcd02f34/raw/7804c7276e855db7a4b2d9ae6801ac6447198810/Modal.ts';
import style from './content.css';
const OPENAI_API_KEY: string = ''; // bookmarklet-var(password): OPENAI_API_KEY
const UUID: string = ''; // bookmarklet-var(uuid): UUID
const errorHtml = (message: string) => `<h1>Error</h1><p>${message}</p>`;
//bookmarklet-title: Canvas DL
//bookmarklet-about: When playing skribbl.io and someone has made a nice drawing, this lets you download the current drawing as a PNG.
var w = window.wdq || (window.wdq = document.createElement("a"));
var p = /The word was '([^']*)'/g,
pp = /<span>([^<>]+) is drawing now!/g,
tt = document.body.innerHTML;
var mm, nn, xx;
while (mm = p.exec(tt)) nn = mm;
while (mm = pp.exec(tt)) xx = mm;
@ashtonmeuser
ashtonmeuser / outline.js
Last active January 14, 2022 09:31
Outline article
//bookmarklet_title: Outline
javascript:(function(){window.location = 'https://outline.com/' + window.location})()
@ashtonmeuser
ashtonmeuser / unhide.js
Created June 1, 2021 03:51
Bookmarklet that toggles hidden elements
// bookmarklet-title: Unhide
// bookmarklet-about: Toggle hidden elements. Credit to u/jcunews1 via https://www.reddit.com/r/bookmarklets/comments/nowz0j/toggle_hidden_elements
if (window.unhiddens_bmkl) {
unhiddens_bmkl.forEach(o => o[0].style.cssText = o[1]);
unhiddens_bmkl = undefined;
} else {
window.unhiddens_bmkl = [];
document.body.querySelectorAll('*:not(script,style)').forEach(e => {
if (getComputedStyle(e).display === 'none') {
@ashtonmeuser
ashtonmeuser / hasher.go
Created April 13, 2021 06:15
Calculate hash as an io.Reader is read
package hasher
import (
"crypto/sha1"
"encoding/hex"
"hash"
"io"
)
// HasherReader calculates the hash of a byte stream
@ashtonmeuser
ashtonmeuser / launch.js
Created April 11, 2021 17:11
Simple Node debugging configuration for VSC
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
// bookmarklet-title: Eno
// bookmarklet-about: Plays demoscene interpretation of Brian Eno's 1/2 from the album Ambient 1. Original code by Mathieu Henri (http://www.p01.org/music_for_tiny_airports).
const k = 8192;
let t = 0;
const AudioContext = window.AudioContext || window.webkitAudioContext;
const ac = new AudioContext();
const sp = ac.createScriptProcessor(k, 0, 1);
sp.connect(ac.destination);
sp.onaudioprocess = pe => {