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: 320 }, // canvas width
5 { name: "ch", value: 180 }, // 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: "plwspd", value: 0.1 }, // plow speed
12 { name: "plwd", value: "left" }, // plow direction
13 { name: "plws", value: 1 }, // plow scale
14 { name: "gamax", value: 4 }, // ground accumulator max
15 { name: "gas", value: 20 }, // ground accumulatior slices
16];
17
18/**
19 * @returns {Config} configuration object
20 * gets configuration from query parameters or defaults
21 */
22function getConfiguration() {
23 const urlParams = new URLSearchParams(window.location.search);
24 if (PARAM_DEFAULTS.some(({ name }) => !urlParams.has(name))) {
25 setParamsAndRefresh(PARAM_DEFAULTS);
26 }
27
28 return {
29 version: parseInt(urlParams.get("v")),
30 canvas: {
31 width: parseInt(urlParams.get("cw")),
32 height: parseInt(urlParams.get("ch")),
33 },
34 snow: {
35 max: parseInt(urlParams.get("smx")),
36 minSize: parseInt(urlParams.get("smnsz")),
37 maxSize: parseInt(urlParams.get("smxsz")),
38 maxSpeed: parseFloat(urlParams.get("smxspd")),
39 minSpeed: parseFloat(urlParams.get("snmnspd")),
40 },
41 plow: {
42 speed: parseFloat(urlParams.get("plwspd")),
43 // @ts-ignore -- I dunno how to get ts / jsdoc to be ok with this
44 direction: urlParams.get("plwd"),
45 scale: parseFloat(urlParams.get("plws")),
46 },
47 groundAccumulator: {
48 max: parseInt(urlParams.get("gamax")),
49 slices: parseInt(urlParams.get("gas")),
50 },
51 };
52}
53
54/**
55 * @param {Array<{name: string, value: any}>} params
56 */
57export function setParamsAndRefresh(params) {
58 const urlParams = new URLSearchParams(window.location.search);
59 params.forEach(({ name, value }) => {
60 urlParams.set(name, value);
61 });
62 window.location.search = urlParams.toString();
63}
64
65const config = getConfiguration();
66
67export default config;