Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name DSRPG Notifications
- // @namespace http://tampermonkey.net/
- // @version 0.3.14
- // @description People wanted some notifications. This will notify you if your autos are under 10, or if a boss is spawning in <10 minutes!
- // @author Bysn
- // @match http*://www.dsrpg.co/m.php*
- // @grant none
- // @run-at document-end
- // @require http://code.jquery.com/jquery-3.4.1.min.js
- // ==/UserScript==
- (function() {
- // Set this once upon script initialization
- var nextBossNotification = Date.now();
- var notifiedOfLowActions = false;
- function checkTheBusiness()
- {
- var $realContent = $('#main').contents().find('html') || $($('#main').contents().find('html'));
- var $chatContent = $('#chat-frame').contents().find('html') || $($('#chat-frame').contents().find('html'));
- var currentTime = Date.now();
- var notifications = [];
- if (nextBossNotification < currentTime)
- {
- // Parse the current server time, then use the values we need
- var date = $chatContent.find('#chat-top').text().match(/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/);
- var currentHour = Number(date[4]);
- var currentMinute = Number(date[5]);
- if (currentHour % 3 == 2 && currentMinute >= 50)
- {
- notifications.push('a boss will spawn in less than 10 minutes');
- // Set a timer for when we can notify again
- // Bosses happen every 3 hours, so...
- // // 60 seconds * 60 minutes * 3 hours * 1000 ms
- nextBossNotification = currentTime + (60 * 60 * 3 * 1000);
- }
- }
- if (!notifiedOfLowActions)
- {
- var autoChecker = $realContent.find('.statautos').text();
- var parsed = autoChecker.match(/(\d+)\/(\d+)/);
- if (parsed)
- {
- var currentAutos = parsed[1];
- if (currentAutos < 10)
- {
- notifications.push('you are low on autos');
- notifiedOfLowActions = true;
- }
- else
- {
- notifiedOfLowActions = false;
- }
- }
- }
- if (notifications.length)
- {
- var complete_Message = add_Commas(notifications);
- var capitalized = complete_Message.charAt(0).toUpperCase() + complete_Message.slice(1);
- display_Notification(capitalized + '!');
- }
- setTimeout(function()
- {
- checkTheBusiness();
- }, 5000);
- }
- function display_Notification(message)
- {
- var notification;
- if (!("Notification" in window))
- {
- // Do nothing
- return;
- }
- if (Notification.permission === "granted")
- {
- notification = new Notification("DSRPG", { body: message, icon: "favicon.ico" });
- }
- else if (Notification.permission !== "denied")
- {
- Notification.requestPermission().then(function(permission)
- {
- if (permission === "granted")
- {
- notification = new Notification("DSRPG", { body: message, icon: "favicon.ico" });
- }
- });
- }
- if (notification)
- {
- notification.onclick = function()
- {
- window.focus();
- }
- }
- }
- function add_Commas(list)
- {
- if (!Array.isArray(list)) { return list; }
- var start = list.slice(0, -1);
- var one = start.join(', ');
- var two = [one].concat(list.slice(-1)).join('');
- var result = [list.slice(0, -1).join(', ')]
- .concat(list.slice(-1)).filter(function(el) { return el != ''; });
- return result.join(
- (result.length == 2 && start.length > 1 ? ', and ' : ' and ')
- );
- }
- setTimeout(function()
- {
- checkTheBusiness();
- }, 5000);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement