Skip to content

Commit 89f5c6d

Browse files
authored
Merge pull request #758 from STForScratch/daniel4-scratch-game
Clicker Game
2 parents c496381 + 1f3a564 commit 89f5c6d

File tree

5 files changed

+137
-0
lines changed

5 files changed

+137
-0
lines changed

extras/game/assets/logo.svg

Lines changed: 4 additions & 0 deletions
Loading

extras/game/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Clicker Game</title>
5+
<meta charset="utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<link rel="stylesheet" href=".\style.css" />
8+
<script src=".\script.js" async></script>
9+
</head>
10+
<body id="body">
11+
<div class="clicker-layer">
12+
<img src=".\assets\logo.svg" id="click">
13+
</div>
14+
<div class="text-layer"><h1>0</h1></div>
15+
</body>
16+
</html>

extras/game/script.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const run = async () => {
2+
try {
3+
let { game: storage } = await chrome.storage.sync.get("game");
4+
var starterStorage = { "version": 1, "clicks": 0 };
5+
6+
// check if storage is trustworthy
7+
if (storage && typeof storage === 'object' && typeof storage.clicks === 'number') {
8+
document.querySelector('.text-layer h1').textContent = String(storage.clicks);
9+
console.log(storage.clicks);
10+
document.getElementById("click").draggable = false;
11+
document.getElementById("click").addEventListener("click", async () => {
12+
storage.clicks += 1;
13+
document.querySelector('.text-layer h1').textContent = String(storage.clicks);
14+
await chrome.storage.sync.set({ "game": storage });
15+
});
16+
} else {
17+
await chrome.storage.sync.set({ "game": starterStorage });
18+
location.reload();
19+
}
20+
} catch (error) {
21+
console.error("Error during storage retrieval:", error);
22+
}
23+
}
24+
25+
const reset = async () => {
26+
try {
27+
await chrome.storage.sync.remove("game");
28+
location.reload();
29+
} catch (error) {
30+
console.error("Error during storage removal:", error);
31+
}
32+
}
33+
34+
// JavaScript
35+
var clickElement = document.getElementById('click');
36+
37+
clickElement.addEventListener('mousedown', function() {
38+
this.classList.add('scale-down');
39+
});
40+
41+
clickElement.addEventListener('mouseup', function() {
42+
this.classList.remove('scale-down');
43+
});
44+
clickElement.addEventListener('mouseleave', function() {
45+
this.classList.remove('scale-down');
46+
});
47+
48+
run();

extras/game/style.css

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Readex+Pro:wght@200;300;400;500;600;700&display=swap');
2+
3+
body {
4+
background-color: #FF9F00;
5+
display: flex;
6+
height: 100vh;
7+
width: 100%;
8+
overflow: hidden;
9+
margin:0em;
10+
}
11+
12+
.clicker-layer{
13+
position:absolute;
14+
user-select: none;
15+
display: flex;
16+
justify-content: center;
17+
align-items: center;
18+
height: 100%;
19+
width: 100%;
20+
z-index: 3;
21+
}
22+
.clicker-layer #click{
23+
/*aloow image to go smaller on smaller window*/
24+
height: auto;
25+
width: auto;
26+
max-height: 207px;
27+
max-width: 207px;
28+
cursor: pointer;
29+
height: auto;
30+
width: auto;
31+
transition: all 0.1s ease-in-out;
32+
}
33+
34+
.text-layer{
35+
margin-top: calc(100vh / 6);
36+
position:relative;
37+
user-select: none;
38+
justify-content: center;
39+
align-items: center;
40+
height: 100vh;
41+
width: 100%;
42+
}
43+
.text-layer h1{
44+
45+
font-size: 5em;
46+
color: #fff;
47+
text-align: center;
48+
margin: 0;
49+
padding: 0;
50+
font-family: 'Readex Pro', sans-serif;
51+
font-weight: 400;
52+
}
53+
54+
/* CSS */
55+
.scale-down {
56+
transform: scale(0.8);
57+
}

extras/popup/popup.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,3 +1385,15 @@ async function getCommit() {
13851385
)})`;
13861386
} catch (err) {}
13871387
}
1388+
1389+
1390+
var iconsclicks = 0;
1391+
1392+
document.querySelector(".searchbaricon")?.addEventListener("click", function () {
1393+
iconsclicks += 1;
1394+
if (iconsclicks > 9) {
1395+
chrome.tabs.create({
1396+
url: "chrome-extension://" + chrome.runtime.id + "/extras/game/index.html",
1397+
});
1398+
}
1399+
})

0 commit comments

Comments
 (0)