-
Notifications
You must be signed in to change notification settings - Fork 0
/
OMNIStalenessWithBackLine.user.js
267 lines (242 loc) · 12.6 KB
/
OMNIStalenessWithBackLine.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// ==UserScript==
// @name OMNIStalenessWithBackLine
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Register Stalenesses and open cases w/ CTRL-SHIFT-SPACE
// @author Connor Kaiser
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @include https://osisoft--fullcopy.*
// @include https://osisoft--prodcopy.*
// @include https://osisoft.lightning.force.*
// ==/UserScript==
(function()
{
if (window.top === window.self)
{
var Skill = "fl_english_ib" //Skill to check against
var BacklineName = "" //Name to check if the case is a CR
GM_deleteValue("Staleness") //Reset Global Variable
if (BacklineName != ""){ GM_deleteValue("BackLineStaleness") } //Reset Global Variable
var TimersCount = 0;
var observer = new MutationObserver(function(mutations)
{
var Timer = document.getElementsByClassName("OmniTimer")
if (Timer != null && (Timer.length != TimersCount))
{
TimersCount = Timer.length
}
else
{
return;
}
//Case Title in case a CR comes in
try
{
if (document.getElementsByClassName("primaryField")[0].innerText)
{
var CaseTitle = document.getElementsByClassName("primaryField")[0].innerText
//PSE Name pulled from OMNI Case Info (e.g. 00787878|Web|Connor Kaiser)
var Name = document.getElementsByClassName("secondaryFields")[0].children[2].innerText
//Placeholder for Staleness Text
try{document.getElementsByClassName("OmniTimer")[0].insertAdjacentHTML("afterend", '<div id="Staleness"> </div>');} catch(er) {console.log("Failed To Add Staleness DIV")}
//Sets Normal Case Staleness
GetStaleness(Name,Skill,0)
GetStaleness(CaseTitle,Skill,1)
if (BacklineName != "")
{
//Sets BackLineStaleness
if (CaseTitle == BacklineName) //Get a CR for a Backline engineer
{
var StartText = document.getElementById("Staleness")
var Staleness = GM_getValue("BackLineStaleness") //Get the staleness of the title user not the user in the case info
var NewStaleness = 0; //CRs are 100%
StartText.innerText = "100% Reduction\nCurrent Staleness: " + msToTime(Staleness) + "\nAfter CR : " + msToTime(NewStaleness)
}
else //Get a normal case for a Backline engineer
{
setTimeout(async function(Skill)
{
//15 h 15 min 15 s
var StartText = document.getElementById("Staleness")
var TimeText = document.getElementsByClassName("OmniTimer")[0].innerText
if (TimeText.match("h") == null)
{
//15 min 15 s
var timeHours = parseInt(TimeText.substr(0,2).trim())/60 //Time in Minutes (in Hours)
var ResetAmount = 25 + (75*(timeHours)/3.5)
var Staleness = GM_getValue("Staleness")
var NewStaleness = (1-(ResetAmount*.01)) * Staleness
StartText.innerText = ResetAmount.toFixed(0).toString() + "% Reduction\nCurrent Staleness: " + msToTime(Staleness) + "\nAfter OMNI Case : " + msToTime(NewStaleness)
}
else
{
//15 h 15 min 15 s
timeHours = parseInt(TimeText.substr(0,2).trim()) //Time in Hours
//15h
//15 min 15 s
var timeMinutes = parseInt(TimeText.substr(3).trim().substr(0,2).trim())/60 //Time in Minutes(in Hours)
//15 h + .25h (we threw out 15s because it barely changes the %)
var timeTotal = timeHours + timeMinutes
ResetAmount = 25 + (75*(timeTotal)/3.5)
if (ResetAmount >= 100) {ResetAmount = 100} //Some cases go over SLA and would throw off math
Staleness = GM_getValue("Staleness")
NewStaleness = (1-(ResetAmount*.01)) * Staleness
StartText.innerText = ResetAmount.toFixed(0).toString() + "% Reduction\nCurrent Staleness: " + msToTime(Staleness) + "\nAfter OMNI Case : " + msToTime(NewStaleness)
}
}, 2000);
}
}
else //Get a normal case for a normal engineer
{
setTimeout(async function(Skill)
{
//15 h 15 min 15 s
var StartText = document.getElementById("Staleness")
try{var TimeText = document.getElementsByClassName("OmniTimer")[0].innerText} catch(er){}
if (TimeText)
{
if (TimeText.match("h") == null)
{
//15 min 15 s
var timeHours = parseInt(TimeText.substr(0,2).trim())/60 //Time in Minutes (in Hours)
var ResetAmount = 25 + (75*(timeHours)/3.5)
var Staleness = GM_getValue("Staleness")
var NewStaleness = (1-(ResetAmount*.01)) * Staleness
StartText.innerText = ResetAmount.toFixed(0).toString() + "% Reduction\nCurrent Staleness: " + msToTime(Staleness) + "\nAfter OMNI Case : " + msToTime(NewStaleness)
}
else
{
//15 h 15 min 15 s
timeHours = parseInt(TimeText.substr(0,2).trim()) //Time in Hours
//15h
//15 min 15 s
var timeMinutes = parseInt(TimeText.substr(3).trim().substr(0,2).trim())/60 //Time in Minutes(in Hours)
//15 h + .25h (we threw out 15s because it barely changes the %)
var timeTotal = timeHours + timeMinutes
ResetAmount = 25 + (75*(timeTotal)/3.5)
if (ResetAmount >= 100) {ResetAmount = 100} //Some cases go over SLA and would throw off math
Staleness = GM_getValue("Staleness")
NewStaleness = (1-(ResetAmount*.01)) * Staleness
StartText.innerText = ResetAmount.toFixed(0).toString() + "% Reduction\nCurrent Staleness: " + msToTime(Staleness) + "\nAfter OMNI Case : " + msToTime(NewStaleness)
}
}
}, 2000);
}
}
else
{
}
}catch(er){}
//Event Handler for opening OMNI Cases
});
observer.observe(document, {
childList: true,
subtree: true
});
}
else
{
return;
}
document.body.addEventListener('keydown', function(e){}, true); //Hook the event e
document.addEventListener('keydown', function(e) //If event was a keypress
{
if (e.keyCode == 32 && e.shiftKey && e.ctrlKey && !e.altKey && !e.metaKey) //Pressed Ctrl-Shift-Space simultaneously
{
try
{
var CaseID = document.getElementsByClassName("visible")[0].children[0].getAttribute("data-worktargetid")
var URL = "https://osisoft.lightning.force.com/lightning/r/Case/" + CaseID + "/view"
window.open(URL) //Open case shown in OMNI
}
catch(er){}
}
}, false);
return;
})();
async function GetStaleness(Name,Skill,BackLine) //This is roughly how TSOPS gets its staleness values
{
//Function saves space above but requires globals because xmlhttprequests are async and can't output values
await GM_xmlhttpRequest({
method: "GET",
url: "https://tsops-api-phl.dev.osisoft.int/api/agents/simple",
onload: await function(response)
{
//console.log(response)
var StartText = response.responseText.substring(1,response.responseText.length)
StartText = StartText.split('"name": ')
var People = [];
for (let i = 0; i < StartText.length; i++)
{
try
{
if (StartText[i].match(Skill).index >= 0)
{
try {var Available = StartText[i].match('Available').index} catch(er) {Available = -1}
try {var Unavailable = StartText[i].match('Unavailable').index} catch(er) {Unavailable = -1}
try {var Lunch = StartText[i].match('Lunch_1hr').index} catch(er) {Lunch = -1}
try {var CustBuff = StartText[i].match('Cust_Mtg_30min_Buffer').index} catch(er) {CustBuff = -1}
try {var IntBuff = StartText[i].match('Int_Mtg_1hr+30min_Buffer').index} catch(er) {IntBuff = -1}
try {var NOC = StartText[i].match('NOC_30min').index} catch(er) { NOC = -1}
try {var OffLine = StartText[i].match('Logged Out').index} catch(er) { OffLine = -1}
if (Available >= 0 || Unavailable >= 0 || Lunch >= 0 || CustBuff >= 0 || IntBuff >= 0 || NOC >= 0 || OffLine >= 0)
{
People.push(StartText[i])
}
}
}
catch(er){}
}
var MyTimes = []
var Stalenesses = []
for (let i = 0; i < People.length; i++)
{
try{
if (People[i].match(Name).index >= 0) //If this person is the "Name"
{
var Regex = /(?<=Time": ").*(?=",)/gm
var Match = People[i].match(Regex)
for (let j = 0; j < Match.length; j++)
{
MyTimes.push(Date.parse(Match[j]))
}
}
}
catch(er) // .index above will fail if Name isn't there so these are the other users
{
Regex = /(?<=Time": ").*(?=",)/gm
Match = People[i].match(Regex)
Stalenesses.push((Date.now() - Date.parse(Match[0]))) //Time between last call/case and now = staleness (stored in Array of users)
}
}
if (BackLine == 1)
{
var Staleness = Date.now() - MyTimes[0]
Stalenesses = Stalenesses.sort().reverse()
GM_setValue("BackLineStaleness", Staleness) //Set Global
return 0;
}
else
{
Staleness = Date.now() - MyTimes[0]
Stalenesses = Stalenesses.sort().reverse()
GM_setValue("Staleness", Staleness) //Set Global
return 1;
}
}
});
return 1;
}
function msToTime(duration) {
var milliseconds = parseInt((duration % 1000) / 100),
seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return hours + ":" + minutes + ":" + seconds;
}