forked from nunyvega/Chat-operators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat-operators.user.js
290 lines (250 loc) · 11.7 KB
/
chat-operators.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// ==UserScript==
// @name Happychat Operators
// @namespace https://github.com/senff/Chat-operators
// @version 1.5
// @description List of operators
// @author Senff
// @require https://code.jquery.com/jquery-1.12.4.js
// @match https://hud.happychat.io/*
// @updateURL https://github.com/senff/Chat-operators/raw/master/chat-operators.user.js
// @grant none
// ==/UserScript==
var $ = window.jQuery;
function nameAdd() {
var opsAll = 0;
var opsGreen = 0;
var opsYellow = 0;
var opsBlue = 0;
var opsRed = 0;
var throttleOne = 0;
var throttleTwo = 0;
var throttleThree = 0;
var throttleFour = 0;
var throttleMore = 0;
var greenLoad = 0;
var greenThrottle = 0;
var greenOpen = 0;
var blueLoad = 0;
var blueThrottle = 0;
var blueOpen = 0;
var HEsGreen = 'GREEN: ';
var HEsBlue = 'BLUE: ';
var HEsYellow = 'YELLOW: ';
var HEsRed = 'RED: ';
var allHEs = '';
var opLang = '';
var opSkillAtomic = '';
var opSkillConcierge = '';
if(($('.chat__chat-queue .capacity__operators').length) && (!$('.chat__chat-queue .operators_stats').length)) {
$('.chat__chat-queue .capacity__operators').after('<div class="operators_stats stats_open"><h4>Operator stats <div class="stats_toggle"></div></h4><div class="operators_all_stats" style="display: block;"><div class="stats-block"><strong>Total HEs</strong>: <span class="all-ops">0</span> ( <strong class="green ops-green">0</strong> <strong class="yellow ops-yellow">0</strong> <strong class="blue ops-blue">0</strong> <strong class="red ops-red">0</strong> )</div><div class="stats-block"><strong>GREEN HEs:</strong><br><span class="throttle-one throttle-count">0</span> have a throttle of 1<br><span class="throttle-two throttle-count">0</span> have a throttle of 2 <span class="alert-throttle" title="More HEs with throttle 2 than throttle 3">!</span><br><span class="throttle-three throttle-count">0</span> have a throttle of 3<br><span class="throttle-four throttle-count">0</span> have a throttle of 4<br><span class="throttle-more throttle-count">0</span> have a throttle of more than 4<br></div><div class="stats-block"><strong>All green HEs load</strong>: <span class="green-ops-load">0</span><br><strong>All green HEs throttle</strong>: <span class="green-ops-throttle">0</span><br><strong>Green HEs open</strong>: <span class="green-ops-open">0</span> <strong class="moar-chat red"></strong></div></div></div>');
}
$('.chat__chat-queue .operators').each(function( index ) {
var opSkills = '';
var opInfo = $(this).find('img').attr('title');
// var opName = opInfo.substring(0, opInfo.indexOf(' ') + 1);
if(opInfo.includes('pt-br')) {
opSkills = " pt-br ";
}
if(opInfo.includes(': es') || opInfo.includes(', es') || opInfo.includes('es,')){
opSkills = opSkills + " es ";
}
if(opInfo.includes('atomic') && !opInfo.includes('fresatomica')) { // Because Oliwia has "atomic" in her username :D
opSkills = opSkills + " atomic ";
}
if(opInfo.includes('WPconcierge')) {
opSkills = opSkills + " concierge ";
}
var opName = opInfo.substring(opInfo.lastIndexOf("(")+1,opInfo.lastIndexOf(")"));
var opLoadPos = opInfo.indexOf('Load: ');
var opLoad = opInfo.substr(opLoadPos+6, 1);
var opThrottlePos = opInfo.indexOf('Throttle: ');
var opThrottle = opInfo.substr(opThrottlePos+10, 1);
var opCapacity = opLoad/opThrottle * 100;
var opCapLevel = parseInt(opLoad/opThrottle * 10);
if (opCapLevel > 10) {
opCapLevel = 'Over';
}
$(this).removeClass('capLevel0').removeClass('capLevel1').removeClass('capLevel2').removeClass('capLevel3').removeClass('capLevel4').removeClass('capLevel5').removeClass('capLevel6').removeClass('capLevel7').removeClass('capLevel8').removeClass('capLevel9').removeClass('capLevel10').removeClass('capLevelOver');
$(this).addClass('capLevel'+opCapLevel);
if (!$(this).hasClass('hasName')) {
$(this).addClass('hasName');
$(this).find('.operator_name').remove();
$(this).find('img').after('<div class="operator_info" title="'+opLang+'"><div class="operator_name '+opSkills+'"><span></span></div><div class="operator_load"></div><div class="operator_capacity"><div class="operator_ind"></div></div></div>');
}
$(this).find('.operator_capacity').css('width',((opThrottle*14)+2)+'px');
$(this).find('.operator_name span').html(opName);
$(this).find('.operator_load').html(opLoad+'/'+opThrottle);
if (opLoad > opThrottle) {
$(this).find('.operator_load').addClass('red').addClass('highlight');
} else {
$(this).find('.operator_load').removeClass('red').removeClass('highlight');
}
if (opCapacity == 100) {
$(this).find('.operator_capacity').addClass('fullHE');
} else if (opCapacity > 100) {
$(this).find('.operator_capacity').addClass('overloadHE');
} else {
$(this).find('.operator_capacity').removeClass('fullHE').removeClass('overloadHE');
}
$(this).find('.operator_ind').css('width',opCapacity+'%');
if ($(this).hasClass('operators__available')) {
opsGreen++;
if (opThrottle == 1) {throttleOne++;}
if (opThrottle == 2) {throttleTwo++;}
if (opThrottle == 3) {throttleThree++;}
if (opThrottle == 4) {throttleFour++;}
if (opThrottle > 4) {throttleMore++;}
greenLoad = parseInt(greenLoad) + parseInt(opLoad);
greenThrottle = parseInt(greenThrottle) + parseInt(opThrottle);
if (opLoad < opThrottle) {
var thisOpen = parseInt(opThrottle) - parseInt(opLoad);
greenOpen = parseInt(greenOpen) + parseInt(thisOpen);
}
HEsGreen = HEsGreen + opName + " (" + opLoad + "/" + opThrottle + "), ";
}
if ($(this).hasClass('operators__busy')) {
opsYellow++;
HEsYellow = HEsYellow + opName + " (" + opLoad + "/" + opThrottle + "), ";
}
if ($(this).hasClass('operators__reserve')) {
opsBlue++;
blueLoad = parseInt(blueLoad) + parseInt(opLoad);
blueThrottle = parseInt(blueThrottle) + parseInt(opThrottle);
if (opLoad < opThrottle) {
thisOpen = parseInt(opThrottle) - parseInt(opLoad);
blueOpen = parseInt(blueOpen) + parseInt(thisOpen);
}
HEsBlue = HEsBlue + opName + " (" + opLoad + "/" + opThrottle + "), ";
}
if ($(this).hasClass('operators__unavailable')) {
opsRed++;
HEsRed = HEsRed + opName + " (" + opLoad + "/" + opThrottle + "), ";
}
opsAll++;
});
$('.all-ops').html(opsAll);
$('.ops-green').html(opsGreen);
$('.ops-yellow').html(opsYellow);
$('.ops-blue').html(opsBlue);
$('.ops-red').html(opsRed);
$('.throttle-one').html(throttleOne);
$('.throttle-two').html(throttleTwo);
$('.throttle-three').html(throttleThree);
$('.throttle-four').html(throttleFour);
$('.throttle-more').html(throttleMore);
$('.green-ops-load').html(greenLoad);
$('.green-ops-throttle').html(greenThrottle);
$('.green-ops-open').html(greenOpen);
if ((greenLoad >= greenThrottle) && (blueLoad >= blueThrottle)) {
$('.moar-chat').html('<br>*** MORECHAT ***');
} else if (greenOpen < 1) {
$('.moar-chat').html('<br>* ALL GREEN HEs ARE FULL *');
} else if (greenOpen < 3) {
$('.moar-chat').html('<br>Green HEs are almost full');
} else {
$('.moar-chat').html('');
}
if (throttleTwo > (throttleThree + throttleFour + throttleMore)) {
$('.alert-throttle').addClass('alert-on');
} else {
$('.alert-throttle').removeClass('alert-on');
}
if ($('#copyOperatorData').length < 1) {
$('.chat__chat-queue .capacity__operators').after('<a href="#" class="button" id="hideRedHEs">Hide red HE\'s</a> <a href="#" class="button" id="showRedHEs" style="display: none;">Show red HEs</a> <a href="#" class="button" id="copyOperatorData">Copy Operator Info</a><div id="operatorData"></div>');
}
HEsGreen = HEsGreen.slice(0, -2);
HEsBlue = HEsBlue.slice(0, -2);
HEsYellow = HEsYellow.slice(0, -2);
HEsRed = HEsRed.slice(0, -2);
allHEs = HEsGreen + '\n' + HEsBlue + '\n' + HEsYellow + '\n' + HEsRed + '\n\n';
allHEs = allHEs + "TOTAL GREEN: " + greenLoad + "/" + greenThrottle + "\n";
allHEs = allHEs + "TOTAL BLUE: " + blueLoad + "/" + blueThrottle + "\n";
$('#operatorData').html(allHEs);
}
window.setInterval(function(){
nameAdd();
}, 5000);
$(document).on('click', '.operators_stats h4', function() {
$(this).parent().toggleClass('stats_open');
$(this).parent().find('.operators_all_stats').slideToggle(200);
});
$("body").on('click','#copyOperatorData', function () {
copyDataToClipboard(document.getElementById("operatorData"));
});
$("body").on('click','#hideRedHEs', function () {
$('body').append('<style type="text/css" class="hideredhes">.chat__chat-queue .operators.operators__unavailable {display: none;}</style>');
$(this).hide();
$('#showRedHEs').show();
});
$("body").on('click','#showRedHEs', function () {
$('.hideredhes').remove();
$(this).hide();
$('#hideRedHEs').show();
});
$("body").on('click','#showRedHEs', function () {
$('.hideredhes').remove();
$(this).hide();
$('#hideRedHEs').show();
});
$("body").on('keyup click change','.chat-actions__current-chat-action-compose textarea', function(){
highlightNote();
});
window.setInterval(function(){
highlightNote();
}, 2500);
function highlightNote(){
var boxContents = $('.chat-actions__current-chat-action-compose textarea').val();
var entryField = boxContents.toLowerCase();
if (entryField.startsWith('/note ')) {
$('.chat-actions__current-chat-action-compose textarea').addClass('note');
} else {
$('.chat-actions__current-chat-action-compose textarea').removeClass('note');
}
}
function copyDataToClipboard(elem) {
// create hidden text element, if it doesn't already exist
var targetId = "_hiddenCopyText_";
var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA";
var origSelectionStart, origSelectionEnd;
if (isInput) {
// can just use the original source element for the selection and copy
target = elem;
origSelectionStart = elem.selectionStart;
origSelectionEnd = elem.selectionEnd;
} else {
// must use a temporary form element for the selection and copy
target = document.getElementById(targetId);
if (!target) {
var target = document.createElement("textarea");
target.style.position = "absolute";
target.style.left = "-9999px";
target.style.top = "0";
target.id = targetId;
document.body.appendChild(target);
}
target.textContent = elem.textContent;
}
// select the content
var currentFocus = document.activeElement;
target.focus();
target.setSelectionRange(0, target.value.length);
// copy the selection
var succeed;
try {
succeed = document.execCommand("copy");
} catch(e) {
succeed = false;
}
// restore original focus
if (currentFocus && typeof currentFocus.focus === "function") {
currentFocus.focus();
}
if (isInput) {
// restore prior selection
elem.setSelectionRange(origSelectionStart, origSelectionEnd);
} else {
// clear temporary content
target.textContent = "";
}
return succeed;
}