A browser source overlay for winter vibes for your Live Streams or Videos
1// default configuration values 2const PARAM_DEFAULTS = [ 3 { name: "v", value: 1 }, // version 4 { name: "cw", value: 640 }, // canvas width 5 { name: "ch", value: 360 }, // canvas height 6 { name: "smx", value: 40 }, // snow max 7 { name: "smnsz", value: 1 }, // snow min size 8 { name: "smxsz", value: 4 }, // snow max size 9 { name: "smxspd", value: 0.07 }, // snow max speed 10 { name: "snmnspd", value: 0.04 }, // snow min speed 11 { name: "pspd", value: 0.1 }, // plow speed 12 { name: "pd", value: "left" }, // plow direction 13 { name: "gamax", value: 4 }, // ground accumulator max 14 { name: "gas", value: 20 }, // ground accumulatior slices 15]; 16 17/** 18 * @returns {Config} configuration object 19 * gets configuration from query parameters or defaults 20 */ 21function getConfiguration() { 22 const urlParams = new URLSearchParams(window.location.search); 23 if (PARAM_DEFAULTS.some(({ name }) => !urlParams.has(name))) { 24 setParamsAndRefresh(PARAM_DEFAULTS); 25 } 26 27 return { 28 version: parseInt(urlParams.get("v")), 29 canvas: { 30 width: parseInt(urlParams.get("cw")), 31 height: parseInt(urlParams.get("ch")), 32 }, 33 snow: { 34 max: parseInt(urlParams.get("smx")), 35 minSize: parseInt(urlParams.get("smnsz")), 36 maxSize: parseInt(urlParams.get("smxsz")), 37 maxSpeed: parseFloat(urlParams.get("smxspd")), 38 minSpeed: parseFloat(urlParams.get("snmnspd")), 39 }, 40 plow: { 41 speed: parseFloat(urlParams.get("pspd")), 42 // @ts-ignore -- I dunno how to get ts / jsdoc to be ok with this 43 direction: urlParams.get("pd"), 44 }, 45 groundAccumulator: { 46 max: parseInt(urlParams.get("gamax")), 47 slices: parseInt(urlParams.get("gas")), 48 }, 49 }; 50} 51 52/** 53 * @param {Array<{name: string, value: any}>} params 54 */ 55export function setParamsAndRefresh(params) { 56 const urlParams = new URLSearchParams(window.location.search); 57 params.forEach(({ name, value }) => { 58 urlParams.set(name, value); 59 }); 60 window.location.search = urlParams.toString(); 61} 62 63const config = getConfiguration(); 64 65export default config;