-
Notifications
You must be signed in to change notification settings - Fork 1
/
UoP-ehancer.user.js
1380 lines (1222 loc) · 50.8 KB
/
UoP-ehancer.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
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
// ==UserScript==
// @name UoPeople Moodle enhancer
// @author Ignas Poklad (Ignas2526)
// @namespace ignas2526_uopeople_moodle_enhancer
// @description Enhances UoPeople Moodle
// @version 0.3.0
// @downloadURL https://raw.githubusercontent.com/Ignas2526/UoPeople-Enahncer/raw/master/UoPeople-ehancer.user.js
// @updateURL https://raw.githubusercontent.com/Ignas2526/UoPeople-Enahncer/master/UoPeople-ehancer.meta.js
// @run-at document-start
// @include http://my.uopeople.edu/*
// @include https://my.uopeople.edu/*
// @connect my.uopeople.edu
// @connect capi.grammarly.com
// @connect paperrater.com
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @grant GM_log
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_openInTab
// ==/UserScript==
/*
This file is part of UoPeople Moodle Enhancer by Ignas Poklad (Ignas2526).
UoPeople Moodle Enhancer is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
UoPeople Moodle Enhancer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UoPeople Moodle Enhancer. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Changelog
* 0.3.0 2016.09.07
* Added PaperRater.
* Fixes in Student Data gathering.
* Fixes and visual improvements in embedded Forums.
* Inactivity alert will not show up after 2 hours and 30 minutes instead of 2 hours.
* One click login now properly handles bad responces like those during Moodle maintenance.
* Other minor improvements.
*
* 0.2.0 2016.08.31
* Added Student data in settings.
* Current courses will be shown at the top of the menu.
* Better request error handling in the Log-In and Gramarly.
* Other minor improvements.
*
* 0.1.0 2016.08.18
* Added Events window
* Last 2 week's forums are embedded into the main course page.
* Possibly logged-out message is now shown after 2 hours of inactivity.
* Possibly logged-out message now tells how much time had passed.
* Other minor script improvements.
*
* 0.0.2 2016.08.14
* Greatly improved log-in functionality
* More detailed log-In messages
* Added sesskey patching
* Improved Grammarly response displaying
* Added Automatic Update support
*
* 0.0.1 2016.08.12
* Initial realease
*/
/*
* TODO
* ADD https://www.paperrater.com/plagiarism_checker
http://paperrater.com/free_paper_grader
*/
/*
iWin class is part of iWin JS library by Ignas Poklad (Ignas2526).
iWin JS library is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
iWin JS library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with iWin JS library. If not, see <http://www.gnu.org/licenses/>.
*/
var iWin = {};
iWin.init = function()
{
iWin.win = {};
iWin.dragwID = null;
iWin.dragObj = -1;
iWin.dragSTop = null;
iWin.dragSleft = null;
iWin.dragMouseX = null;
iWin.dragMouseY = null;
iWin.dragWindowLimitX = 0;
iWin.dragWindowLimitY = 40;
iWin.resizeWidth = null;
iWin.resizeHeight = null;
iWin.zwin = [];
iWin.zindex = 99;
iWin.scroll_length = 0;
iWin.contentMaxAutoWidth = 810;
iWin.contentMaxAutoHeight = 610;
var tmpDiv = document.createElement('div');
tmpDiv.style.cssText = 'position:aboslute;top:-99px;left:-99px;width:70px;height:70px;overflow:scroll;border:0;margin:0;padding:0';
document.body.appendChild(tmpDiv);
iWin.scroll_length = tmpDiv.offsetWidth - tmpDiv.clientWidth;
document.body.removeChild(tmpDiv);
};
iWin.create = function(param, wID)
{
if (typeof iWin.win[wID] != 'undefined') return false;
iWin.win[wID] = {};
iWin.win[wID].wID = wID;
iWin.win[wID].obj = document.createElement('div');
iWin.win[wID].obj.className = "winb";
iWin.win[wID].obj.style.cssText = "display:none;top:50px;left:20px;";
iWin.win[wID].obj.innerHTML = '<div class="winbt"><i class="fa fa-times" style="color:red"></i><u></u></div><div class="winbb" style="display:none"></div><div class="winbc"></div>' +
'<div style="cursor:nwse-resize;width:20px;height:20px;position:absolute;right:-7px;bottom:-7px;"> </div>';
//'<div style="display:none;position:absolute;width:100%;height:100%;top:0;"></div>';// for modal window lock
/*"<img src=\"/img/refresh.png\" onclick=\"bref('"+id+"')\" /> "+*/
document.body.appendChild(iWin.win[wID].obj);
iWin.win[wID].onshow = typeof param.onshow == 'function' ? param.onshow : function(){};
iWin.win[wID].onhide = typeof param.onhide == 'function' ? param.onhide : function(){};
iWin.win[wID].onclose = typeof param.onclose == 'function' ? param.onclose : function(){};
iWin.win[wID].onrefresh = typeof param.onrefresh == 'function' ? param.onrefresh : function(){};
iWin.win[wID].obj.addEventListener('mousedown', function(){iWin.toFront(wID);}, true);
iWin.win[wID].obj.children[0].addEventListener('mousedown', function(e) {iWin.drag(wID, e);}, true);
iWin.win[wID].obj.children[0].children[0].addEventListener('mousedown', function(e) {iWin.win[wID].onclose(wID, e);}, true);
iWin.win[wID].obj.children[3].addEventListener('mousedown', function(e) {iWin.resize(wID, e);}, true);
iWin.win[wID].contentWidth = 0;
iWin.win[wID].contentHeight = 0;
iWin.win[wID].contentScroll = false;
iWin.setTitle(param.title, wID);
return true;
}
iWin.destroy = function(wID, e)
{
if (typeof iWin.win[wID] == 'undefined') return false;
var evt = e || window.event;
iWin.zRemove(wID);
document.body.removeChild(iWin.win[wID].obj);
delete iWin.win[wID];
if (evt) evt.stopPropagation();
return true;
}
iWin.show = function(wID)
{
if (iWin.win[wID].obj.style.display == 'block') return false;
iWin.win[wID].obj.style.display = 'block';
iWin.zAdd(wID);
iWin.win[wID].onshow(wID);
return true;
}
iWin.hide = function(wID)
{
if (iWin.win[wID].obj.style.display == 'none') return false;
iWin.win[wID].onhide(wID);
iWin.win[wID].obj.style.display = 'none';
iWin.zRemove(wID);
return true;
}
iWin.refresh = function(wID)
{
iWin.win[wID].onrefresh(wID);
return true;
}
iWin.setTitle = function(title, wID)
{
if (typeof title == 'undefined' || !title.length) {
iWin.win[wID].titlebar = false;
iWin.win[wID].obj.children[0].style.display = 'none';
} else {
iWin.win[wID].titlebar = true;
iWin.win[wID].obj.children[0].style.display = 'block';
iWin.win[wID].obj.children[0].children[1].innerHTML = title;
}
return true;
}
iWin.setContent = function(content, autoSize, wID)
{
iWin.win[wID].obj.children[2].innerHTML = content;
if (autoSize) iWin.setContentDimensionsAuto(wID)
return true;
}
iWin.setContentDimensions = function(width, height, wID)
{
iWin.win[wID].contentWidth = parseInt(width, 10);
iWin.win[wID].contentHeight = parseInt(height, 10);
iWin.win[wID].obj.children[2].style.width = (iWin.win[wID].contentWidth + (iWin.win[wID].contentScroll ? iWin.scroll_length : 0)) + 'px';
iWin.win[wID].obj.children[2].style.height = iWin.win[wID].contentHeight + 'px';
return true;
}
iWin.setContentScroll = function(scroll, wID)
{
iWin.win[wID].contentScroll = scroll ? true : false;
if (iWin.win[wID].contentScroll) {
iWin.win[wID].obj.children[2].style.overflowY = 'scroll';
iWin.win[wID].obj.children[2].style.width = (iWin.win[wID].contentWidth + iWin.scroll_length) + 'px';
}
return true;
}
iWin.setPosition = function(top, left, wID)
{
iWin.win[wID].obj.style.top = parseInt(top, 10) + 'px';
iWin.win[wID].obj.style.left = parseInt(left, 10) + 'px';
return true;
}
iWin.setContentDimensionsAuto = function(wID)
{
// The order of operations is important
var posTop = iWin.win[wID].obj.offsetTop, posLeft = iWin.win[wID].obj.offsetLeft;
iWin.win[wID].obj.style.top = '-9999px';
iWin.win[wID].obj.style.left = '-9999px';
var isHidden = iWin.show(wID);
iWin.win[wID].obj.children[2].style.width = 'auto';
iWin.win[wID].obj.children[2].style.height = 'auto';
iWin.win[wID].obj.children[2].style.overflow = '';
iWin.win[wID].contentWidth = iWin.win[wID].obj.children[2].scrollWidth;
if (iWin.win[wID].contentWidth < 10) iWin.win[wID].contentWidth = 10;
else if (iWin.win[wID].contentWidth > iWin.contentMaxAutoWidth) iWin.win[wID].contentWidth = iWin.contentMaxAutoWidth;
iWin.win[wID].obj.children[2].style.width = iWin.win[wID].contentWidth + 'px';
iWin.win[wID].contentHeight = iWin.win[wID].obj.children[2].scrollHeight;
if (iWin.win[wID].contentHeight > iWin.contentMaxAutoHeight) {
iWin.win[wID].contentHeight = iWin.contentMaxAutoHeight;
iWin.win[wID].contentScroll = true;
} else if (iWin.win[wID].contentHeight < 10) iWin.win[wID].contentHeight = 10;
if (iWin.win[wID].contentScroll) {
iWin.win[wID].obj.children[2].style.overflowY = 'scroll';
iWin.win[wID].obj.children[2].style.width = (iWin.win[wID].contentWidth + iWin.scroll_length) + 'px';
}
iWin.win[wID].obj.children[2].style.height = iWin.win[wID].contentHeight + 'px';
iWin.win[wID].obj.style.top = posTop + 'px';
iWin.win[wID].obj.style.left = posLeft + 'px';
if (isHidden) iWin.hide(wID);
return true;
}
iWin.showTab = function(tID, wID)
{
for (var i = 0; i < iWin.win[wID].obj.children[2].children.length; i++) {
if (iWin.win[wID].obj.children[2].children[i].getAttribute('data-id') == tID)
iWin.win[wID].obj.children[2].children[i].style.display = 'block';
else
iWin.win[wID].obj.children[2].children[i].style.display = 'none';
}
return true;
}
iWin.setTabs = function(tabs, wID)
{
var first = '';
iWin.win[wID].obj.children[1].innerHTML = '';
for (var id in tabs) {
if (typeof(id) == 'undefined') continue;
if (!first.length) {first = id;}
var obj = document.createElement('div');
obj.className = 'winbbt';
(function(id, wID){obj.onclick = function(){iWin.showTab(id, wID);};})(id, wID);
obj.innerHTML = tabs[id];
iWin.win[wID].obj.children[1].appendChild(obj);
}
if (first.length) {
iWin.win[wID].obj.children[1].style.display = 'block';
iWin.showTab(first, wID);
} else {
iWin.win[wID].obj.children[1].style.display = 'none';
}
return true;
}
iWin.zAdd = function(wID)
{
iWin.zindex++;
iWin.win[wID].obj.style.zIndex = iWin.zindex;
iWin.zwin[iWin.zindex] = iWin.win[wID].obj;
return true;
}
iWin.zRemove = function(wID)
{
var zID = parseInt(iWin.win[wID].obj.style.zIndex, 10);
for (var i = zID + 1; i < iWin.zindex + 1; i++) {iWin.zwin[i - 1] = iWin.zwin[i]; iWin.zwin[i].style.zIndex = i - 1;}
delete iWin.zwin[iWin.zindex];
iWin.zindex--;
return true;
}
iWin.toFront = function(wID)
{
var zID = parseInt(iWin.win[wID].obj.style.zIndex, 10);
if (zID != iWin.zindex) {
for (var i = zID + 1; i < iWin.zindex + 1; i++) {
iWin.zwin[i - 1] = iWin.zwin[i];
iWin.zwin[i].style.zIndex = i - 1;
}
iWin.zwin[iWin.zindex] = iWin.win[wID].obj;
iWin.win[wID].obj.style.zIndex = iWin.zindex;
}
return true;
}
iWin.drag = function(wID, e)
{
var evt = e || window.event;
if (iWin.dragObj != -1) iWin.MoveStop(); // prevent multiple drags
iWin.dragwID = wID;
iWin.dragObj = iWin.win[wID].obj;
iWin.dragMouseX = evt.clientX; iWin.dragMouseY = evt.clientY;
iWin.dragSTop = iWin.dragObj.offsetTop; iWin.dragSLeft = iWin.dragObj.offsetLeft;
document.body.classList.add('nse');
document.addEventListener('mousemove', iWin.dragM, true);
document.addEventListener('mouseup', iWin.MoveStop, true);
document.addEventListener('blur', iWin.MoveStop, true);
document.addEventListener('mouseout', iWin.MoveStop2, true);
return true;
}
iWin.resize = function(wID, e)
{
var evt = e || window.event;
if (iWin.dragObj != -1) iWin.MoveStop(); // prevent multiple drags
iWin.dragwID = wID;
iWin.dragObj = iWin.win[wID].obj;
iWin.dragMouseX = evt.clientX; iWin.dragMouseY = evt.clientY;
iWin.resizeWidth = iWin.win[wID].contentWidth + (iWin.win[wID].contentScroll ? iWin.scroll_length : 0);
iWin.resizeHeight = iWin.win[wID].contentHeight;
document.body.classList.add('nse');
document.addEventListener('mousemove', iWin.resizeM, true);
document.addEventListener('mouseup', iWin.MoveStop, true);
document.addEventListener('blur', iWin.MoveStop, true);
document.addEventListener('mouseout', iWin.MoveStop2, true);
return true;
}
iWin.resizeM = function(e)
{
var wID = iWin.dragwID;
iWin.win[wID].contentWidth = iWin.resizeWidth + e.clientX - iWin.dragMouseX;
if (iWin.win[wID].contentWidth < 100) iWin.win[wID].contentWidth = 100;
iWin.win[wID].obj.children[2].style.width = iWin.win[wID].contentWidth + 'px';
iWin.win[wID].contentHeight = iWin.resizeHeight + e.clientY - iWin.dragMouseY;
if (iWin.win[wID].contentHeight < 20) iWin.win[wID].contentHeight = 20;
iWin.win[wID].obj.children[2].style.height = iWin.win[wID].contentHeight + 'px';
}
iWin.dragM = function(e)
{
var NewWindowY = iWin.dragSTop + e.clientY - iWin.dragMouseY;
var NewWindowX = iWin.dragSLeft + e.clientX - iWin.dragMouseX;
if (NewWindowY < iWin.dragWindowLimitY) NewWindowY = iWin.dragWindowLimitY;
if (NewWindowY > (window.innerHeight - 10)) NewWindowY = window.innerHeight - 10;
if (NewWindowX < iWin.dragWindowLimitX) NewWindowX = iWin.dragWindowLimitX;
// TODO: add proper limit config if (e.clientX < 5) NewWindowX = iWin.dragSLeft + 5 - iWin.dragMouseX;
if (NewWindowX > (window.innerWidth - 10)) NewWindowX = window.innerWidth - 10;
iWin.dragObj.style.top = NewWindowY + 'px'; iWin.dragObj.style.left = NewWindowX + 'px';
};
iWin.MoveStop2 = function(e)
{
if ((e.pageY >= 0 && e.pageY <= window.innerHeight) && (e.pageX >= 0 && e.pageX <= window.innerWidth)) return;
iWin.MoveStop();
};
iWin.MoveStop = function()
{
document.body.classList.remove('nse');
document.removeEventListener('mousemove', iWin.resizeM, true);
document.removeEventListener('mousemove', iWin.dragM, true);
document.removeEventListener('mouseup', iWin.MoveStop, true);
document.removeEventListener('blur', iWin.MoveStop, true);
document.removeEventListener('mouseout', iWin.MoveStop2, true);
iWin.dragObj = -1;
if (document.selection && document.selection.empty) {document.selection.empty();}else if (window.getSelection) {window.getSelection().removeAllRanges();}
};
iWin.messageBox = function(msg, params, _wID)
{
// TOOD: _wID will be used in future for modal messageBox
var wID = 'iAlert' + new Date().getTime();
iWin.create({title: params.title, onclose:function(wID, e){iWin.destroy(wID, e);}}, wID);
iWin.setContent(msg, true, wID);
iWin.setPosition(60, (window.innerWidth / 2) - 20, wID);
iWin.show(wID);
iWin.toFront(wID);
iWin.show(wID);
if (typeof params.timeout != 'undefined')
setTimeout(function(e){iWin.destroy(wID, e);}, parseInt(params.timeout, 10));
return true;
};
window.addEventListener('DOMContentLoaded', function()
{
UoPE_menu_init();
setTimeout(UoP_cosmetic_improvements, 0);
uop_time_init();
GM_addStyle(
".winb, .winbt, .winbb, .winbbt, .winbc{box-sizing:border-box;}"+
".nse{-moz-user-select:-moz-none;-moz-user-select:none;-o-user-select:none;-khtml-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none}"+
".winb{overflow:hidden;position:fixed;border:1px solid #003;border-radius:2px;background:#FDFDFD;}"+
".winbt{display:block;border:solid #003;border-width:0px 0px 1px 0px;font-size:15px;cursor:move}"+
".winbt>img{margin:0px 1px -2px 1px;cursor:pointer}"+
".winbb{display:block;border:solid #003;border-width:0px 0px 1px 0px;font-size:15px;}"+
".winbbt{display:inline-block;padding:1px 2px;border:solid #003;border-width: 0px 1px 0px 0px;cursor:pointer}"+
".winbc{display:block;white-space:nowrap;padding:5px}"+
".winbt u{text-decoration:none;vertical-align:top;}"+
".winbc h1, .winbc h2, .winbc h3, .winbc h4, .winbc h5, .winbc h6{margin:0;line-height:1.5;}"
);
iWin.init();
log_out_handler_init();
uop_time_init();
}, 0);
window.onfocus = function()
{
is_possibly_logged_out();
};
function UoPE_menu_init()
{
GM_addStyle(
"#uope_menu{position:fixed; margin:0; padding:3px 4px; display:block; top:0; right:0; cursor:pointer; z-index:100;" +
"border-radius:2px;font-size:20px;color:#fff;background:rgba(0,0,0,.7);}" +
"#uope_menu > *{cursor:pointer}" +
".uope_menu_mt{text-align:right}" +
".uope_menu_mm{display:none}" +
".uope_menu_mm a {display:block; color:#fff}" +
"#uope_menu:hover .uope_menu_mm{display:block;}" +
".ume-invisible-overlay{position:fixed;width:100%;height:100%;left:0;top:0;}"
);
var menu = document.createElement('div');
menu.id = 'uope_menu';
menu.innerHTML = '<div class="uope_menu_mt"><i class="fa fa-bars"> </i></div><div class=\"uope_menu_mm\"></div>';
document.body.appendChild(menu);
var menu_itm;
if (settings.student_data.profileId) {
for (var i = 0; i < settings.student_data.courses.length; i++) {
menu_itm = document.createElement('a');
menu_itm.innerText = settings.student_data.courses[i].name;
menu_itm.href = 'http://my.uopeople.edu/course/view.php?id=' + settings.student_data.courses[i].id;
menu.children[1].appendChild(menu_itm);
}
}
menu_itm = document.createElement('div');
menu_itm.innerText = 'Log me in';
menu_itm.onclick = do_uop_login;
menu.children[1].appendChild(menu_itm);
menu_itm = document.createElement('div');
menu_itm.innerText = 'Grammarly';
menu_itm.onclick = open_grammarly_window;
menu.children[1].appendChild(menu_itm);
menu_itm = document.createElement('div');
menu_itm.innerText = 'Paperrater';
menu_itm.onclick = open_paperrater_window;
menu.children[1].appendChild(menu_itm);
menu_itm = document.createElement('div');
menu_itm.innerText = 'Events';
menu_itm.onclick = open_events_window;
menu.children[1].appendChild(menu_itm);
menu_itm = document.createElement('div');
menu_itm.innerText = 'Settings';
menu_itm.onclick = open_settings_window;
menu.children[1].appendChild(menu_itm);
}
function UoP_cosmetic_improvements()
{
/*
* Changes for the main course page
* http://my.uopeople.edu/course/view.php?id=XXX
*/
if (top.location.toString().indexOf('course/view.php') != -1) {
GM_addStyle('.forumheaderlist thead,.forumheaderlist{border:1px solid black;width:100%}td .unread{margin:0 !important} .author,.replies,.lastpost{text-align:center}');
// Remove big UoP logo at the top
var logo_img = document.querySelectorAll('#section-0 .summary img');
if (logo_img && logo_img[0]) {
logo_img[0].parentElement.removeChild(logo_img[0]);
}
// Reverse order the weeks so that current week is at the top of the page and so on
var sections = [];
for (var i = 0; i < 10; i++) {
var section = document.getElementById('section-' + i);
if (section == null) break;
sections[i] = section;
}
if (sections.length > 2) {
for (var i = 2; i < sections.length; i++) {
sections[0].parentNode.insertBefore(sections[i],sections[i -1]);
}
}
// Proper last week: sections[sections.length - 1]
// Currently we show for last two weeks
var limit = sections.length > 2 ? sections.length - 2 : sections.length - 1;
for (i = sections.length; i >= limit; i--) {
console.log(i % sections.length);
var latest_week_obj = sections[i % sections.length];
var forum_obj = latest_week_obj.querySelectorAll('.forum');
for (var j = 0; j < forum_obj.length; j++) {
var href = forum_obj[j].children[0].children[0].children[1].children[0].children[0].href;
if (!href) continue;
(function(j, href,forum_obj){
GM_xmlhttpRequest({
method: "GET",
url: href,
onload: function(response) {
if (response.responseText) {
var forum = response.responseText.match(/<table[\s\S]*<\/table>/);
if (forum !== null) {
forum = forum[0].replace(/<td class="picture">.*<\/td>/gi, '<td> </td>');
forum = forum.replace(/<th class="header group" scope="col">Group<\/th>/gi, '');
forum = forum.replace(/<td class="picture group">.*<\/td>/gi, '');
forum = forum.replace(/<a href="([^"]*)">.*\(Instructor\)/gi, '<a href="$1">(Instructor)');
forum_obj[j].innerHTML += forum;
}
}
}
});
})(j, href,forum_obj);
}
}
}
}
/*
* The functions below deal with UoP log-in
*/
var in_process_login = false; // Prevent parallel log-in
function do_uop_login()
{
if (in_process_login) return;
if (!settings.uop_login[0].length || !settings.uop_login.length) {
iWin.messageBox('You did not provide UoP Enhancer with your UoP username and password.', {title:'Auto Log-In', timeout:5000});
return;
}
in_process_login = true;
var sesskey_patch_success_msg = 'sesskey was found and patched.';
var sesskey_patch_failure_msg = '<span style="color:red">sesskey was not patched!<br>Back-up form data, if any!</span>';
GM_xmlhttpRequest({
method: "GET",
url: "http://my.uopeople.edu/",
onload: function(response) {
if (response.responseText.indexOf('Log in to the site') != -1) {
GM_xmlhttpRequest({
method: "POST",
url: "https://my.uopeople.edu/login/index.php",
data: "username=" +settings.uop_login[0]+ "&password=" +settings.uop_login[1]+ "&rememberusername=1",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Referer": "https://my.uopeople.edu/login/index.php"
},
onload: function(response)
{
if (response.responseText.indexOf('You are logged in as') != -1) {
var msg = 'Successfully logged in.<br>';
var sesskey = response.responseText.match(/"sesskey":"([^"]+)"/);
if (sesskey.length == 2) {
log_in_patch_sesskey(sesskey[1]);
msg += sesskey_patch_success_msg;
} else {
msg += sesskey_patch_failure_msg;
}
iWin.messageBox(msg, {title:'Auto Log-In', timeout:5000});
in_process_login = false;
} else {
iWin.messageBox('<span style="color:red">Error:</span> Moodle returned weird responce.<br>Perhaps there\'s maintenance?', {title:'Auto Log-In'});
in_process_login = false;
}
},
onerror: function(response)
{
iWin.messageBox('<span style="color:red">Failed to Log-In!</span><br>Request error.', {title:'Auto Log-In', timeout:5000});
in_process_login = false;
}
});
} else if (response.responseText.indexOf('You are logged in as') != -1) {
var msg = 'Already logged in.<br>';
var sesskey = response.responseText.match(/"sesskey":"([^"]+)"/);
if (sesskey !== null && sesskey.length == 2) {
log_in_patch_sesskey(sesskey[1]);
msg += sesskey_patch_success_msg;
} else {
msg += sesskey_patch_failure_msg;
}
iWin.messageBox(msg, {title:'Auto Log-In', timeout:5000});
in_process_login = false;
} else {
iWin.messageBox('<span style="color:red">Error:</span> Moodle returned weird responce.<br>Perhaps there\'s maintenance?', {title:'Auto Log-In'});
in_process_login = false;
}
}
});
}
/*
* After we logged in, we need to patch sesskey on the current page.
* We can do that by replacing it with the one we found in the responce page after log-in.
* Without patching the sesskey, submittig form on the current page will cause invalid sesskey error.
* There are couple other places where we could patch the sesskey such as log-out link, however,
* we don't really care that much about them.
*/
function log_in_patch_sesskey(sesskey)
{
if (typeof window.M != 'undefined') {
window.M.cfg.sesskey = sesskey;
} else if (typeof unsafeWindow.M != 'undefined') {
unsafeWindow.M.cfg.sesskey = sesskey;
}
var el = document.querySelectorAll('input[name="sesskey"]');
for (var i = 0; i < el.length; i++) {
el[i].value = sesskey;
}
}
var possibly_logged_out_after = (2 * 60 + 30) * 60 * 1000; //2h 30min in milliseconds
var invisible_overlay_obj = null;
var time_when_page_loaded = new Date().getTime(); // Unix timestamp
function log_out_handler_init()
{
invisible_overlay_obj = document.createElement('div');
invisible_overlay_obj.className = 'ume-invisible-overlay';
invisible_overlay_obj.style.display = 'none';
invisible_overlay_obj.onclick = show_possibly_logged_out_warning;
document.body.appendChild(invisible_overlay_obj);
}
function show_possibly_logged_out_warning()
{
invisible_overlay_obj.style.display = 'none';
var wID = 'inactivityWarn';
iWin.create({title: 'Inactivity Warning', onclose:function(wID, e){iWin.destroy(wID, e);}}, wID);
iWin.setContent('You had this page open for ' + format_time_period(new Date().getTime() - time_when_page_loaded, false) + '.<br>' +
'There\'s a chance that Moodle logged you out automatically.<br>' +
'If you are in any form (e.g. learning journal, forum reply, PM),<br>' +
'you should click on "Log me in" in the UoP ehancher menu,<br>' +
'or backup you work and log back in manually,<br>' +
'<b>before</b> you try to submit the form.', true, wID);
iWin.setPosition(60, (window.innerWidth / 2) - 20, wID);
iWin.show(wID);
time_when_page_loaded = new Date().getTime();
}
function is_possibly_logged_out()
{
var inactive_for = new Date().getTime() - time_when_page_loaded;
// If page was loaded for less than hour, we are should still be logged in.
if (inactive_for < possibly_logged_out_after) return;
invisible_overlay_obj.style.display = 'block';
}
setTimeout(function(){
is_possibly_logged_out();
}, possibly_logged_out_after);
function open_grammarly_window()
{
var wID = 'grammarlyWindowID';
var window_exists = !iWin.create({title: 'Grammarly Text Check', onclose:function(wID, e){iWin.destroy(wID, e);}}, wID);
iWin.setContent('<div id="plagiarism_check_responce" style="overflow-y:scroll"><strong>Plagiarism</strong><br><strong>Contextual Spelling</strong><br><strong>Grammar</strong><br><strong>Punctuation</strong><br><strong>Sentence Structure</strong><br><strong>Style</strong><br><strong>Vocabulary enhancement</strong><br>' +
'</div><textarea rows="8" cols="50" id="plagiarism_check_text"></textarea><br>' +
'<input type="button" id="plagiarism_check" value="Check">', true, wID);
iWin.setPosition(60, (window.innerWidth / 2) - 20, wID);
iWin.show(wID);
if (!window_exists) {
document.getElementById('plagiarism_check').onclick = plagiarism_check;
}
}
var in_process_grammarly = false;
function plagiarism_check()
{
if (in_process_grammarly) return;
in_process_grammarly = true;
data = document.getElementById('plagiarism_check_text').value;
GM_xmlhttpRequest({
method: "POST",
url: "https://capi.grammarly.com/api/check",
data: data,
headers: {
"Content-Type": "text/plain",
"Accept": "application/json",
"Accept-Language": "en-US,en;q=0.5",
"Origin": "https://www.grammarly.com",
"Referer": "https://www.grammarly.com/plagiarism?q=plagiarism"
},
onload: function(response) {
if (response.responseText) {
var jsonResp = JSON.parse(response.responseText);
var out = '';
// TODO: add word count: a.replace(/\W+/g, " ").split(' ').length
// TODO: that word count doesn't work with-a-word-like-that
var plag_count = grammarly_find_value('Plagiarism', 'Plagiarism', jsonResp);
out += '<strong>Plagiarism</strong> ' + plag_count + '% of words<br>';
for (var i = 0; i < grammarly_check_values.length; i++) {
out += '<strong>' + grammarly_check_values[i].name+ '</strong>';
for (var j = 0; j < grammarly_check_values[i].items.length; j++) {
var count = grammarly_find_value(grammarly_check_values[i].key, grammarly_check_values[i].items[j].key, jsonResp);
if (count) {
out += ' ' + count + ' ' + grammarly_check_values[i].items[j].name;
}
}
out += '<br>';
}
document.getElementById('plagiarism_check_responce').innerHTML = out;
} else {
iWin.messageBox('<span style="color:red">Request to Grammarly API had failed</span>', {title:'Grammarly', timeout:5000});
}
in_process_grammarly = false;
},
onerror: function(response)
{
iWin.messageBox('<span style="color:red">Request to Grammarly API had failed</span>', {title:'Grammarly', timeout:5000});
in_process_grammarly = false;
}
});
}
function grammarly_find_value(group, category, obj)
{
for (var i = 0; i < obj.length; i++) {
if (obj[i].group == group && obj[i].category == category) return obj[i].count;
}
return 0;
}
var grammarly_check_values = [{
name: "Contextual Spelling",
key: "ContextualSpelling",
items: [
{key: "AccidentallyConfused", name: "Confused Words"},
{key: "BritishVsAmerican", name: "Mixed Dialects of English"},
{key: "CommonlyConfused", name: "Commonly Confused Words"},
{key: "Misspelled", name: "Misspelled Words"},
{key: "Unknown", name: "Unknown Words"}
]
}, {
name: "Grammar",
key: "Grammar",
items: [
{key: "Determiners",name: "Determiner Use (a/an/the/this, etc.)"},
{key: "Conditional", name: "Conditional Sentences"},
{key: "Conjunctions", name: "Conjunction Use"},
{key: "Modals", name: "Modal Verbs"},
{key: "Modifiers", name: "Misuse of Modifiers"},
{key: "Nouns", name: "Incorrect Noun Number"},
{key: "Numerals", name: "Numeral Use"},
{key: "Prepositions", name: "Wrong or Missing Prepositions"},
{key: "Pronouns", name: "Pronoun Use"},
{key: "Quantifiers", name: "Misuse of Quantifiers"},
{key: "SVA", name: "Faulty Subject-Verb Agreement"},
{key: "Verbs", name: "Incorrect Verb Forms"},
{key: "Tenses", name: "Faulty Tense Sequence"},
{key: "Lexical", name: "Incorrect Phrasing"}
]
}, {
name: "Punctuation",
key: "Punctuation",
items: [
{key: "BasicPunct", name: "Comma Misuse within Clauses"},
{key: "ClosingPunct", name: "Closing Punctuation"},
{key: "CompPunct", name: "Punctuation in Compound/Complex Sentences"},
{key: "SpecialCharacters", name: "Misuse of Semicolons, Quotation Marks, etc."}
]
}, {
name: "Sentence Structure",
key: "SentenceStructure",
items: [
{key: "Fragment",name: "Incomplete Sentences"},
{key: "Parallelism", name: "Faulty Parallelism"},
{key: "WordOrder", name: "Misplaced Words or Phrases"}
]
}, {
name: "Style",
key: "Style",
items: [
{key: "Colloquial", name: "Inappropriate Colloquialisms"},
{key: "Formatting", name: "Improper Formatting"},
{key: "OldWords", name: "Outdated Language"},
{key: "PassiveVoice", name: "Passive Voice Misuse"},
{key: "ToneCheck", name: "Politically Incorrect or Offensive Language"},
{key: "TooFormal", name: "Inappropriate Formality"},
{key: "Wordiness", name: "Wordy Sentences"},
{key: "Clarity", name: "Unclear Reference"}
]
}, {
name: "Vocabulary enhancement",
key: "Enhancement",
items:
[
{key: "_WordChoice", name: "Word Choice"}
]
}];
/*
* Paper Rater functions
*/
function open_paperrater_window()
{
var wID = 'paperraterWindowID';
var window_exists = !iWin.create({title: 'PaperRater Check', onclose:function(wID, e){iWin.destroy(wID);}}, wID);
iWin.setContent('<textarea rows="8" cols="50" id="paperrater-text"></textarea><br>' +
'<input type="button" id="paperrater-analyze" value="Check">', true, wID);
iWin.setPosition(60, (window.innerWidth / 2) - 20, wID);
iWin.show(wID);
if (!window_exists) {
document.getElementById('paperrater-analyze').onclick = paperrater_check;
}
}
var in_process_paperrater = false;
function paperrater_check()
{
if (in_process_paperrater) return;
in_process_paperrater = true;
GM_xmlhttpRequest({
method: "GET",
url: "http://paperrater.com/free_paper_grader",
headers: {
"Accept-Language": "en-US,en;q=0.8",
"Origin": "http://paperrater.com",
},
onload: function(response) {
if (response.responseText) {
var csrf_token = response.responseText.match(/name="authenticity_token" type="hidden" value="([^"]*)"/);
if (csrf_token.length != 2) {
iWin.messageBox('<span style="color:red">Request to PaperRater API had failed</span>', {title:'PaperRater Check', timeout:5000});
in_process_paperrater = false;
return;
}
csrf_token = csrf_token[1];
data = document.getElementById('paperrater-text').value;
GM_xmlhttpRequest({
method: "POST",
url: 'http://paperrater.com/site/submit_paper',
// %5B is [ %5D is ]
data: 'utf8=%E2%9C%93' +
'&authenticity_token=' + encodeURIComponent(csrf_token) +
'&submission%5Bpaper%5D=' + encodeURIComponent(data) +
'&submission%5Bworks_cited%5D=' +
'&submission%5Beducation_level%5D=14' +
'&submission%5Bpaper_type%5D=' +
'&submission%5Boriginality_option%5D=skip' +
'&terms=on',
headers: {
'Accept':'*/*;q=0.5, text/javascript, application/javascript, application/ecmascript, application/x-ecmascript',
'Content-Type':'application/x-www-form-urlencoded',
'Origin':'http://paperrater.com',
'Referer':'http://paperrater.com/free_paper_grader',
'X-Csrf-Token': csrf_token,
'X-Requested-With':'XMLHttpRequest',
},
onload: function(response) {
if (response.responseText) {
var ticket_id = response.responseText.match(/style=\\"display:none\\">([^<]*)</);
if (ticket_id === null || ticket_id.length != 2) {
iWin.messageBox('<span style="color:red">Request to PaperRater API had failed</span>', {title:'PaperRater Check', timeout:5000});
in_process_paperrater = false;
return;
}
ticket_id = ticket_id[1];
// Orignial PaperRater waits at least 8 seconds or so. We will wait 2 seconds before checking the status of submission.
setTimeout(function(){plagiarism_check_status_check(csrf_token, ticket_id);}, 3000);
} else {
iWin.messageBox('<span style="color:red">Request to PaperRater API had failed</span>', {title:'PaperRater Check', timeout:5000});
}
in_process_paperrater = false;
},
onerror: function(response)
{
iWin.messageBox('<span style="color:red">Request to PaperRater API had failed</span>', {title:'PaperRater Check', timeout:5000});
in_process_paperrater = false;
}
});
} else {
iWin.messageBox('<span style="color:red">Request to PaperRater API had failed</span>', {title:'PaperRater Check', timeout:5000});
}
in_process_paperrater = false;
},
onerror: function(response)
{
iWin.messageBox('<span style="color:red">Request to PaperRater API had failed</span>', {title:'PaperRater Check', timeout:5000});
in_process_paperrater = false;
}
});
}
function plagiarism_check_status_check(csrf_token, ticket_id)
{
console.log(csrf_token, ticket_id);
GM_xmlhttpRequest({
method: "GET",
url: 'http://paperrater.com/ticket/' + ticket_id,
headers: {
'Referer':'http://paperrater.com/free_paper_grader',
},
onload: function(response) {
if (response.responseText) {
if (response.responseText.indexOf('Submission was blank') != -1) {
setTimeout(function(){plagiarism_check_status_check(csrf_token, ticket_id);}, 2000);
} else {
GM_openInTab('http://paperrater.com/ticket/' + ticket_id, 1);
}
} else {
iWin.messageBox('<span style="color:red">Request to PaperRater API had failed</span>', {title:'PaperRater Check', timeout:5000});
}
in_process_paperrater = false;