xeonthread

Untitled

Aug 14th, 2019
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Ikariam desktop notifications
  3. // @namespace    Danielv123
  4. // @version      1.9
  5. // @description  Runs when you have ikariam open and provides push notifications when the advisors lights up.
  6. // @author       Danielv123
  7. // @match        http://*.ikariam.gameforge.com/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. // request permission on page load
  12. document.addEventListener('DOMContentLoaded', function () {
  13.     if (Notification.permission !== "granted") {
  14.         Notification.requestPermission();
  15.     }
  16. });
  17. // http://s28-en.ikariam.gameforge.com/skin/layout/advisors/mayor_premium_active.png
  18. // $('#js_GlobalMenu_cities')[0].className == "premiumactive"
  19. // main checking loop
  20. setInterval(function() {
  21.     if (Notification.permission !== "granted")
  22.         Notification.requestPermission();
  23.     else {
  24.         // check if the advisors are glowing
  25.         // City advisor
  26.         if ($('#js_GlobalMenu_cities')[0].className == "normalactive") {
  27.             console.log('Ding!');
  28.             notifyMe("Ikariam", "Something happened in one of your towns!", "http://s28-en.ikariam.gameforge.com/skin/layout/advisors/mayor_active.png");
  29.         }
  30.         if ($('#js_GlobalMenu_cities')[0].className == "premiumactive") {
  31.             console.log('Ding!');
  32.             notifyMe("Ikariam", "Something happened in one of your towns!", "http://s28-en.ikariam.gameforge.com/skin/layout/advisors/mayor_premium_active.png");
  33.         }
  34.         // diplomacy advisor
  35.         if ($('#js_GlobalMenu_diplomacy')[0].className == "normalactive") {
  36.             console.log('Ding!');
  37.             notifyMe("Ikariam", "Someone sent you a message!", "http://s28-en.ikariam.gameforge.com/skin/layout/advisors/diplomat_active.png");
  38.         }
  39.         if ($('#js_GlobalMenu_diplomacy')[0].className == "premiumactive") {
  40.             console.log('Ding!');
  41.             notifyMe("Ikariam", "Someone sent you a message!", "http://s28-en.ikariam.gameforge.com/skin/layout/advisors/diplomat_premium_active.png");
  42.         }
  43.         // military advisor
  44.         // by checking if military is !normal we can also include the red status
  45.         if ($('#js_GlobalMenu_military')[0].className == "normalactive") {
  46.             console.log('Ding!');
  47.             notifyMe("Ikariam", "Your military advisor is trying to tell you something!", "http://s28-en.ikariam.gameforge.com/skin/layout/advisors/general_active.png");
  48.         }
  49.         if ($('#js_GlobalMenu_military')[0].className == "premiumactive") {
  50.             console.log('Ding!');
  51.             notifyMe("Ikariam", "Your military advisor is trying to tell you something!", "http://s28-en.ikariam.gameforge.com/skin/layout/advisors/general_premium_active.png");
  52.         }
  53.         if ($('#js_GlobalMenu_military')[0].className == "normalalert") {
  54.             console.log('Ding!');
  55.             notifyMe("Ikariam", "You are under attack!", "http://s28-en.ikariam.gameforge.com/skin/layout/advisors/general_alert.png");
  56.         }
  57.         if ($('#js_GlobalMenu_military')[0].className == "premiumalert") {
  58.             console.log('Ding!');
  59.             notifyMe("Ikariam", "You are under attack!", "http://s28-en.ikariam.gameforge.com/skin/layout/advisors/general_premium_alert.png");
  60.         }
  61.         // research advisor
  62.         if ($('#js_GlobalMenu_research')[0].className == "normalactive") {
  63.             console.log('Ding!');
  64.             notifyMe("Ikariam", "New research aviable!", "http://s28-en.ikariam.gameforge.com/skin/layout/advisors/scientist_active.png");
  65.         }
  66.         if ($('#js_GlobalMenu_research')[0].className == "premiumactive") {
  67.             console.log('Ding!');
  68.             notifyMe("Ikariam", "New research aviable!", "http://s28-en.ikariam.gameforge.com/skin/layout/advisors/scientist_premium_active.png");
  69.         }
  70.     }
  71.     // wait 60.000 ms (1 min) between checking for notifications
  72. },30000);
  73.  
  74. function soundClick() {
  75.     var audio = new Audio();
  76.     audio.src = 'https://soundslibmp3.ru/sounds/1517303822_165.wav';
  77.     audio.autoplay = true;
  78.     }
  79.  
  80. function notifyMe(title, message, picture) {
  81.     // check if functionality exists
  82.     if (!Notification) {
  83.         alert('Desktop notifications not available in your browser. Try Chromium.');
  84.         return;
  85.     }
  86.  
  87.     if (!picture) {
  88.         picture = "https://www.jcdanczak.com/images/samples.png";
  89.     }
  90.  
  91.     // ask for permission to speak
  92.     if (Notification.permission !== "granted")
  93.         Notification.requestPermission();
  94.     else {
  95.         soundClick();
  96.         var notification = new Notification(title, {
  97.             // notification icon, should be replaced with the correct advisor later
  98.             icon: picture,
  99.             body: message,
  100.         });
  101.         // kill notifications 700 ms after their birth
  102.         setTimeout(function(){notification.close();}, 7000);
  103.         // if user shows affection for notify, let notify do them a last service before it dies prematurely.
  104.         notification.onclick = function () {
  105.             window.open("http://s28-en.ikariam.gameforge.com/index.php");
  106.         };
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment