From 5c85e09ad568fbe5f1d431319e16527ad6a8d906 Mon Sep 17 00:00:00 2001
From: Xiretza <xiretza@xiretza.xyz>
Date: Tue, 4 Feb 2025 23:20:16 +0000
Subject: [PATCH] Add clang-format config

---
 .clang-format    |   7 ++
 Justfile         |   4 +
 assets/js/its.js | 260 ++++++++++++++++++++++++-----------------------
 3 files changed, 143 insertions(+), 128 deletions(-)
 create mode 100644 .clang-format

diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..1148da9
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,7 @@
+---
+Language: JavaScript
+UseTab: Always
+IndentWidth: 4
+TabWidth: 4
+LineEnding: LF
+---
diff --git a/Justfile b/Justfile
index 7346455..d123175 100644
--- a/Justfile
+++ b/Justfile
@@ -1,5 +1,9 @@
 check:
 	markdownlint-cli2
+	clang-format --dry-run assets/js/*.js
+
+format:
+	clang-format -i assets/js/*.js
 
 serve:
 	hugo serve
diff --git a/assets/js/its.js b/assets/js/its.js
index 2bb3846..8043861 100644
--- a/assets/js/its.js
+++ b/assets/js/its.js
@@ -16,8 +16,8 @@ function randomRange(min, max) {
 }
 
 async function delay(millis) {
-	await new Promise((resolve) =>
-		setTimeout(resolve, millis),
+	await new Promise(
+		(resolve) => setTimeout(resolve, millis),
 	);
 }
 
@@ -108,7 +108,7 @@ function setNixieColor(color) {
 function nixieRainbow() {
 	const tubeSpans = document.querySelectorAll('.tube>span');
 	const numberOfSpans = tubeSpans.length;
-	
+
 	tubeSpans.forEach((span, index) => {
 		const hue = Math.floor((360 / numberOfSpans) * index);
 		const color = `hsl(${hue}, 100%, 50%)`;
@@ -126,13 +126,13 @@ function nixieRainbow() {
 }
 
 function resetNixieRainbow() {
-    const tubeSpans = document.querySelectorAll('.tube>span');
-    
-    tubeSpans.forEach((span) => {
-        span.style.color = '';
-        span.style.textShadow = '';
-        span.style.animation = '';
-    });
+	const tubeSpans = document.querySelectorAll('.tube>span');
+
+	tubeSpans.forEach((span) => {
+		span.style.color = '';
+		span.style.textShadow = '';
+		span.style.animation = '';
+	});
 }
 
 function handleInput(event) {
@@ -143,36 +143,39 @@ function handleInput(event) {
 }
 
 function inputCodeCheck(typedText) {
-	switch(typedText.toLowerCase()) {
-		case "(){:;}":
-			shellShock();
-			break;
-		case "matrix":
-			matrix();
-			break;
-		case "barrel":
-			barrel();
-			break;
-		case "astley":
-			astley();
-			break;
-		case "kawaii":
-			nyan_cat();
-			break;
-		case "pacman":
-			pacman();
-			break;
-		case "gamble":
-			gamble();
-			break;
-		case "drkhsh":
-			drkhsh();
-			break;
+	switch (typedText.toLowerCase()) {
+	case "(){:;}":
+		shellShock();
+		break;
+	case "matrix":
+		matrix();
+		break;
+	case "barrel":
+		barrel();
+		break;
+	case "astley":
+		astley();
+		break;
+	case "kawaii":
+		nyan_cat();
+		break;
+	case "pacman":
+		pacman();
+		break;
+	case "gamble":
+		gamble();
+		break;
+	case "drkhsh":
+		drkhsh();
+		break;
 	}
 }
 
-const code = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
-const code_two = [48, 49, 49, 56, 57, 57, 57, 56, 56, 49, 57, 57, 57, 49, 49, 57, 55, 50, 53, 51];
+const code = [ 38, 38, 40, 40, 37, 39, 37, 39, 66, 65 ];
+const code_two = [
+	48, 49, 49, 56, 57, 57, 57, 56, 56, 49,
+	57, 57, 57, 49, 49, 57, 55, 50, 53, 51
+];
 
 let currentStepOne = 0;
 let currentStepTwo = 0;
@@ -188,7 +191,8 @@ function checkSequence(e) {
 				currentStepOne = 0;
 				setNixieColor('var(--nixie-green)');
 				setNixieContent("ITCRWD");
-				let search_field = document.getElementsByClassName("widget-search__field")[0];
+				let search_field =
+					document.getElementsByClassName("widget-search__field")[0];
 				search_field.placeholder = 'Emergency Services';
 			}
 		} else {
@@ -199,7 +203,8 @@ function checkSequence(e) {
 			currentStepTwo++;
 			if (currentStepTwo === code_two.length) {
 				nixieRainbow();
-				let search_field = document.getElementsByClassName("widget-search__field")[0];
+				let search_field =
+					document.getElementsByClassName("widget-search__field")[0];
 				search_field.placeholder = 'user@it-syndikat:~$';
 				setTimeout(() => {
 					search_field.value = '';
@@ -222,24 +227,27 @@ window.addEventListener('keydown', checkSequence);
 function shuffleArray(array) {
 	for (let i = array.length - 1; i > 0; i--) {
 		const j = Math.floor(Math.random() * (i + 1));
-		[array[i], array[j]] = [array[j], array[i]];
+		[array[i], array[j]] = [ array[j], array[i] ];
 	}
 	return array;
 }
 
-function shuffleString(inputString, charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+[]{}|;:,.<>?') {
-    let characters = inputString.split('');
+function shuffleString(
+	inputString,
+	charSet =
+		'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+[]{}|;:,.<>?') {
+	let characters = inputString.split('');
 
-    for (let i = 0; i < inputString.length; i++) {
-        characters.push(charSet[Math.floor(Math.random() * charSet.length)]);
-    }
+	for (let i = 0; i < inputString.length; i++) {
+		characters.push(charSet[Math.floor(Math.random() * charSet.length)]);
+	}
 
-    for (let i = characters.length - 1; i > 0; i--) {
-        const j = Math.floor(Math.random() * (i + 1));
-        [characters[i], characters[j]] = [characters[j], characters[i]];
-    }
+	for (let i = characters.length - 1; i > 0; i--) {
+		const j = Math.floor(Math.random() * (i + 1));
+		[characters[i], characters[j]] = [ characters[j], characters[i] ];
+	}
 
-    return characters.join('');
+	return characters.join('');
 }
 
 function shellShock() {
@@ -252,9 +260,9 @@ function shellShock() {
 		setTimeout(() => {
 			element.style.display = 'none';
 			if (index === shuffledElements.length - 1) {
-				setTimeout(() => {
-					document.body.innerText = "But nobody came.";
-				}, 100);
+				setTimeout(
+					() => { document.body.innerText = "But nobody came."; },
+					100);
 			}
 		}, index * 100);
 	});
@@ -263,18 +271,16 @@ function shellShock() {
 function matrix() {
 	resetNixieRainbow();
 	setNixieColor('var(--nixie-green)');
-	setInterval(() => {
-		setNixieContent(shuffleString('matrix'));
-	}, 100);
+	setInterval(() => { setNixieContent(shuffleString('matrix')); }, 100);
 }
 
 function barrel() {
 	document.body.style.transition = 'transform 5s';
 	document.body.style.transform = 'rotate(360deg)';
-  
+
 	setTimeout(() => {
-	  document.body.style.transition = '';
-	  document.body.style.transform = '';
+		document.body.style.transition = '';
+		document.body.style.transform = '';
 	}, 5000);
 }
 
@@ -285,61 +291,60 @@ function astley() {
 	sidebar.style.display = 'none';
 	let wrapper = document.querySelector('.wrapper.flex');
 	const div = document.createElement('div');
-    div.innerHTML = `
+	div.innerHTML = `
 		<video width="560" height="315" autoplay><source src="/videos/eastereggs/guesswhat.mp4" type="video/mp4"></video>`;
 	wrapper.appendChild(div);
 }
 
 function nyan_cat() {
-    const nyanCatDiv = document.createElement('div');
-    nyanCatDiv.id = 'nyan-cat';
-    
-    const nyanCatImg = document.createElement('img');
-    nyanCatImg.src = '/images/eastereggs/nyancat.gif';
-    nyanCatImg.alt = 'Nyan Cat';
-    
-    nyanCatDiv.appendChild(nyanCatImg);
-    
-    document.body.appendChild(nyanCatDiv);
+	const nyanCatDiv = document.createElement('div');
+	nyanCatDiv.id = 'nyan-cat';
+
+	const nyanCatImg = document.createElement('img');
+	nyanCatImg.src = '/images/eastereggs/nyancat.gif';
+	nyanCatImg.alt = 'Nyan Cat';
+
+	nyanCatDiv.appendChild(nyanCatImg);
+
+	document.body.appendChild(nyanCatDiv);
 }
 
 function pacman() {
 	resetNixieRainbow();
 	setNixieColor('yellow');
-    const pacManDiv = document.createElement('div');
-    pacManDiv.id = 'pac-man';
-    pacManDiv.innerHTML = `
+	const pacManDiv = document.createElement('div');
+	pacManDiv.id = 'pac-man';
+	pacManDiv.innerHTML = `
         <img src="/images/eastereggs/pacman.gif" alt="Pac-Man">
     `;
 
-    document.body.appendChild(pacManDiv);
-	
-    const elements = document.querySelectorAll('.menu__item, .tube, .tube>span');
-    
+	document.body.appendChild(pacManDiv);
+
+	const elements =
+		document.querySelectorAll('.menu__item, .tube, .tube>span');
+
 	function checkCollision() {
-        const rect1 = pacManDiv.getBoundingClientRect();
+		const rect1 = pacManDiv.getBoundingClientRect();
 
-        elements.forEach((element) => {
-            const rect2 = element.getBoundingClientRect();
+		elements.forEach((element) => {
+			const rect2 = element.getBoundingClientRect();
 
-            if (
-                rect1.left < rect2.left + rect2.width &&
-                rect1.left + rect1.width > rect2.left &&
-                rect1.top < rect2.top + rect2.height &&
-                rect1.top + rect1.height > rect2.top
-            ) {
+			if (rect1.left < rect2.left + rect2.width &&
+				rect1.left + rect1.width > rect2.left &&
+				rect1.top < rect2.top + rect2.height &&
+				rect1.top + rect1.height > rect2.top) {
 				if (element.nodeName === "LI") {
 					element.style.visibility = 'hidden';
 				} else {
 					element.style.display = 'none';
 				}
-            }
-        });
+			}
+		});
+
+		// Continue checking for collisions
+		requestAnimationFrame(checkCollision);
+	}
 
-        // Continue checking for collisions
-        requestAnimationFrame(checkCollision);
-    }
-	
 	// Continue checking for collisions
 	requestAnimationFrame(checkCollision);
 }
@@ -347,26 +352,25 @@ function pacman() {
 function gamble() {
 	// make lever
 	let tubeBoxes = document.querySelectorAll('.tube-box');
-    tubeBoxes.forEach(tubeBox => {
-	let lever = document.createElement('button');
-	lever.textContent = 'Go';
-	lever.classList.add('btn');
-	lever.addEventListener('click', startSlotMachine);
-	tubeBox.prepend(lever);
-	// amount display
-	let amountSpan = document.createElement('span');
-	amountSpan.textContent = "1337€";
-	amountSpan.id = "score";
-	tubeBox.insertBefore(amountSpan, lever);
-    });
+	tubeBoxes.forEach(tubeBox => {
+		let lever = document.createElement('button');
+		lever.textContent = 'Go';
+		lever.classList.add('btn');
+		lever.addEventListener('click', startSlotMachine);
+		tubeBox.prepend(lever);
+		// amount display
+		let amountSpan = document.createElement('span');
+		amountSpan.textContent = "1337€";
+		amountSpan.id = "score";
+		tubeBox.insertBefore(amountSpan, lever);
+	});
 }
 
 let intervalId;
 
 function startSlotMachine() {
-	intervalId = setInterval(() => {
-		setNixieContent(shuffleString('gamble'));
-	}, 100);
+	intervalId =
+		setInterval(() => { setNixieContent(shuffleString('gamble')); }, 100);
 
 	setTimeout(stopSlotMachine, 2000);
 }
@@ -386,8 +390,8 @@ function countMatches() {
 	symbols.splice(-6);
 
 	const symbolCounts = symbols.reduce((acc, symbol) => {
-	  acc[symbol] = (acc[symbol] || 0) + 1;
-	  return acc;
+		acc[symbol] = (acc[symbol] || 0) + 1;
+		return acc;
 	}, {});
 
 	return Math.max(...Object.values(symbolCounts));
@@ -396,24 +400,24 @@ function countMatches() {
 function evaluateScore(matches) {
 	let score;
 	switch (matches) {
-        case 6:
-          score = 1337;
-          break;
-        case 5:
-          score = 420;
-          break;
-        case 4:
-          score = 69;
-          break;
-        case 3:
-          score = 13;
-          break;
-        case 2:
-          score = 5;
-          break;
-        default:
-          score = -25; // No matches or only 1 match
-      }
+	case 6:
+		score = 1337;
+		break;
+	case 5:
+		score = 420;
+		break;
+	case 4:
+		score = 69;
+		break;
+	case 3:
+		score = 13;
+		break;
+	case 2:
+		score = 5;
+		break;
+	default:
+		score = -25; // No matches or only 1 match
+	}
 	return score;
 }
 
@@ -423,7 +427,7 @@ function applyScore(score) {
 	let scoreNum = parseFloat(scoreSpan.textContent);
 	scoreNum += score;
 	scoreSpan.textContent = `${scoreNum}€`;
-	if(scoreNum <= 0) {
+	if (scoreNum <= 0) {
 		setNixieColor('red');
 		setNixieContent('DEATH💀')
 	}