Ikariam desktop notifications

Runs when you have ikariam open and provides push notifications when the advisors lights up.

  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.  
  75. function notifyMe(title, message, picture) {
  76. // check if functionality exists
  77. if (!Notification) {
  78. alert('Desktop notifications not available in your browser. Try Chromium.');
  79. return;
  80. }
  81.  
  82. if (!picture) {
  83. picture = "https://www.jcdanczak.com/images/samples.png";
  84. }
  85.  
  86. // ask for permission to speak
  87. if (Notification.permission !== "granted")
  88. Notification.requestPermission();
  89. else {
  90. var notification = new Notification(title, {
  91. // notification icon, should be replaced with the correct advisor later
  92. icon: picture,
  93. body: message,
  94. });
  95. // kill notifications 700 ms after their birth
  96. setTimeout(function(){notification.close();}, 7000);
  97. // if user shows affection for notify, let notify do them a last service before it dies prematurely.
  98. notification.onclick = function () {
  99. window.open("http://s28-en.ikariam.gameforge.com/index.php");
  100. };
  101. }
  102. }