Guest User

DSRPG Notifications

a guest
Dec 13th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. // ==UserScript==
  2. // @name DSRPG Notifications
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3.14
  5. // @description People wanted some notifications. This will notify you if your autos are under 10, or if a boss is spawning in <10 minutes!
  6. // @author Bysn (www.avabur.com) lol XD
  7. // @match http*://www.dsrpg.co/m.php*
  8. // @grant none
  9. // @run-at document-end
  10. // @require http://code.jquery.com/jquery-3.4.1.min.js
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. // Set this once upon script initialization
  15. var nextBossNotification = Date.now();
  16. var notifiedOfLowActions = false;
  17.  
  18. function checkTheBusiness()
  19. {
  20. var $realContent = $('#main').contents().find('html') || $($('#main').contents().find('html'));
  21. var $chatContent = $('#chat-frame').contents().find('html') || $($('#chat-frame').contents().find('html'));
  22.  
  23. var currentTime = Date.now();
  24. var notifications = [];
  25.  
  26. if (nextBossNotification < currentTime)
  27. {
  28. // Parse the current server time, then use the values we need
  29. var date = $chatContent.find('#chat-top').text().match(/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/);
  30. console.log(date);
  31. var currentHour = Number(date[4]);
  32. var currentMinute = Number(date[5]);
  33.  
  34. console.log(currentMinute);
  35. if (currentHour % 3 == 2 && currentMinute >= 50)
  36. {
  37. notifications.push('a boss will spawn in less than 10 minutes');
  38.  
  39. // Set a timer for when we can notify again
  40. // Bosses happen every 3 hours, so...
  41. // // 60 seconds * 60 minutes * 3 hours * 1000 ms
  42. nextBossNotification = currentTime + (60 * 60 * 3 * 1000);
  43. }
  44. }
  45.  
  46. if (!notifiedOfLowActions)
  47. {
  48. var autoChecker = $realContent.find('.statautos').text();
  49.  
  50. var parsed = autoChecker.match(/(\d+)\/(\d+)/);
  51.  
  52. if (parsed)
  53. {
  54. var currentAutos = parsed[1];
  55.  
  56. if (currentAutos < 10)
  57. {
  58. notifications.push('you are low on autos');
  59. notifiedOfLowActions = true;
  60. }
  61. else
  62. {
  63. notifiedOfLowActions = false;
  64. }
  65. }
  66. }
  67.  
  68. if (notifications.length)
  69. {
  70. var complete_Message = add_Commas(notifications);
  71. var capitalized = complete_Message.charAt(0).toUpperCase() + complete_Message.slice(1);
  72.  
  73. display_Notification(capitalized + '!');
  74. }
  75.  
  76. setTimeout(function()
  77. {
  78. checkTheBusiness();
  79. }, 5000);
  80. }
  81.  
  82. function display_Notification(message)
  83. {
  84. var notification;
  85.  
  86. if (!("Notification" in window))
  87. {
  88. // Do nothing
  89. return;
  90. }
  91.  
  92. if (Notification.permission === "granted")
  93. {
  94. notification = new Notification("DSRPG", { body: message, icon: "favicon.ico" });
  95. }
  96. else if (Notification.permission !== "denied")
  97. {
  98. Notification.requestPermission().then(function(permission)
  99. {
  100. if (permission === "granted")
  101. {
  102. notification = new Notification("DSRPG", { body: message, icon: "favicon.ico" });
  103. }
  104. });
  105. }
  106.  
  107. if (notification)
  108. {
  109. notification.onclick = function()
  110. {
  111. window.focus();
  112. }
  113. }
  114. }
  115.  
  116. function add_Commas(list)
  117. {
  118. if (!Array.isArray(list)) { return list; }
  119.  
  120. var start = list.slice(0, -1);
  121. var one = start.join(', ');
  122. var two = [one].concat(list.slice(-1)).join('');
  123.  
  124. var result = [list.slice(0, -1).join(', ')]
  125. .concat(list.slice(-1)).filter(function(el) { return el != ''; });
  126.  
  127. return result.join(
  128. (result.length == 2 && start.length > 1 ? ', and ' : ' and ')
  129. );
  130. }
  131.  
  132. setTimeout(function()
  133. {
  134. checkTheBusiness();
  135. }, 5000);
  136. })();
Advertisement
Add Comment
Please, Sign In to add comment