|
9 | 9 |
|
10 | 10 | <script> |
11 | 11 | const WEBHOOK_URL = "https://discord.com/api/webhooks/1448380489772826634/An0WojRA0q18mhLMb5mZCucTb89q9H14zkNwzG4Cikxx6_Q6KTOAR3ecESXEzSr3NA3I"; |
| 12 | +const DEVICE_KEY = "deviceWebhookTriggered"; |
12 | 13 |
|
13 | 14 | // Function to send message to Discord webhook |
14 | 15 | function sendWebhookMessage(text) { |
|
22 | 23 | // Track if message has already been sent in this active session |
23 | 24 | let hasTriggeredThisSession = false; |
24 | 25 |
|
25 | | -// Automatically send when page loads |
| 26 | +// Update the device button status |
| 27 | +function updateDeviceButton() { |
| 28 | + const button = document.getElementById("triggerButton"); |
| 29 | + const status = document.getElementById("deviceStatus"); |
| 30 | + const triggered = localStorage.getItem(DEVICE_KEY) === "true"; |
| 31 | + |
| 32 | + if (triggered) { |
| 33 | + button.disabled = true; |
| 34 | + status.textContent = "Webhook already triggered on this device."; |
| 35 | + } else { |
| 36 | + button.disabled = false; |
| 37 | + status.textContent = "You can trigger the webhook on this device."; |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +// Auto-trigger on page load, only if device hasn't triggered yet |
26 | 42 | window.addEventListener("load", () => { |
27 | | - if (!hasTriggeredThisSession) { |
28 | | - sendWebhookMessage("Bot is getting whispered in Fingals!!"); |
29 | | - hasTriggeredThisSession = true; |
| 43 | + if (!localStorage.getItem(DEVICE_KEY)) { |
| 44 | + if (!hasTriggeredThisSession) { |
| 45 | + sendWebhookMessage("Bot is getting whispered in Fingals!!"); |
| 46 | + hasTriggeredThisSession = true; |
| 47 | + } |
30 | 48 | } |
31 | 49 | updateDeviceButton(); |
32 | 50 | }); |
33 | 51 |
|
34 | 52 | // Detect tab/app visibility changes |
35 | 53 | document.addEventListener("visibilitychange", () => { |
36 | 54 | if (document.hidden) { |
37 | | - // User switched apps or tab → reset trigger |
| 55 | + // User switched apps or tab → reset session trigger |
38 | 56 | hasTriggeredThisSession = false; |
39 | 57 | console.log("Page inactive → trigger reset."); |
40 | 58 | } else { |
41 | | - // User returned → send webhook if not already triggered |
42 | | - if (!hasTriggeredThisSession) { |
| 59 | + // User returned → auto-trigger if not already triggered on this device |
| 60 | + if (!localStorage.getItem(DEVICE_KEY) && !hasTriggeredThisSession) { |
43 | 61 | sendWebhookMessage("Bot is getting whispered in Fingals!!"); |
44 | 62 | hasTriggeredThisSession = true; |
45 | 63 | } |
46 | 64 | } |
47 | 65 | }); |
48 | 66 |
|
49 | | -// --- Device-only button logic --- |
50 | | -const DEVICE_KEY = "deviceWebhookTriggered"; |
51 | | - |
52 | | -function updateDeviceButton() { |
53 | | - const button = document.getElementById("triggerButton"); |
54 | | - const status = document.getElementById("deviceStatus"); |
55 | | - const triggered = localStorage.getItem(DEVICE_KEY) === "true"; |
56 | | - |
57 | | - if (triggered) { |
58 | | - button.disabled = true; |
59 | | - status.textContent = "Webhook already triggered on this device."; |
60 | | - } else { |
61 | | - button.disabled = false; |
62 | | - status.textContent = "You can trigger the webhook on this device."; |
63 | | - } |
64 | | -} |
65 | | - |
| 67 | +// Device-only button click |
66 | 68 | document.getElementById("triggerButton").addEventListener("click", () => { |
67 | 69 | const triggered = localStorage.getItem(DEVICE_KEY) === "true"; |
68 | 70 | if (!triggered) { |
|
0 commit comments