Advertisement
Guest User

DSRPG Notifications

a guest
Dec 13th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 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
  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.  
  31. var currentHour = Number(date[4]);
  32. var currentMinute = Number(date[5]);
  33.  
  34. if (currentHour % 3 == 2 && currentMinute >= 50)
  35. {
  36. notifications.push('a boss will spawn in less than 10 minutes');
  37.  
  38. // Set a timer for when we can notify again
  39. // Bosses happen every 3 hours, so...
  40. // // 60 seconds * 60 minutes * 3 hours * 1000 ms
  41. nextBossNotification = currentTime + (60 * 60 * 3 * 1000);
  42. }
  43. }
  44.  
  45. if (!notifiedOfLowActions)
  46. {
  47. var autoChecker = $realContent.find('.statautos').text();
  48.  
  49. var parsed = autoChecker.match(/(\d+)\/(\d+)/);
  50.  
  51. if (parsed)
  52. {
  53. var currentAutos = parsed[1];
  54.  
  55. if (currentAutos < 10)
  56. {
  57. notifications.push('you are low on autos');
  58. notifiedOfLowActions = true;
  59. }
  60. else
  61. {
  62. notifiedOfLowActions = false;
  63. }
  64. }
  65. }
  66.  
  67. if (notifications.length)
  68. {
  69. var complete_Message = add_Commas(notifications);
  70. var capitalized = complete_Message.charAt(0).toUpperCase() + complete_Message.slice(1);
  71.  
  72. display_Notification(capitalized + '!');
  73. }
  74.  
  75. setTimeout(function()
  76. {
  77. checkTheBusiness();
  78. }, 5000);
  79. }
  80.  
  81. function display_Notification(message)
  82. {
  83. var notification;
  84.  
  85. if (!("Notification" in window))
  86. {
  87. // Do nothing
  88. return;
  89. }
  90.  
  91. if (Notification.permission === "granted")
  92. {
  93. notification = new Notification("DSRPG", { body: message, icon: "favicon.ico" });
  94. }
  95. else if (Notification.permission !== "denied")
  96. {
  97. Notification.requestPermission().then(function(permission)
  98. {
  99. if (permission === "granted")
  100. {
  101. notification = new Notification("DSRPG", { body: message, icon: "favicon.ico" });
  102. }
  103. });
  104. }
  105.  
  106. if (notification)
  107. {
  108. notification.onclick = function()
  109. {
  110. window.focus();
  111. }
  112. }
  113. }
  114.  
  115. function add_Commas(list)
  116. {
  117. if (!Array.isArray(list)) { return list; }
  118.  
  119. var start = list.slice(0, -1);
  120. var one = start.join(', ');
  121. var two = [one].concat(list.slice(-1)).join('');
  122.  
  123. var result = [list.slice(0, -1).join(', ')]
  124. .concat(list.slice(-1)).filter(function(el) { return el != ''; });
  125.  
  126. return result.join(
  127. (result.length == 2 && start.length > 1 ? ', and ' : ' and ')
  128. );
  129. }
  130.  
  131. setTimeout(function()
  132. {
  133. checkTheBusiness();
  134. }, 5000);
  135. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement