Skip to content

Commit 8f8cb24

Browse files
committed
IDK why the main.js and styles.css changed but if it works, it works.
also remove one / no. 4
1 parent 6cae827 commit 8f8cb24

5 files changed

Lines changed: 3444 additions & 1543 deletions

File tree

Build/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "htmlrunner",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "A small live HTML/JS runner with console capture.",
55
"main": "index.js",
66
"scripts": {

Build/src/index.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>HTMLRunner</title>
7+
<link rel="shortcut icon" type="image/x-icon" href="favicon.png">
8+
<link rel="apple-touch-icon" href="favicon.png">
9+
<link rel="manifest" href="manifest.json">
710
<!-- Font Awesome CDN -->
811
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
912
<!-- CodeMirror CSS -->
@@ -25,6 +28,7 @@
2528
<div class="header">
2629
<div class="logo">HTMLRunner</div>
2730
<div class="controls">
31+
<button class="btn" id="install-button" hidden>Install App</button>
2832
<button class="btn btn-run" onclick="runCode()"><i class="fas fa-play"></i> Run</button>
2933
<button class="btn btn-format" onclick="formatCode()"><i class="fas fa-code"></i> Format</button>
3034
<button class="btn btn-reset" onclick="resetCode()"><i class="fas fa-undo"></i> Reset</button>
@@ -60,6 +64,45 @@
6064
</div>
6165
</div>
6266
</div>
67+
<script>
68+
document.addEventListener("DOMContentLoaded", function() {
69+
// Register the service worker
70+
if ("serviceWorker" in navigator) {
71+
navigator.serviceWorker.register("service-worker.js");
72+
}
73+
74+
let deferredPrompt;
75+
const installButton = document.getElementById("install-button");
76+
77+
// Listen for the install prompt
78+
window.addEventListener("beforeinstallprompt", (e) => {
79+
e.preventDefault();
80+
deferredPrompt = e;
81+
installButton.hidden = false;
82+
});
83+
84+
// Handle install button click
85+
installButton.addEventListener("click", async () => {
86+
const isStandalone = window.matchMedia("(display-mode: standalone)").matches || window.navigator.standalone;
87+
88+
if (isStandalone) {
89+
console.log("App is already installed");
90+
return;
91+
}
92+
93+
if (deferredPrompt) {
94+
deferredPrompt.prompt();
95+
const { outcome } = await deferredPrompt.userChoice;
96+
deferredPrompt = null;
97+
console.log(outcome === "accepted" ? "User accepted install prompt" : "User dismissed install prompt");
98+
} else {
99+
if (window.matchMedia("(display-mode: browser)").matches) {
100+
window.location.assign("chrome://apps/");
101+
}
102+
}
103+
});
104+
});
105+
</script>
63106
<script src="main.js"></script>
64107
</body>
65108
</html>

index.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>HTMLRunner</title>
7+
<link rel="shortcut icon" type="image/x-icon" href="favicon.png">
8+
<link rel="apple-touch-icon" href="favicon.png">
9+
<link rel="manifest" href="manifest.json">
710
<!-- Font Awesome CDN -->
811
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
912
<!-- CodeMirror CSS -->
@@ -25,6 +28,7 @@
2528
<div class="header">
2629
<div class="logo">HTMLRunner</div>
2730
<div class="controls">
31+
<button class="btn" id="install-button" hidden>Install App</button>
2832
<button class="btn btn-run" onclick="runCode()"><i class="fas fa-play"></i> Run</button>
2933
<button class="btn btn-format" onclick="formatCode()"><i class="fas fa-code"></i> Format</button>
3034
<button class="btn btn-reset" onclick="resetCode()"><i class="fas fa-undo"></i> Reset</button>
@@ -60,6 +64,45 @@
6064
</div>
6165
</div>
6266
</div>
67+
<script>
68+
document.addEventListener("DOMContentLoaded", function() {
69+
// Register the service worker
70+
if ("serviceWorker" in navigator) {
71+
navigator.serviceWorker.register("service-worker.js");
72+
}
73+
74+
let deferredPrompt;
75+
const installButton = document.getElementById("install-button");
76+
77+
// Listen for the install prompt
78+
window.addEventListener("beforeinstallprompt", (e) => {
79+
e.preventDefault();
80+
deferredPrompt = e;
81+
installButton.hidden = false;
82+
});
83+
84+
// Handle install button click
85+
installButton.addEventListener("click", async () => {
86+
const isStandalone = window.matchMedia("(display-mode: standalone)").matches || window.navigator.standalone;
87+
88+
if (isStandalone) {
89+
console.log("App is already installed");
90+
return;
91+
}
92+
93+
if (deferredPrompt) {
94+
deferredPrompt.prompt();
95+
const { outcome } = await deferredPrompt.userChoice;
96+
deferredPrompt = null;
97+
console.log(outcome === "accepted" ? "User accepted install prompt" : "User dismissed install prompt");
98+
} else {
99+
if (window.matchMedia("(display-mode: browser)").matches) {
100+
window.location.assign("chrome://apps/");
101+
}
102+
}
103+
});
104+
});
105+
</script>
63106
<script src="main.js"></script>
64107
</body>
65108
</html>

0 commit comments

Comments
 (0)