Scav Monitoring with Alerts

Scav Allert

  1. // ==UserScript==
  2. // @name Scav Monitoring with Alerts
  3. // @version 1.85
  4. // @include https://*/game.php*screen=place&mode=scavenge
  5. // @include https://*/game.php*screen=place&mode=scavenge&
  6. // @namespace https://greasyfork.org/users/1388863
  7. // @description Scav Allert
  8. // ==/UserScript==
  9.  
  10. (function () {
  11. 'use strict';
  12.  
  13. const botToken = "8151644407:AAHl5d3W8wZnQeCaFJHLNouYQCzqgS7zi-s"; // Ganti dengan token bot Anda
  14. let lastTelegramMessageTime = 0; // Track last message sent time
  15. let captchaDetected = false; // Track CAPTCHA detection
  16. let intervalId = null; // Ensure only one interval runs
  17.  
  18. // Function to send a message to Telegram (rate-limited to 1x per 5 minutes)
  19. function sendToTelegram(message) {
  20. const currentTime = Date.now();
  21. if (currentTime - lastTelegramMessageTime >= 300000) { // 5-minute limit
  22. const chatId = localStorage.getItem('telegramChatId') || '0';
  23. const url = `https://api.telegram.org/bot${botToken}/sendMessage?chat_id=${chatId}&text=${encodeURIComponent(message)}`;
  24. fetch(url)
  25. .then(response => {
  26. if (!response.ok) {
  27. console.error("Failed to send message to Telegram:", response.statusText);
  28. } else {
  29. console.log("Message sent to Telegram:", message);
  30. }
  31. })
  32. .catch(error => console.error("Telegram API error:", error));
  33. lastTelegramMessageTime = currentTime; // Update last message time
  34. } else {
  35. console.log("Telegram message rate limit hit. Skipping message:", message);
  36. }
  37. }
  38.  
  39. // Function to parse time from countdown text
  40. function parseTime(timeText) {
  41. const parts = timeText.split(":").map(Number);
  42. return parts[0] * 3600 + parts[1] * 60 + parts[2]; // Convert hours, minutes, seconds to total seconds
  43. }
  44.  
  45. // Function to monitor countdown
  46. let lastNotification = null; // Track the last notification time
  47. function monitorCountdown() {
  48.  
  49. const countdownElement = document.querySelector('.scavenge-option .return-countdown');
  50. if (countdownElement) {
  51. const timeText = countdownElement.innerText.trim();
  52. const remainingTime = parseTime(timeText);
  53.  
  54. console.log(`Remaining time: ${remainingTime} seconds`);
  55.  
  56. // if (remainingTime % 1800 === 0 && remainingTime !== lastNotification) {
  57. // // Notify on every 30-minute mark
  58. // sendToTelegram(`Countdown reached ${remainingTime / 60} minutes.`);
  59. // lastNotification = remainingTime; }
  60. if (remainingTime === 300 && remainingTime !== lastNotification) {
  61. // Notify when 5 minutes are left
  62. sendToTelegram("Countdown has 5 minutes remaining!");
  63. lastNotification = remainingTime;
  64. }
  65.  
  66. if (remainingTime <= 0) {
  67. console.log("Scav completed!");
  68. sendToTelegram("Scav Selesai");
  69.  
  70. // Start the new countdown (1-10 minutes)
  71. startPostScavCountdown();
  72. clearInterval(intervalId); // Stop monitoring after scav is complete
  73. intervalId = null; // Reset intervalId
  74. }
  75. } else {
  76. if (!captchaDetected) {
  77. sendToTelegram("Tidak Ada Scav");
  78. startPostScavCountdown();
  79. clearInterval(intervalId); // Stop monitoring
  80. intervalId = null; // Reset intervalId
  81. }
  82. }
  83. }
  84.  
  85. // Function to start the countdown after scavenging is done (1-10 minutes)
  86. function startPostScavCountdown() {
  87. const countdownTime = Math.floor(Math.random() * 2 * 60) + 60; // Random countdown between 1-10 minutes (60-600 seconds)
  88. let timeLeft = countdownTime;
  89. const countdownPopup = document.createElement("div");
  90. countdownPopup.style.position = "fixed";
  91. countdownPopup.style.bottom = "30px";
  92. countdownPopup.style.right = "30px";
  93. countdownPopup.style.padding = "10px 20px";
  94. countdownPopup.style.fontSize = "16px";
  95. countdownPopup.style.backgroundColor = "#333";
  96. countdownPopup.style.color = "white";
  97. countdownPopup.style.borderRadius = "5px";
  98. countdownPopup.style.zIndex = "1000";
  99. document.body.appendChild(countdownPopup);
  100.  
  101. const countdownInterval = setInterval(() => {
  102. if (timeLeft <= 0) {
  103. clearInterval(countdownInterval);
  104. countdownPopup.innerText = `Post Scav countdown finished!`;
  105. window.location.href = "/game.php?screen=place&mode=scavenge_mass";
  106. console.log("Redirecting to mass scavenge page...");
  107. if (localStorage.getItem('redirectToMassScavenge') === 'true') {
  108. window.location.href = "/game.php?screen=place&mode=scavenge_mass";
  109. }
  110. } else {
  111. countdownPopup.innerText = `Post Scav Time left: ${Math.floor(timeLeft / 60)}m ${timeLeft % 60}s`;
  112. timeLeft--;
  113. }
  114. }, 1000); // Update countdown every second
  115. }
  116.  
  117. // Ensure only one interval runs
  118. if (!intervalId) {
  119. intervalId = setInterval(monitorCountdown, 1000); // Start monitoring countdown for Scavenge
  120. }
  121. })();