diff --git a/servicenow-chat-alert.user.js b/servicenow-chat-alert.user.js new file mode 100644 index 0000000..4a53885 --- /dev/null +++ b/servicenow-chat-alert.user.js @@ -0,0 +1,75 @@ +// ==UserScript== +// @name ServiceNow - Chat Alert +// @namespace it.epfl.ch +// @version 0.1 +// @description Watch for new incoming chat and alert the team +// @author Laurent Indermühle +// @match https://it.epfl.ch/backoffice/navpage.do* +// @match https://it-test.epfl.ch/backoffice/navpage.do* +// @grant none +// ==/UserScript== + +/** + * COMPATIBILITY + * + * V0.1 : ServiceNow Helsinki + */ + +/** + * LOG + * + * 2017.01.13 L.Indermühle: Initial version + */ + +(function() { + 'use strict'; + + function getButtons() { + // Visible : + // Hidden : + return document.querySelectorAll('[id^="accept_button_"]'); + } + + function countChatBtn(btnList) { + var chat_detected = 0; + + for(var i of btnList) { + if(!i.classList.contains('ng-hide')) { + chat_detected++; + } + } + //console.log('Chat detected', chat_detected); + return chat_detected; + } + + function newChatDetected() { + //var incomingMsgBtnList = getButton(); + + if(getButtons() === null) { + console.log('Erreur: Bouton pas détecté'); + return false; + } + + if(countChatBtn(getButtons()) > 0) { + return true; + } else { + return false; + } + + + } + + function main() { + if (newChatDetected()) { + console.log('Chat !!!'); + //setTimeout(mainLoop, 1000); + } else { + console.log('Pas de chat...'); + } + } + + setInterval(main, 10000); + + //clearInterval(); + +})();