feat: YWRkIGEgbGl0dGxlIGNoYXR0eSBhY2hpZXZlbWVudA==
This commit is contained in:
BIN
web/audio/achievement-unlocked.mp3
Normal file
BIN
web/audio/achievement-unlocked.mp3
Normal file
Binary file not shown.
@@ -37,8 +37,14 @@
|
|||||||
<input id="volume-slider" type="range" min="0" max="100" step="1" />
|
<input id="volume-slider" type="range" min="0" max="100" step="1" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
<aside role="alert" id="notification">
|
||||||
|
<p id="notification-title">a little chatty</p>
|
||||||
|
<p id="notification-body">make milo meow 100 times</p>
|
||||||
|
</aside>
|
||||||
|
|
||||||
<img id="cat" src="./images/cat-0.png">
|
<img id="cat" src="./images/cat-0.png">
|
||||||
<img id="eeping-cat" src="./images/eeping-cat.png">
|
<img id="eeping-cat" src="./images/eeping-cat.png">
|
||||||
<img id="heart" src="./images/heart.png">
|
<img id="heart" src="./images/heart.png">
|
||||||
@@ -54,6 +60,7 @@
|
|||||||
<audio id="click-audio" preload="auto" src="./audio/click.wav"></audio>
|
<audio id="click-audio" preload="auto" src="./audio/click.wav"></audio>
|
||||||
<audio id="click-release-audio" preload="auto" src="./audio/click-release.wav"></audio>
|
<audio id="click-release-audio" preload="auto" src="./audio/click-release.wav"></audio>
|
||||||
<audio id="meow-audio" preload="auto" src="./audio/cat-meow.mp3"></audio>
|
<audio id="meow-audio" preload="auto" src="./audio/cat-meow.mp3"></audio>
|
||||||
|
<audio id="achievement-unlocked-audio" preload="auto" src="./audio/achievement-unlocked.mp3"></audio>
|
||||||
|
|
||||||
<script type="module" src="./bg.js"></script>
|
<script type="module" src="./bg.js"></script>
|
||||||
<script type="module" src="./script.js"></script>
|
<script type="module" src="./script.js"></script>
|
||||||
|
@@ -8,10 +8,17 @@ const catImg = document.getElementById("cat");
|
|||||||
const heartImg = document.getElementById("heart");
|
const heartImg = document.getElementById("heart");
|
||||||
const volumeSlider = document.getElementById("volume-slider");
|
const volumeSlider = document.getElementById("volume-slider");
|
||||||
const currentVolumeLabel = document.getElementById("current-volume-label");
|
const currentVolumeLabel = document.getElementById("current-volume-label");
|
||||||
|
const listenerCountLabel = document.getElementById("listener-count");
|
||||||
|
const notificationContainer = document.getElementById("notification");
|
||||||
|
const notificationTitle = document.getElementById("notification-title");
|
||||||
|
const notificationBody = document.getElementById("notification-body");
|
||||||
|
|
||||||
const clickAudio = document.getElementById("click-audio");
|
const clickAudio = document.getElementById("click-audio");
|
||||||
const clickReleaseAudio = document.getElementById("click-release-audio");
|
const clickReleaseAudio = document.getElementById("click-release-audio");
|
||||||
const meowAudio = document.getElementById("meow-audio");
|
const meowAudio = document.getElementById("meow-audio");
|
||||||
const listenerCountLabel = document.getElementById("listener-count");
|
const achievementUnlockedAudio = document.getElementById(
|
||||||
|
"achievement-unlocked-audio",
|
||||||
|
);
|
||||||
|
|
||||||
let isPlaying = false;
|
let isPlaying = false;
|
||||||
let isFading = false;
|
let isFading = false;
|
||||||
@@ -19,6 +26,7 @@ let currentAudio;
|
|||||||
let maxVolume = 100;
|
let maxVolume = 100;
|
||||||
let currentVolume = 0;
|
let currentVolume = 0;
|
||||||
let saveVolumeTimeout = null;
|
let saveVolumeTimeout = null;
|
||||||
|
let meowCount = 0;
|
||||||
let ws = connectToWebSocket();
|
let ws = connectToWebSocket();
|
||||||
|
|
||||||
function playAudio() {
|
function playAudio() {
|
||||||
@@ -134,7 +142,9 @@ function enableSpaceBarControl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function connectToWebSocket() {
|
function connectToWebSocket() {
|
||||||
const ws = new WebSocket(`ws://${location.host}/ws`);
|
const ws = new WebSocket(
|
||||||
|
`${location.protocol === "https:" ? "wss:" : "ws:"}//${location.host}/ws`,
|
||||||
|
);
|
||||||
ws.onmessage = (event) => {
|
ws.onmessage = (event) => {
|
||||||
console.log(event.data);
|
console.log(event.data);
|
||||||
|
|
||||||
@@ -189,6 +199,34 @@ function loadInitialVolume() {
|
|||||||
document.getElementById("volume-slider-container").style.display = "flex";
|
document.getElementById("volume-slider-container").style.display = "flex";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadMeowCount() {
|
||||||
|
const lastMeowCount = localStorage.getItem("meowCount");
|
||||||
|
if (!lastMeowCount) {
|
||||||
|
meowCount = 0;
|
||||||
|
} else {
|
||||||
|
const n = Number.parseInt(lastMeowCount);
|
||||||
|
if (Number.isNaN(n)) {
|
||||||
|
meowCount = 0;
|
||||||
|
} else {
|
||||||
|
meowCount += n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showNotification(title, content, duration) {
|
||||||
|
notificationTitle.innerText = title;
|
||||||
|
notificationBody.innerText = content;
|
||||||
|
notificationContainer.style.display = "block";
|
||||||
|
notificationContainer.style.animation = "0.5s linear 0s notification-fade-in";
|
||||||
|
setTimeout(() => {
|
||||||
|
notificationContainer.style.animation =
|
||||||
|
"0.5s linear 0s notification-fade-out";
|
||||||
|
setTimeout(() => {
|
||||||
|
notificationContainer.style.display = "none";
|
||||||
|
}, 450);
|
||||||
|
}, duration);
|
||||||
|
}
|
||||||
|
|
||||||
playBtn.onmousedown = () => {
|
playBtn.onmousedown = () => {
|
||||||
clickAudio.play();
|
clickAudio.play();
|
||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
@@ -231,8 +269,19 @@ meowAudio.onplay = () => {
|
|||||||
heartImg.style.display = "none";
|
heartImg.style.display = "none";
|
||||||
heartImg.style.animation = "";
|
heartImg.style.animation = "";
|
||||||
}, 900);
|
}, 900);
|
||||||
|
|
||||||
|
meowCount += 1;
|
||||||
|
localStorage.setItem("meowCount", `${meowCount}`);
|
||||||
|
|
||||||
|
if (meowCount === 100) {
|
||||||
|
showNotification("a little chatty", "make milo meow 100 times", 5000);
|
||||||
|
achievementUnlockedAudio.play();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// don't wanna jumpscare ppl
|
||||||
|
achievementUnlockedAudio.volume = 0.05;
|
||||||
|
|
||||||
window.addEventListener("offline", () => {
|
window.addEventListener("offline", () => {
|
||||||
ws = null;
|
ws = null;
|
||||||
});
|
});
|
||||||
@@ -241,6 +290,7 @@ window.addEventListener("online", () => {
|
|||||||
ws = connectToWebSocket();
|
ws = connectToWebSocket();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
loadMeowCount();
|
||||||
loadInitialVolume();
|
loadInitialVolume();
|
||||||
animateCat();
|
animateCat();
|
||||||
enableSpaceBarControl();
|
enableSpaceBarControl();
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
:root {
|
:root {
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
--text: #4c4f69;
|
--text: #4c4f69;
|
||||||
|
--surface0: #ccd0da;
|
||||||
--surface1: #bcc0cc;
|
--surface1: #bcc0cc;
|
||||||
--base: #eff1f5;
|
--base: #eff1f5;
|
||||||
--lavender: #7287fd;
|
--lavender: #7287fd;
|
||||||
@@ -149,17 +150,6 @@ a {
|
|||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
#volume-slider-container {
|
|
||||||
display: none;
|
|
||||||
justify-content: start;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
#volume-slider-container > output {
|
|
||||||
color: var(--text);
|
|
||||||
margin-right: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (-webkit-min-device-pixel-ratio: 0) {
|
@media screen and (-webkit-min-device-pixel-ratio: 0) {
|
||||||
input[type="range"] {
|
input[type="range"] {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@@ -333,3 +323,55 @@ input[type="range"]::-ms-fill-upper {
|
|||||||
right: 50%;
|
right: 50%;
|
||||||
height: 15px;
|
height: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#volume-slider-container {
|
||||||
|
display: none;
|
||||||
|
justify-content: start;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#volume-slider-container > output {
|
||||||
|
color: var(--text);
|
||||||
|
margin-right: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
aside#notification {
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
background: var(--surface0);
|
||||||
|
padding: 1rem 2rem;
|
||||||
|
margin: 2rem;
|
||||||
|
border: 2px solid var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
aside#notification > p {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
aside#notification > #notification-title {
|
||||||
|
font-weight: 700;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes notification-fade-in {
|
||||||
|
0% {
|
||||||
|
display: block;
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes notification-fade-out {
|
||||||
|
0% {
|
||||||
|
opactiy: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user