Skip to content

Instantly share code, notes, and snippets.

View ashtonmeuser's full-sized avatar

Ashton Meuser ashtonmeuser

  • Dialpad
  • Vancouver, BC
View GitHub Profile
// bookmarklet-title: Stay Here
// bookmarklet-about: Prevent leaving current page. See https://river.me/blog/bookmarklet-stay-here/.
window.addEventListener('beforeunload', function (e) {
e.preventDefault();
});
// bookmarklet-title: Kill Sticky
// See https://alisdair.mcdiarmid.org/kill-sticky-headers/
var i, elements = document.querySelectorAll('body *');
for (i = 0; i < elements.length; i++) {
if (getComputedStyle(elements[i]).position === 'fixed') {
elements[i].parentNode.removeChild(elements[i]);
}
}
@ashtonmeuser
ashtonmeuser / playbackSpeed.js
Created January 24, 2025 22:17
Toggle the playback speed of a video
// bookmarklet-title: Playback Speed
// bookmarklet-about: Toggle video playback speed
const video = document.querySelector('video');
if (video) {
const rates = [1.0, 1.5, 2.0];
const rate = video.playbackRate;
const index = rates.indexOf(rate);
video.playbackRate = index >= 0 ? rates[(index + 1) % rates.length] : rates[0];
@ashtonmeuser
ashtonmeuser / ChatGPT Canvas HTML Renderer from Clipboard.url
Last active January 23, 2025 03:55 — forked from rmtbb/ChatGPT Canvas HTML Renderer from Clipboard.url
Bookmarklet that lets you render a full HTML page with any included css and javascript that is currently copied to your clipboard. Also works for SVG code. Useful with ChatGPT Canvas
javascript:(function(){try{navigator.clipboard.readText().then(function(t){if(t){var e=window.open("","_blank","width=800,height=600");e.document.open(),e.document.write(t),e.document.close()}else alert("Clipboard is empty. Please copy some text to the clipboard first.")}).catch(function(t){console.error("Failed to read clipboard contents: ",t),alert("An error occurred while trying to access the clipboard. Please ensure your browser allows clipboard access.")})}catch(t){console.error("An error occurred:",t),alert("An error occurred while trying to open the new window with the clipboard content.")}})();//bookmarklet_title: HTML Preview from Clipboard
@ashtonmeuser
ashtonmeuser / reader.ts
Last active February 2, 2025 23:14
Reader view using Mozilla's readability
// bookmarklet-title: Reader
// bookmarklet-about: Mozilla's readability (https://github.com/mozilla/readability) piped into a modal.
import Modal from '/ashtonmeuser/0613e3aeff5a4692d8c148d7fcd02f34/raw/d6dd01eaab665a14bded5487a8c03b6bb7197388/Modal.ts';
import { Readability } from 'https://esm.sh/@mozilla/readability';
const id = ''; // bookmarklet-var(uuid): id
const reader = new Readability(document.cloneNode(true)).parse();
const content = `<h1>${reader.title}</h1>${reader.content}`;
@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 January 21, 2025 04:35
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;