Skip to content

Commit 7135bd9

Browse files
Update index.html
1 parent 0a0c3bf commit 7135bd9

1 file changed

Lines changed: 21 additions & 29 deletions

File tree

index.html

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,46 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>1</title>
4+
<title>Webhook Auto Trigger</title>
55
</head>
66
<body>
7-
8-
<h2>Webhook Test</h2>
9-
<button id="send">Send to Webhook</button>
10-
117
<script>
12-
const WEBHOOK_URL = "https://discord.com/api/webhooks/1448380489772826634/An0WojRA0q18mhLMb5mZCucTb89q9H14zkNwzG4Cikxx6_Q6KTOAR3ecESXEzSr3NA3I"; // replace with regenerated webhook
8+
const WEBHOOK_URL = "https://discord.com/api/webhooks/1448380489772826634/An0WojRA0q18mhLMb5mZCucTb89q9H14zkNwzG4Cikxx6_Q6KTOAR3ecESXEzSr3NA3I";
139

14-
// Send a simple message to the webhook
10+
// Function to send message to Discord webhook
1511
function sendWebhookMessage(text) {
1612
fetch(WEBHOOK_URL, {
1713
method: "POST",
1814
headers: { "Content-Type": "application/json" },
19-
body: JSON.stringify({
20-
content: text
21-
})
22-
}).catch(err => console.error("Failed:", err));
15+
body: JSON.stringify({ content: text })
16+
}).catch(err => console.error("Webhook error:", err));
2317
}
2418

25-
// When user taps the button:
26-
document.getElementById("send").onclick = () => {
27-
sendWebhookMessage("Button pressed!");
28-
};
29-
30-
// Track activity state
19+
// Track if message has already been sent in this active session
3120
let hasTriggeredThisSession = false;
3221

33-
// Send message on visibility change
34-
document.addEventListener("visibilitychange", () => {
35-
36-
// Page goes to background (user switches apps or tabs)
37-
if (document.hidden) {
38-
console.log("User left the app → resetting trigger.");
39-
hasTriggeredThisSession = false; // reset state
22+
// Automatically send when page loads
23+
window.addEventListener("load", () => {
24+
if (!hasTriggeredThisSession) {
25+
sendWebhookMessage("User visited the page!");
26+
hasTriggeredThisSession = true;
4027
}
28+
});
4129

42-
// Page becomes active again
43-
else {
44-
console.log("User returned → firing trigger.");
30+
// Detect tab/app visibility changes
31+
document.addEventListener("visibilitychange", () => {
32+
if (document.hidden) {
33+
// User switched apps or tab → reset trigger
34+
hasTriggeredThisSession = false;
35+
console.log("Page inactive → trigger reset.");
36+
} else {
37+
// User returned → send webhook if not already triggered
4538
if (!hasTriggeredThisSession) {
46-
sendWebhookMessage("User returned to the app.");
39+
sendWebhookMessage("User returned to the page!");
4740
hasTriggeredThisSession = true;
4841
}
4942
}
5043
});
5144
</script>
52-
5345
</body>
5446
</html>

0 commit comments

Comments
 (0)