Skip to content

Instantly share code, notes, and snippets.

@oliverjam
oliverjam / mini-markdown.html
Last active December 6, 2020 15:39
A tiny markdown editor. Paste into your URL bar with `data:text/html,` at the front
<style>
body {
margin: 0;
min-height: 100vh;
display: grid;
grid: none / 1fr 1fr;
gap: 1rem;
}
%23i {
outline: 0;
function html(strings, ...interpolations) {
return strings
.map((string, i) => {
let value = interpolations[i];
// 0 is falsy but a valid value in HTML
if (value === undefined || value === null || value === false) {
value = "";
}
// join arrays so they aren't stringified with commas
if (Array.isArray(value)) {
@oliverjam
oliverjam / safer-autoplay.js
Created January 27, 2021 12:30
A simple Custom Element for autoplaying a video only if the user hasn't opted out of motion
// Wrap around a video you want to autoplay.
// Don't set the autoplay attribute,
// since that can't respect user preferences.
// e.g. <safer-autoplay><video src="vid.mp4"></video></safer-autoplay>
// Sidenote: motion should _really_ be opt-in,
// since lots of users won't know they can set a preference
// "no motion" is the safest default,
// but good luck getting that past your PO/designer ¯\_(ツ)_/¯
import { useReducer, useRef, useEffect } from "react";
function reducer(state, action) {
switch (action.type) {
// When the hook is first called
case "LOAD": {
return { ...state, status: "loading" };
}
// When LOAD finishes fetching initial remote data
case "RESOLVE_LOAD": {