-
Notifications
You must be signed in to change notification settings - Fork 0
/
scw33t_global.js
1492 lines (1303 loc) · 59.5 KB
/
scw33t_global.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
///////////////////////////////////// scw33t_global.js //////////////////////////////////////
//
// VeRsIoN: 0.1
// Last updated: 03/27/2017
// Full Path: scw33t_global.js
//
// Description: Holds globally required functions.
//
// Notes:
//
///////////////////////////////////////////////////////////////////////////////////////////////////////
// TODO limit the scope of Globally applied scripts (for speed & mem)
// TODO console style for search bar & tab colorings
console.log("SCw33t_Global loaded... HREF: "+ window.location.href);
var debugLevel = 4;
// 0 = ERROR
// 1 = ERROR + WARNING
// 2 = ERROR + WARNING + INFO
// 3 = ERROR + WARNING + INFO + DEBUG
// 4 = ERROR + WARNING + INFO + DEBUG + TRACE
var logTitle = "SCw33tLog";
logTrace('scw33t_global.js initializing.');
//var removePullDownBar = true;
//var boostTextSize = "75%"; // SC Default = 75%
//var peekItHeight = 300;
// BEGIN: Browser ID
var isFirefox = false; // typeof InstallTrigger !== 'undefined';
var isChrome = true; // !!window.chrome && !!window.chrome.webstore;
//alert("FF: " + isFirefox + ". Chrome: " + isChrome);
// END: Browser ID
var boostTextSize;
var removePullDownBar;
var caseNum = null;
var fiveHunId = null;
var needToDismiss = null;
// CSS Theme
var themeParts = [
"console_top_color",
"console_bottom_color",
"console_text_color",
"tabstrip_bg_color",
"tabstrip_alt_bg_color",
"tabstrip_text_color",
"tabstrip_border_color",
"tabstrip_tab_border_color",
"tabstrip_tab_alt_border_color",
'body_bg_color',
'body_text_color',
'body_text_modified_color',
'body_link_hover_color',
'body_link_color',
'body_label_text_color',
'alert_bg_color',
'alert_text_color',
'alert_border_color',
'warning_bg_color',
'warning_text_color',
'warning_border_color',
'success_bg_color',
'success_text_color',
'success_border_color',
'percent_bar_color',
'percent_bar_bg_color',
'tb_bg_color',
'tb_text_color',
'tb_link_color',
'tb_border_color',
'box_h_text_color',
'box_h_bg_color',
'box_h_border_color',
'box_body_bg_color',
'box_body_border_color',
'table_header_bg_color',
'table_header_text_color',
'table_header_border_color',
'cell_label_border_color',
'cell_data_border_color',
'row_color_even',
'row_color_odd',
'row_color_highlight',
'btn_text_color',
'btn_bg_color',
'btn_border_color',
'btn_alt_text_color',
'btn_alt_bg_color',
'btn_alt_border_color',
'txtfield_text_color',
'txtfield_bg_color',
'txtfield_border_color',
'txtfield_alt_border_color'];
var console_top_color;
var console_bottom_color;
var console_text_color;
var tabstrip_bg_color;
var tabstrip_alt_bg_color;
var tabstrip_text_color;
var tabstrip_border_color;
var tabstrip_tab_border_color;
var tabstrip_tab_alt_border_color;
var body_bg_color;
var body_text_color;
var body_text_modified_color;
var body_link_hover_color;
var body_link_color;
var body_label_text_color;
var alert_bg_color;
var alert_text_color;
var alert_border_color;
var warning_bg_color;
var warning_text_color;
var warning_border_color;
var success_bg_color;
var success_text_color;
var success_border_color;
var percent_bar_color;
var percent_bar_bg_color;
var tb_bg_color;
var tb_text_color;
var tb_link_color;
var tb_border_color;
var box_h_text_color;
var box_h_bg_color;
var box_h_border_color;
var box_body_bg_color;
var box_body_border_color;
var table_header_bg_color;
var table_header_text_color;
var table_header_border_color;
var cell_label_border_color;
var cell_data_border_color;
var row_color_even;
var row_color_odd;
var row_color_highlight;
var btn_text_color;
var btn_bg_color;
var btn_border_color;
var btn_alt_text_color;
var btn_alt_bg_color;
var btn_alt_border_color;
var txtfield_text_color;
var txtfield_bg_color;
var txtfield_border_color;
var txtfield_alt_border_color;
var requestVars = ['boostTextSize','removePullDownBar'].concat(themeParts);
// var requestVars ='themeParts';
// Sets Global Theme
getVars(JSON.stringify(requestVars), setTheme);
function setTheme() { setStyle(themeParts); }
////////////////////////////////////////////////
// BOOST text size
////////////////////////////////////////////////
$('body').css('font-size', boostTextSize);
////////////////////////////////////////////////
// SCw33t Logger v1.0
////////////////////////////////////////////////
// TODO add confirmbox..... why?!
// TODO colorize more:
// console.log('%c Oh my heavens! ', 'background: #222; color: #bada55');
function logError(message, type) {
logSCweet('ERROR', message, type, 'background: pink; color: black');
}
function logWarning(message, type) {
if (debugLevel >= 1) {
logSCweet('WARNING', message, type);
}
}
function logInfo(message, type) {
if (debugLevel >= 2) {
logSCweet('INFO', message, type);
}
}
function logDebug(message, type) {
if (debugLevel >= 3){
logSCweet('DEBUG', message, type);
}
}
function logTrace(message, type) {
if (debugLevel >= 4) {
logSCweet('TRACE', message, type);
}
}
function logSCweet(level, message, type, color) {
if (type === undefined) {
type = 0;
}
message = '%c' + logTitle + "." + level + " " + makeTimestamp() + "-> " + message;
switch(type) {
// Only Console Log
case 0:
console.log(message, color);
break;
// Only Alert
case 1:
alert(message);
break;
// Alert & Console Log
case 2:
console.log(message, color);
alert(message);
break;
}
}
function makeTimestamp() {
var date = new Date();
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours();
var min = date.getMinutes();
var sec = date.getSeconds();
month = (month < 10 ? "0" : "") + month;
day = (day < 10 ? "0" : "") + day;
hour = (hour < 10 ? "0" : "") + hour;
min = (min < 10 ? "0" : "") + min;
sec = (sec < 10 ? "0" : "") + sec;
var stamp = date.getFullYear() + "-" + month + "-" + day + "_" + hour + ":" + min + ":" + sec;
return stamp;
}
var alertLevels = [
"! ERROR !",
"<span class=\'alertText\'>Alert</span>",
"<span class=\'warningText\'>Warning</span>",
"Info"
];
function addAlert(level, details) {
if (level == 0) {
logError(details);
}
if ($("#arrangeSC-alertBox-No-Alerts").css('display') != 'none' ) {
$("#arrangeSC-alertBox-No-Alerts").css('display','none');
}
var numAlerts = parseInt($("#numAlerts").text()) +1;
$("#numAlerts").text(numAlerts);
$("<tr><td align='right' class='labelCol' style='word-wrap: break-word;'>"
+ "<span class='labelSpan'>" + alertLevels[level] + "<span></td>"
+ "<td class='data2Col' style='width:100% !important; word-wrap: break-word;' colspan='3'>" + details + "</td></tr>")
.appendTo("#arrangeSC-alertBox-table-" + level);
}
////////////////////////////////////////////////
// Message Handling
////////////////////////////////////////////////
chrome.extension.onMessage.addListener(
function(msg, sender, sendResponse) {
if (msg.action == 'insert_scnippet') {
logDebug("Posting SCnippet to '" + document.activeElement.id + "', payload: "+ msg.value);
insertAtCaret(document.activeElement.id , msg.value);
} //else if (msg.action == '') {}
}
);
function getVars(requestedVars, func) {
logTrace('Retreiving vars from background_vars.js.')
chrome.runtime.sendMessage({action: "get_vars",varList: requestedVars}, function(response) {
if (requestedVars != 'all') {
// console.log(JSON.parse(response));
try {
response = JSON.parse(response);
} catch (e) {}
}
for (var vari in response) {
logTrace("getVars: Setting " + vari + " to: " + response[vari]);
try {
window[vari] = JSON.parse(response[vari]);
} catch (e) {
window[vari] = response[vari];
}
logDebug(vari + " = " + window[vari]);
}
func();
//return true;
// init();
// eval(post);
});
}
function setVars(varsToSet) {
logTrace('Setting var(s) via background_vars.js.')
chrome.runtime.sendMessage({action: "set_vars",varList: JSON.stringify(varsToSet)}, function(response) {
// if (requestedVars != 'all') {
// try {
//response = JSON.parse(response);
console.log(response.response);
if (response.response == 'true') {
alert("Settings saved!");
} else {
alert("Settings may not have saved... please reload to check.");
}
// } catch (e) { console.log("Problem receiving response from background " + e); }
// }
/*for (var vari in response) {
logTrace("getVars: Setting " + vari + " to: " + response[vari]);
try {
window[vari] = JSON.parse(response[vari]);
} catch (e) {
window[vari] = response[vari];
}
logDebug(vari + " = " + window[vari]);
}
func();*/
});
}
function clearSettings() {
alert('about to clear your settings...');
chrome.storage.sync.clear();
alert('they gon!');
}
function setStyle(args) {
for (var arg in args){
logTrace("Setting css var: --" + args[arg] + " to : " + window[args[arg]]);
document.documentElement.style.setProperty('--' + args[arg], window[args[arg]]);
}
// for (var arg in args){
// logTrace("Setting css var: " + arg + " to : " + args[arg]);
// document.documentElement.style.setProperty('--' + arg, args[arg]);
// }
}
////////////////////////////////////////////////
// Shared Functions
////////////////////////////////////////////////
var windowLocation = window.location.href;
function getUrlSub(url,sub) {
if (url.indexOf(sub) > -1) {
console.log("url = " + url);
console.log("sub = " + sub);
console.log("beg = " + url.split(new RegExp("[\&\?]"+sub+"="))[1]);
console.log("finRes = " + url.split(new RegExp("[\&\?]"+sub+"="))[1].split(/\&?.*$/)[0]);
return url.split(new RegExp("[\&\?]"+sub+"="))[1].split('&')[0];
} else { return false; }
}
function b64EncodeUnicode(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
return String.fromCharCode('0x' + p1);
}));
}
function b64DecodeUnicode(str) {
return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
function encode_utf8(s) {
return unescape(encodeURIComponent(s));
}
function decode_utf8(s) {
return decodeURIComponent(escape(s));
}
// LZW-compress a string
// Email2Comment: Used to compress email body so >2000 chars body can be sent through url
function lzw_encode(s) {
s = b64EncodeUnicode(s);
var dict = {};
var data = (s + "").split("");
var out = [];
var currChar;
var phrase = data[0];
var code = 256;
for (var i=1; i<data.length; i++) {
currChar=data[i];
if (dict['_' + phrase + currChar] != null) {
phrase += currChar;
}
else {
out.push(phrase.length > 1 ? dict['_'+phrase] : phrase.charCodeAt(0));
dict['_' + phrase + currChar] = code;
code++;
phrase=currChar;
}
}
out.push(phrase.length > 1 ? dict['_'+phrase] : phrase.charCodeAt(0));
for (var i=0; i<out.length; i++) {
out[i] = String.fromCharCode(out[i]);
}
return out.join("");
}
// Decompress an LZW-encoded string
function lzw_decode(s) {
var dict = {};
var data = (s + "").split("");
var currChar = data[0];
var oldPhrase = currChar;
var out = [currChar];
var code = 256;
var phrase;
for (var i=1; i<data.length; i++) {
var currCode = data[i].charCodeAt(0);
if (currCode < 256) {
phrase = data[i];
}
else {
phrase = dict['_'+currCode] ? dict['_'+currCode] : (oldPhrase + currChar);
}
out.push(phrase);
currChar = phrase.charAt(0);
dict['_'+code] = oldPhrase + currChar;
code++;
oldPhrase = phrase;
}
//return decode_utf8(out.join(""));
return b64DecodeUnicode(out.join(""));
}
function addTemplateByClass(templateHTML, className, elNumber) {
//try {
if (elNumber === undefined) { elNumber = 0; }
//var templateHTML = "<span>SC SETTINGS</span>";
var template = document.createElement('template');
template.innerHTML = templateHTML;
return document.getElementsByClassName(className)[elNumber].appendChild(template.content);//.firstChild
//} catch(e) {return false;}
}
// POP-UP creation
function popIt(frameName, loc, friendlyName, dontKill, refresh) {
try {
// Center Pop-up
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
var left = ((width / 2) - (popUpWidth / 2)) + dualScreenLeft;
var top = ((height / 2) - (popUpHeight / 2)) + dualScreenTop;
// End: Center Pop-up
if (refresh != false) {
refresh = true;
}
var title;
if (caseNum !== null) {
title = caseNum + ": " + friendlyName;
} else {
title = friendlyName;
}
var popScript1 = '<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>'; // Script to include JQuery libraries
// Script to handle the automatic closing of window when action finishes (instead of leaving pop-up open and letting it re-direct to case page)
var popScript2 = '<script type="text/javascript"> \n';
popScript2 += ' $( document ).ready(function() { \n';
popScript2 += ' document.getElementById("' + frameName + '").onload = function() { \n';
popScript2 += ' if ($("#' + frameName + '").attr("frameborder") == "0" && ("' + dontKill + '" === undefined || ("' + dontKill + '" !== undefined && $("#' + frameName + '").contents().find("title").text().indexOf("' + dontKill + '") == -1))) \n';
if (refresh) {
popScript2 += ' { try { window.opener.location.reload(); } catch(e) {} parent.window.close(); } \n';
} else {
popScript2 += ' { parent.window.close(); } \n';
}
popScript2 += ' $("#' + frameName + '").attr({"frameborder": "0"}); \n';
popScript2 += ' }});';
popScript2 += '</script>';
var popFrame = '<iframe id="' + frameName + '" scrolling="auto" frameborder="1" src="' + loc;
if (needToDismiss) { popFrame += "&dismiss=1"; }
//else alert(needToDismiss + " - not needed");
popFrame += '" style="width: 100%; height: 100%; padding: 0; border: 0px none; position: absolute; top:0; left:0;"> </iframe>';
// Chrome and FF handle the pop-up creation differently
if (isChrome) {
//var newWindow = window.open($(popFrame).attr('src'), '', 'height=' + popUpHeight + ',width=' + popUpWidth + 'resizable=yes, location=no'); // Create pop-up window
var newWindow = window.open($(popFrame).attr('src'), '', 'height=' + popUpHeight + ',width=' + popUpWidth + 'resizable=yes, location=no'+ ', top=' + top + ', left=' + left); // Create pop-up window
newWindow.document.write($(popFrame)[0].outerHTML + popScript1 + popScript2); // Add scripts and iFrame to page
newWindow.document.title = title; // Change pop-up window name to caseNumber: User Readable Page Name
newWindow.document.close(); // Stop editing pop-up window document
if (window.focus) { newWindow.focus(); } // Change focus to pop-up
} else if (isFirefox) {
// Create html doc to be loaded into pop-up, including iframe and supporing scripts
var htmlDoc = 'data:text/html,<html><head><title>' + title + '</title>' + popScript1 + popScript2.replace(/#/g,"%23") + '</head><body style="margin: 0;">' + popFrame + '</body></html>'; // Create html doc to load into pop-up
var newWindow = window.open(htmlDoc, '', 'height=' + popUpHeight + ',width=' + popUpWidth + 'resizable=yes, location=no'); // Create pop-up window
if (window.focus) { newWindow.focus(); } // Change focus to pop-up
}
} catch(e) {
if ($('#alertHider').length > 0) {
addAlert(0, "ArrangeSC: There was a problem with POP! '" + friendlyName + "'.<br />Additional info: " + e);
} else {
logError("There was a problem with POP! '" + friendlyName + "'. Additional info: " + e);
}
}
}
function formatBytes(bytes,decimals)
{
try
{
bytes= bytes.replace(/,/g, '');
if(bytes === 0) return '0 Byte';
var k = 1000;
var dm = decimals + 1 || 3;
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
var i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
catch(e)
{
if ($('#alertHider').length > 0) {
addAlert(0, "ArrangeSC: There was a problem with formatBytes.<br />Additional info: " + e);
} else {
logError("There was a problem with formatBytes. Additional info: " + e);
}
}
}
function makeFloatingBox(args) {
/* args:
* id**
* title: goes in title bar
* height: height of box
* width: width of box
* overlay: t/f
* > overlayColor: rgb color, 0,0,0 = black | 255,255,255 = white
* > overlayAlpha: alpha level, 0.75 = 75%
* positionX: x-axis position - top
* positionY: y-axis position - left
*
*/
// alert('making box');
if (!(args.id)) { args.id = args[0]; }
if (!(args.boxTarget)) { args.boxTarget = 'body'; }
if (!(args.title)) { args.title = ""; }
if (!(args.positionX)) { args.positionX = "calc(32%)"; }
if (!(args.positionY)) { args.positionY = "calc(37.5%)"; }
if (!(args.height)) { args.height = "35%"; }
if (!(args.width)) { args.width = "25%"; }
if (args.overlay) {
if (!(args.overlayAlpha)) { args.overlayAlpha = 0.75; }
if (!(args.overlayColor)) { args.overlayColor = "0,0,0"; }
// $("<div id='" + args.id + "-overlayDiv' class='overlayDiv' style='height:100%; width:100%; background-color: rgba(0, 0, 0, 0.8); position:fixed; top:0px; left:0px; z-index: 102;'></div>").appendTo($('body'));//'div.efObjectDetails'
$("<div id='" + args.id + "-overlayDiv' class='overlayDiv' style='background-color: rgba(" + args.overlayColor + "," + args.overlayAlpha + ");'></div>").appendTo($(args.boxTarget));//'div.efObjectDetails'
args.boxTarget = '#' + args.id + "-overlayDiv";
}
var floatingBoxTemplate = "<table id='" + args.id + "' class='floatingBox' border='0' padding='0' style='top: " + args.positionX + "; left:" + args.positionY + "; width:" + args.width + "; height:" + args.height + ";'><tbody></tbody></table>";
$(floatingBoxTemplate).appendTo($(args.boxTarget));
$("<tr id='" + args.id + "-floatingBox-titleBar' class='pbHeader fbTitleBar'><td id='" + args.id + "-title' class='pbTitle fbTitle'><h3> " + args.title + "<h3></td><td id='" + args.id + "-btns' class='pbButton fbTitleBtns'></td><td id='" + args.id + "-close' class='fbTtileClose'></td></tr>").appendTo($('#' + args.id));
$("<a href='javascript:void(0)'> X </a>").click(
function() {
$('#' + args.id + "-overlayDiv").remove();
$('#' + args.id).remove();
}
).appendTo($('#' + args.id + '-close'));
$("<tr id='" + args.id + "-content' class='fbContent'></tr>").appendTo($('#' + args.id));
return {
"content": args.id + '-content',
"id": args.id,
"titleBtns": args.id + '-btns'
};
}
function triggerChange(targetId) {
var evt = document.createEvent("HTMLEvents");
evt.initEvent("change", false, true);
document.getElementById(targetId).dispatchEvent(evt);
}
function reviewChanges() {
if ($("#reviewChanges").length == 0){
// alert('reviewing change');
var fb = makeFloatingBox({"id":"reviewChanges","overlay":true,"title":"Whats New?"});
$("<select id='changesSelect'></select>").change(
function() {
$('#changesList').children().remove();
var verVal = $('#changesSelect option:selected').val();
for (var i = 2; i < changeLog[verVal].length; i++) {
var bolden = changeLog[verVal][i].split(':');
$("<li><b>" + bolden[0]+ ":</b>" + bolden[1] + "</li>").appendTo($("#changesList"));
}
}
).appendTo($('#' + fb.titleBtns));
for (var i = 0; i < changeLog.length; i++) {
$("<option id='change" + i + "' value='" + i + "'>" + changeLog[i][0] + " - " + changeLog[i][1] + "</option>").appendTo($('#changesSelect'));
}
$("<td colspan='3'><ul id='changesList' style='height:100%; width:100%; overflow:auto;'></ul></td>").appendTo($('#' + fb.content));
//On change function:
$('#changesList').children().remove();
var verVal = $('#changesSelect option:selected').val();
for (var i = 2; i < changeLog[verVal].length; i++) {
var bolden = changeLog[verVal][i].split(':');
$("<li><b>" + bolden[0]+ ":</b>" + bolden[1] + "</li>").appendTo($("#changesList"));
}
}
}
//Changelog review
function reviewChangesBak()
{
$("<div id='changesDiv' style='height:100%; width:100%; background-color: rgba(0, 0, 0, 0.8); position:fixed; top:0px; left:0px; z-index: 102;'></div>").appendTo($('body'));//'div.efObjectDetails'
$("<table id='changesTab' border='0' padding='0' style='position:absolute; top:calc(32%); left:calc(37.5%); background-color:#FFFFFF; width:25%; height: 35%;'><tbody></tbody></table>").appendTo($('#changesDiv'));
$("<tr id='changesTab-r1' style='border:1px solid rgb(216, 221, 230); height:28px; background-color: rgb(244, 246, 249);'><td id='changesTab-r1-c1' width='25%'><h3>What's New?<h3></td><td id='changesTab-r1-c2' width='65%'></td><td id='changesTab-r1-c3' width='10%'></td></tr>").appendTo($('#changesTab'));
$("<a href='javascript:void(0)'>Close</a>").click(function() { $('#changesDiv').remove(); }).appendTo($('#changesTab-r1-c3')); //add .click(function() {})
$("<tr id='changesTab-r2'></tr>").appendTo($('#changesTab'));
$("<select id='changesSelect'></select>").change(
function()
{
$('#changesList').children().remove();
var verVal = $('#changesSelect option:selected').val();
for (var i = 2; i < changeLog[verVal].length; i++)
{
var bolden = changeLog[verVal][i].split(':');
$("<li><b>" + bolden[0]+ ":</b>" + bolden[1] + "</li>").appendTo($("#changesList"));
}
}).appendTo($('#changesTab-r1-c2'));
for (var i = 0; i < changeLog.length; i++)
{
$("<option id='change" + i + "' value='" + i + "'>" + changeLog[i][0] + " - " + changeLog[i][1] + "</option>").appendTo($('#changesSelect'));
}
$("<td colspan='3'><ul id='changesList' style='height:90%; width:90%; overflow:auto;'></ul></td>").appendTo($('#changesTab-r2'));
//On change function:
$('#changesList').children().remove();
var verVal = $('#changesSelect option:selected').val();
for (var i = 2; i < changeLog[verVal].length; i++)
{
var bolden = changeLog[verVal][i].split(':');
$("<li><b>" + bolden[0]+ ":</b>" + bolden[1] + "</li>").appendTo($("#changesList"));
}
//$('#changesDiv').children().css('opacity', '1');
}
// TODO remove me?
var peekItHeight = 300;
var peekItWidth = 450;
//BEGIN: PeekIt
//BEGIN: HoverBox Style
$('<style id="Arrange_Hover_Box_Style">'+
".hoverBox {"+
"padding: 0;"+
//"position: absolute;"+
"position: fixed;"+
"overflow: hidden;"+
"top: 0;"+
"left: 0;"+
"border: 3px solid #0070d2;"+
"height: " + peekItHeight + "px;"+
"width: " + peekItWidth + "px;"+
"z-index: 70;"+
"background-color: rgb(255, 255, 255);"+
"box-shadow: rgba(0, 0, 0, 0.156863) 0px 2px 3px;"+
"border-radius: 4px;"+
"}"+
".hoverFrame {"+
"padding: 0;"+
"position: absolute;"+
"overflow: auto;"+
"top: 0;"+
"left: 0;"+
"border: 0px none;"+
"height: " + peekItHeight + "px;"+
"width: " + peekItWidth + "px;"+
//"height: 100%;"+
//"width: 100%;"+
//"z-index: 71;"+
"}"+
"</style>")
.appendTo($('body'));
//END: peekit Style
function peekIt(attachTo, insides) {
try {
//testing... peek?
// TODO FIX DISAPPEARING SCROLL BARS, only a problem on chrome...
// TODO look into mimicing default SC style
// TODO add peeks for: ??
// TODO add header with PopIt link
// TODO keep open & x buttons?
// TODO movable???
// TODO FIX WHOLE PAGE over-SCROLL!!!
// TODO FF cant do files (Content Security Policy Violation, ftp instead of HTTPS)
/*
var hoverBox2 = '<div id="hoverBox_' + attachTo + '" class="hoverBox individualPalette lookupHoverDetail lookupHoverDetailOverridable" style="height:300px, width:300px;display: none;"'+
" onmouseover=\"var hb = getElementById('hoverBox_" + attachTo + "'); hb.style.display='block';\"" +
" onmouseout=\"getElementById('hoverBox_" + attachTo + "').style.display='none';\">" +
'<div class="userProfileHoverUserBlock setupBlock topLeft">'+
'<div class="bPageBlock brandSecondaryBrd secondaryPalette">'+
'<div class="pbHeader brandSecondaryBrd"></div>'+
'<div id="hoverBox_' + attachTo + '_content" class="userProfileHoverBody pbBody"></div>'+
'<div class="pbFooter secondaryPalette">'+
'<div class="bg"></div>'+
'</div> </div> </div> </div>';
*/
var hoverBox = '<div id="hoverBox_' + attachTo + '" class="hoverBox" style="display: none;"' +
" onmouseover=\"var hb = getElementById('hoverBox_" + attachTo + "'); hb.style.display='block';\"" +
" onmouseout=\"getElementById('hoverBox_" + attachTo + "').style.display='none';\"" +
'></div>';
var hoverFrame = '<iframe id="hoverFrame_' + attachTo + '" class="hoverFrame"></iframe>';
var hb = $(hoverBox).appendTo("body");
//var hbc = $("#hoverBox_" + attachTo + "_content");
var hf = $(hoverFrame).appendTo(hb);
if (highlightPeeks) {
document.getElementById(attachTo).style.background = peekHighlightColor;
}
// Add eyes to identify as peekable
var image = document.createElement("img");
image.src = chrome.extension.getURL("images/eyes_40x20.png");
image.alt = "PeekIT!";
image.style = "height: 10px;";
document.getElementById(attachTo).prepend(" ");
document.getElementById(attachTo).prepend(image);
document.getElementById(attachTo)
.addEventListener("mouseover",
function(e) {
e = e || window.event;
var mx = e.clientX;
var my = e.clientY;
window.mytimeout = setTimeout(
function() {
try {
var hb = document.getElementById('hoverBox_' + attachTo);
hb.style.display = 'block';
var wx = document.documentElement.clientWidth;
var wy = document.documentElement.clientHeight;
var modY = -15;
var modX = -15;
//alert(wx - mx + " vs " + peekItWidth);
var dx = wx - mx;
var dy = wy - my;
var buffer = 10;
var safeSizeX = parseInt(peekItWidth) + buffer;
var safeSizeY = parseInt(peekItHeight) + buffer;
// Mod X
if (dx >= safeSizeX) // if mouse right has room, use it (looks better)
{
modX = -15;
}
else if (dx < safeSizeX && mx >= safeSizeX) // if mouse to right too small, & left OK, check left
{
modX = -safeSizeX + 5;
}
else // very small window..., hitting bounds on both sides
{
modX = dx - safeSizeX;
}
// Mod Y
if (dy >= safeSizeY) {
modY = -15;
}
else if (dy < safeSizeY && my >= safeSizeY) {
modY = -safeSizeY + 5;
}
else // very small window..., hitting bounds on both sides
{
modY = dy - safeSizeY;
}
hb.style.top = my + modY + 'px';
hb.style.left = mx + modX + 'px';
var ifr = document.getElementById('hoverFrame_' + attachTo);
if (ifr.src === '' || ifr.src === undefined) {
ifr.src = insides;
}
}
catch(e) {
logError("Failed to load Hoverframe page. Additional info: " + e);
}
}, peekDelay);
}
);
document.getElementById(attachTo)
.addEventListener("mouseout", function()
{
clearTimeout(window.mytimeout);
document.getElementById('hoverBox_' + attachTo).style.display = 'none';
}
);
document.getElementById(attachTo)
.addEventListener("blur", function()
{
clearTimeout(window.mytimeout);
document.getElementById('hoverBox_' + attachTo).style.display = 'none';
}
);
}
catch(e)
{
if ($('#alertHider').length > 0) {
addAlert(0, "ArrangeSC: Failed to create Hover Box: " + attachTo + ". <br />Additional info: " + e);
} else {
logError("Failed to create Hover Box: " + attachTo + ". Additional info: " + e);
}
}
}
//END: PeekIt
function prependZero(s)
{
if(s && s.indexOf("null") == -1)
{
s = s.toString().trim();
if(s.toString().length == 6)
{
s = "0" + s;
}
}
return s;
}
function addConvButton(pageName,friendlyName,type,arg)
{
// Types:
// - c = click button, arg = button jQuery selector statement
// - l = link, open a link with target _blank, arg = link
// - m = link, open a link with default target, arg = link
try
{
var buttonToAddCONV = $('<a/>').attr({'id': 'openCONV_' + pageName, 'class': 'btn', 'href': 'javascript:void(0)', 'title': friendlyName})
.css({'vertical-align': 'middle','margin': '3px', 'height': '17px', 'line-height': '17px', 'padding': '0 3px 0 3px'})
.text(friendlyName).prop('value', friendlyName);
if (type == 'c') buttonToAddCONV.unbind().click( function() { $(arg).click(); } );
else if (type == 'l') buttonToAddCONV.attr({'href': arg, 'target': '_blank'});
else if (type == 'm') buttonToAddCONV.attr({'href': arg});
var liToAddCONV = $('<li/>'); // Create a list item to add the link button into
buttonToAddCONV.appendTo(liToAddCONV); // Add link to <li> so it shows up properly in CONV dropdown
liToAddCONV.appendTo($("#convButtonHolder")); // Add button/li to CONV dropdown
//$("a#dismissLink").on("click", function() { $("[name='dismiss_the_selected_call_backs']").click(); });
//<li><a id=\"caCommentLink\" href=\"#\">Comment</a></li>\
}
catch(e)
{
if ($('#alertHider').length > 0) {
addAlert(0, "ArrangeSC: There was a problem adding the " + friendlyName + " Convenience button.<br />Additional info: " + e);
} else {
logError("There was a problem adding the " + friendlyName + " Convenience button. Additional info: " + e);
}
}
}
function addDropDown(id, text, target)
{
try
{
if (target === undefined)
{
target = $("#topButtonRow");
}
var popDropdownButton = "<button class=\"btn ca-button\" type=\"button\" id=\"" + id + "\" data-jq-dropdown=\"#BTNS-BTN-GRP-" + id + "\">" + text + "<span class=\"caret\"></span></button>";
var popDropdownDiv = "<div class=\"jq-dropdown\" id=\"BTNS-BTN-GRP-" + id + "\"><ul id=\"" + id + "ButtonHolder\" class=\"jq-dropdown-menu\"></ul></div>";
$("body").append(popDropdownDiv); // POP: Add the div that contains the magic - it can go anywhere within body, so just stick it at the end... It's not visable.
target.append(popDropdownButton); // POP: Add the button to top bar.
}
catch(e)
{
if ($('#alertHider').length > 0) {
addAlert(0, "ArrangeSC: Failed to add " + text + " drop-down button.<br />Additional info: " + e);
} else {
logError("Failed to add " + text + " drop-down button. Additional info: " + e);
}
}
}
function emailAdjustment(x)
{
x.each(
function()
{
var tt = $(this).text();
var skipVals = ["Reply","To All", "Del"];
if (skipVals.indexOf(tt) == -1) //(tt != "Reply" && tt != "To All" && tt != "Del")
{
var oldMailID = $(this).attr("href").replace("javascript:srcUp(%27%2F","").replace("%3Fisdtp%3Dvw%27);","");
var oldMailLink = "https://ca.my.salesforce.com/" + oldMailID + "?isdtp=vw&nonce=" + /*SID +*/ "&sfdcIFrameOrigin=https%3A%2F%2Fca.my.salesforce.com";
$(this).attr("id", oldMailID);
if (enablePeekIt)
{
peekIt(oldMailID,oldMailLink+"#ToAddress_ilecell");
}
if (popUpEmails)
{
$(this).click(
function()
{
newwindow=window.open(oldMailLink,'','height=' + popUpHeight + ',width=' + popUpWidth);
if (window.focus) { newwindow.focus(); }
return false;
}
);
}
}
}
);
}
function insertAtCaret(areaId, text) {
var txtarea = document.getElementById(areaId);
if (!txtarea) { return; }
var scrollPos = txtarea.scrollTop;
var strPos = 0;
// DONE remove browser check... only chrome here
// var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false ) );
// alert(br);
// if (br == "ie") {
// txtarea.focus();
// var range = document.selection.createRange();
// range.moveStart ('character', -txtarea.value.length);
// strPos = range.text.length;
// } else if (br == "ff") {
strPos = txtarea.selectionStart;
// }
var front = (txtarea.value).substring(0, strPos);
var back = (txtarea.value).substring(strPos, txtarea.value.length);
txtarea.value = front + text + back;
strPos = strPos + text.length;
// if (br == "ie") {
// txtarea.focus();
// var ieRange = document.selection.createRange();
// ieRange.moveStart ('character', -txtarea.value.length);
// ieRange.moveStart ('character', strPos);
// ieRange.moveEnd ('character', 0);
// ieRange.select();
// } else if (br == "ff") {
txtarea.selectionStart = strPos;
txtarea.selectionEnd = strPos;
txtarea.focus();
// }
txtarea.scrollTop = scrollPos;
}
/* Shared functions for Service Cloud User Scripts.
*
* This file originally written by kaise01
* Some functions may have been written by other authors and should be noted below
*
* Referece: http://cawiki.ca.com/display/CASupport/Service+Cloud+User+Scripts
*
* Release Notes:
* 1.4 - 7/27/2015