sourcehypertextpubliccosmeticsscript.js

// Element selection

const $ = sel => document.querySelector(sel);
const $$ = sel => document.querySelectorAll(sel);

Element.prototype.$ = Element.prototype.querySelector;
Element.prototype.$$ = Element.prototype.querySelectorAll;

EventTarget.prototype.on = EventTarget.prototype.addEventListener;

const documentReady = fn => document.on("DOMContentLoaded", fn);

// Comments stuff :-)

function prepend(postId) {
	$("#comments-form-comment").value += `@${postId}`;
}

// Maths

const π = Math.PI,
	τ = π * 2,
	ex = Math.E,
	sqrt2 = Math.SQRT2,
	sqrtHalf = Math.SQRT1_2;

const sqrt = Math.sqrt,
	cbrt = Math.cbrt;

const ln = Math.log,
	exp = Math.exp;

const sin = Math.sin,
	cos = Math.cos,
	tan = Math.tan,
	asin = Math.asin,
	acos = Math.acos,
	atan = Math.atan;

const floor = Math.floor,
	ceil = Math.ceil,
	round = Math.round,
	abs = Math.abs,
	max = Math.max,
	min = Math.min;

const random = Math.random;

const log = (base, num) => {
	switch (base) {
		case ex:
			return ln(num);
		case 10:
			return Math.log10(num);
		case 2:
			return Math.log2(num);
		default:
			return ln(num) / ln(base);
	}
};

const modulo = (n, d) => ((n % d) + d) % d;

// x radians = x * deg degrees

const deg = τ / 360;
const rad = 360 / τ;