// ==UserScript== // @name Ikariam desktop notifications // @namespace Danielv123 // @version 1.2 // @description Runs when you have ikariam open and provides push notifications when the advisors lights up. // @author Danielv123 // @match *.ikariam.gameforge.com/* // @grant none // @downloadURL none // ==/UserScript== // request permission on page load document.addEventListener('DOMContentLoaded', function () { if (Notification.permission !== "granted") { Notification.requestPermission(); } }); // main checking loop setInterval(function() { if (Notification.permission !== "granted") Notification.requestPermission(); else { // check if the advisors are glowing if ($('#js_GlobalMenu_cities')[0].className == "normalactive") { console.log('Ding!'); notifyMe("Ikariam", "Something happened in one of your towns!"); } if ($('#js_GlobalMenu_diplomacy')[0].className == "normalactive") { console.log('Ding!'); notifyMe("Ikariam", "Someone sent you a message!"); } // by checking if military is !normal we can also include the red status if ($('#js_GlobalMenu_military')[0].className != "normal") { console.log('Ding!'); notifyMe("Ikariam", "Your military advisor is trying to tell you something!"); } if ($('#js_GlobalMenu_research')[0].className == "normalactive") { console.log('Ding!'); notifyMe("Ikariam", "New research aviable!"); } } // wait 60.000 ms (1 min) between checking for notifications },60000); function notifyMe(title, message) { // check if functionality exists if (!Notification) { alert('Desktop notifications not available in your browser. Try Chromium.'); return; } // ask for permission to speak if (Notification.permission !== "granted") Notification.requestPermission(); else { var notification = new Notification(title, { // notification icon, should be replaced with the correct advisor later icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png', body: message, }); // kill notifications 700 ms after their birth setTimeout(function(){notification.close();}, 7000); // if user shows affection for notify, let notify do them a last service before it dies prematurely. notification.onclick = function () { window.open("http://s28-en.ikariam.gameforge.com/index.php"); }; } }