// ==UserScript==
// @name Long call alert
// @namespace Helpdesk
// @description Pop up letting you know when you are on a long contact.
// @include *
// @version 1
// @require
http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js// @grant GM_xmlhttpRequest
// @grant GM_log
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
//DATE: 8/21/2015
//Author: Alex
alert(GM_listValues());
//get agent name and CSC unique ID and store it in greasemonkey sqlite db
var agentName=GM_getValue("agent", "" );
var cscUsrID=GM_getValue("cscUsrID", "" );
if(agentName==""){
agentName= prompt("Your agent cookie file is missing. Please enter your name:", "");
GM_setValue("agent", agentName);
}
if(cscUsrID=="") {
//here is the hard coded CSC user data. This is needed in order to flip data
var agentValues=["avthomse","AFJKP1EKEOSK0","calvoi","A3A7WUF9KAHVUU","daniwren","ATCUQY96BLG7C","grci","A3UMVGW2Z3VT29","hartchri","A25FLINFFXMI69","jamendez","A3LHN1Q7DY0BN8","jcronk","A1KB6OXUWST0ZP","joepablo","AUBAU8AP08LFQ","joseaco","AU1BV5Y586KUP","lordsman","A2V5Z7A9A6MWGV","mfitzhug","A3H8RL3FPH9YHU","padjuan","A12PEEQ2NIIEPQ","prochett","AIUU2TUCJXXLL","ramijosu","AFWY2CS2NKRCH","rolandoj","AT8YSATRE9SE7","smull","A2OYQDP0TC5ON8","tarmijo","A3S664N12AWX0Q","tayon","A3EZ0NCRWQ8104","vaughnf","A1N9BQPZBQ294F"];
var index=agentValues.indexOf(agentName);
var cscVal = agentValues[index+1];
GM_setValue("cscUsrID", cscVal );
}
//see if there are contacts in queue
GM_setValue("callsInQueueLongCallAlert", "false");
//create cookies to store if notifications have been sent
var fifteenNotice = GM_getValue("15Notice", "" );
var twentyNotice = GM_getValue("20Notice", "" );
var thirtyNotice = GM_getValue("30Notice", "" );
var fourtyNotice = GM_getValue("40Notice", "" );
if(fifteenNotice==""){GM_setValue("15Notice","false");};
if(twentyNotice==""){GM_setValue("20Notice","false");};
if(thirtyNotice==""){GM_setValue("30Notice","false");};
if(fourtyNotice==""){GM_setValue("40Notice","false");};
//THIS CHUNK IS ALL FOR THE CHECKING IF CALL QUEUE
GM_xmlhttpRequest({
method: "GET",
url: "
http://phonestats/site/get-site-statistics?site=PSC-Helpdesk&skills=AmazonUSHelpdesk",
headers: {
"User-Agent": "Mozilla/5.0", // If not specified, navigator.userAgent will be used.
"Accept": "text/xml" // If not specified, browser defaults will be used.
},
onload: function(response) {
var responseXML = null;
// Inject responseXML into existing Object (only appropriate for XML content).
if (!response.responseXML) {
responseXML = new DOMParser()
.parseFromString(response.responseText, "text/xml");
}
GM_log([
response.status,
response.statusText,
response.readyState,
response.responseHeaders,
response.responseText,
response.finalUrl,
responseXML
].join("\n"));
callResponse=response.responseText.split(",");
if(callResponse[7]>0)
{
GM_setValue("callsInQueueLongCallAlert", "true");
}
}
});
//put the check on timeout to get a chance for page to load
setTimeout(function(){
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//ACTION ITEM HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
GM_setValue("callsInQueueLongCallAlert", "true");
//THIS CHUNK IS Checking agent state and there are
//CALLS in queue but you are avail
if(GM_getValue("callsInQueueLongCallAlert").indexOf("true")> -1)
{
GM_xmlhttpRequest({
method: "GET",
url: "
http://phonestats/agent/get-agent-statistics?site=PSC-Helpdesk&report=active-agents&attribute=state&attribute=state-duration&attribute=durations-of-active-phones",
headers: {
"User-Agent": "Mozilla/5.0", // If not specified, navigator.userAgent will be used.
"Accept": "text/xml" // If not specified, browser defaults will be used.
},
onload: function(response) {
var responseXML = null;
// Inject responseXML into existing Object (only appropriate for XML content).
if (!response.responseXML) {
responseXML = new DOMParser()
.parseFromString(response.responseText, "text/xml");
}
GM_log([
response.status,
response.statusText,
response.readyState,
response.responseHeaders,
response.responseText,
response.finalUrl,
responseXML
].join("\n"));
GM_setValue("15Notice","false");
GM_setValue("20Notice","false");
GM_setValue("30Notice","false");
GM_setValue("40Notice","false");
//evaluate if items should be displayed
//then flip the greasemonkey stored key to not keep displaying
var agentSiteReports;
agentSiteReports=response.responseText.split("\n");
for each (var line in agentSiteReports)
{
if((line.split(",")[0].indexOf(agentName) > -1)&&((line.split(",")[1]).indexOf("Meeting") > -1)&&(line.split(",")[2]>900)&&(line.split(",")[3]==0)&&(fifteenNotice=="false"))
{
buttonDisplay("
http://dashboard.aka.amazon.com/graphics/yellowLight.jpg","yellow");
GM_setValue("15Notice","true");
}
if((line.split(",")[0].indexOf(agentName) > -1)&&((line.split(",")[1]).indexOf("Meeting") > -1)&&(line.split(",")[2]>1200)&&(line.split(",")[3]==0)&&(twentyNotice=="false"))
{
buttonDisplay("
http://dashboard.aka.amazon.com/graphics/redLight.jpg","red");
GM_setValue("20Notice","true");
}
if((line.split(",")[0].indexOf(agentName) > -1)&&((line.split(",")[1]).indexOf("Meeting") > -1)&&(line.split(",")[2]>1800)&&(line.split(",")[3]==0)&&(thirtyNotice=="false"))
{
buttonDisplay("
http://dashboard.aka.amazon.com/graphics/30min.jpg","30min");
GM_setValue("30Notice","true");
}
if((line.split(",")[0].indexOf(agentName) > -1)&&((line.split(",")[1]).indexOf("Meeting") > -1)&&(line.split(",")[2]>2400)&&(line.split(",")[3]==0)&&(fourtyNotice=="false"))
{
buttonDisplay("
http://dashboard.aka.amazon.com/graphics/40Min.jpg","40min");
GM_setValue("40Notice","true");
}
}
}
});
}//end of the if statement
}, 2000);
//function that will create and display the input button object, it will make it click to hide
function buttonDisplay(displayImage,idName) {
var imageButton = document.createElement("input");
imageButton.id=idName;
var hashedName="#"+idName;
imageButton.type="image";
imageButton.src = displayImage;
imageButton.addEventListener('click',function(){$(hashedName).hide();},false);
$('body').prepend(imageButton);
}