Skip to content

Commit dd174eb

Browse files
committed
Allow killing sheep
1 parent 9d4214c commit dd174eb

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

components/apps/Terminal/useCommandInterpreter.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,9 @@ const useCommandInterpreter = (
921921
}
922922
case "sheep":
923923
case "esheep": {
924-
const { default: spawnSheep } = await import("utils/spawnSheep");
924+
const { countSheep, killSheep, spawnSheep } = await import(
925+
"utils/spawnSheep"
926+
);
925927
let [count = 1, duration = 0] = commandArgs;
926928

927929
if (!Number.isNaN(count) && !Number.isNaN(duration)) {
@@ -936,10 +938,12 @@ const useCommandInterpreter = (
936938
const maxDuration =
937939
(duration || (count > 1 ? 1 : 0)) * MILLISECONDS_IN_SECOND;
938940

939-
Array.from({ length: count })
941+
Array.from({ length: count === 0 ? countSheep() : count })
940942
.fill(0)
941943
.map(() => Math.floor(Math.random() * maxDuration))
942-
.forEach((delay) => setTimeout(spawnSheep, delay));
944+
.forEach((delay) =>
945+
setTimeout(count === 0 ? killSheep : spawnSheep, delay)
946+
);
943947
}
944948
break;
945949
}

components/system/Dialogs/Run/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from "utils/constants";
2424
import { getExtension, haltEvent } from "utils/functions";
2525
import { getIpfsFileName, getIpfsResource } from "utils/ipfs";
26-
import spawnSheep from "utils/spawnSheep";
26+
import { spawnSheep } from "utils/spawnSheep";
2727
import Icon from "styles/common/Icon";
2828

2929
const OPEN_ID = "open";

components/system/Taskbar/Clock/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const easterEggOnClick: React.MouseEventHandler<HTMLElement> = async ({
5050
triggerEasterEggCountdown -= 1;
5151

5252
if (triggerEasterEggCountdown === 0) {
53-
const { default: spawnSheep } = await import("utils/spawnSheep");
53+
const { spawnSheep } = await import("utils/spawnSheep");
5454

5555
spawnSheep();
5656

components/system/Taskbar/StartButton/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const StartButton: FC<StartButtonProps> = ({
7878
toggleStartMenu();
7979

8080
if (ctrlKey && shiftKey) {
81-
const { default: spawnSheep } = await import("utils/spawnSheep");
81+
const { spawnSheep } = await import("utils/spawnSheep");
8282

8383
spawnSheep();
8484
}

utils/spawnSheep.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const pickRandomPet = (): string => {
4141
return petPath;
4242
};
4343

44-
const spawnSheep = (): Promise<void> =>
44+
export const spawnSheep = (): Promise<void> =>
4545
loadFiles(["/Program Files/eSheep/eSheep.js"]).then(() => {
4646
if (window.Sheep) {
4747
const sheep = new window.Sheep({
@@ -59,4 +59,14 @@ const spawnSheep = (): Promise<void> =>
5959
}
6060
});
6161

62-
export default spawnSheep;
62+
const sheepSelector =
63+
"main > div[style*='z-index: 2000'] > img[src^='data:image']";
64+
65+
export const killSheep = (): void => {
66+
const firstSheep = document.querySelector(sheepSelector) as HTMLElement;
67+
68+
firstSheep?.parentElement?.remove();
69+
};
70+
71+
export const countSheep = (): number =>
72+
document.querySelectorAll(sheepSelector).length;

0 commit comments

Comments
 (0)