xeonthread

Untitled

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