-
Notifications
You must be signed in to change notification settings - Fork 0
/
CanvasAllInfo.user.js
730 lines (703 loc) · 25 KB
/
CanvasAllInfo.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
// ==UserScript==
// @name Canvas All Info
// @namespace https://github.com/maccorehenni
// @version 1.0.0
// @icon https://canvas.instructure.com/favicon.ico
// @copyright 2020-2021, Daniel Lau (orignal); 2022, Mac Henni and others (improvements)
// @license MIT
// @description Place all information on a single page (https://canvas.example.com/all or https://example.instructure.com/all)
// @author machenni
// @include /^https:\/\/canvas\.[a-z0-9]*?\.[a-z]*?\/all\/?(\?.*)?$/
// @include /^https:\/\/[a-z0-9]*?\.instructure\.com\/all\/?(\?.*)?$/
// @grant none
// ==/UserScript==
/*
thanks to Mr. Lau from Userscriptzone (original)
Note:
- This userscript uses public APIs accessed by canvas
- Gets class information
- Gets assignments
- Gets basic teacher information
- This userscript does not store or upload any information gathered by the script
- This userscript overwrites /all in canvas
- This userscript was originally developed for Oregon State University
Useful Links (for use later?)
/api/v1/conversations?scope=inbox&filter_mode=and&include_private_conversation_enrollments=false
- Canvas mail
/api/v1/conversations/(mailbox_id)?include_participant_contexts=false&include_private_conversation_enrollments=false
- Specific mail
/courses/(class_id)/modules/items/assignment_info
- Module items
*/
/**
* log - logs info to console
* @param {*} str
* @param {...any} data
*/
const log = (str, ...data) => {
if (data.length > 0) {
console.log(`[CANVAS-ALL] ${str}`, data);
}
console.log(`[CANVAS-ALL] ${str}`);
};
/**
* load - Loads everything
*/
async function load() {
document.title = "Dashboard - All";
/**
* mainElement - the main application div
* iFrameLoader - The div for loading iframes for getting data
* styles - A style element
*/
const mainElement = document.getElementById("main"),
iFrameLoader = document.createElement("div");
mainElement.innerHTML = `<style>
#canvas-all-iframe-loader{
visibility: hidden;
position: fixed;
width: 100%;
height: 100%;
pointer-events: none;
left: 0;
}
#canvas-all-iframe-loader > iframe{
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
}
#main{
display: flex;
flex-flow: column;
padding: 1rem;
}
#main>span{
flex: 0;
margin-bottom: 1rem;
}
#main>div{
flex: 1;
}
#canvasall_main_wrapper{
display: flex;
}
#canvasall_main_wrapper>div{
flex: 75%;
}
#canvasall_class_grades{
display: flex;
flex-flow: column;
background: #fff5e0;
padding: 0.5rem;
border-radius: 0.5rem;
}
#canvasall_assignments_wrapper{
padding: 0.5rem;
background: #fff5e0;
border-radius: 0.5rem;
}
#canvasall_main_wrapper>#canvasall_announcement_wrapper{
flex: 25%;
padding: 0.5rem;
}
#canvasall_assignment_filter_list_chosen{
display: inline-block;
}
#canvasall_assignment_filter_list_chosen>option{
display: inline-block;
background: grey;
color: white;
padding: 0.25rem;
margin: 0.25rem;
cursor: pointer;
}
#canvasall_assignment_filter_list_chosen>option::before{
content: "x ";
}
.canvasall_announcement_wrapper{
margin-bottom: 0.5rem;
padding: 0.5rem;
border-radius: 0.5rem;
}
.canvasall_announcement_wrapper:nth-child(2n+1){
background: #fff5e0;
}
.canvasall_announcement_wrapper:nth-child(2n){
background: #ddd;
}
.canvasall_announcement_title{
font-size: 1.25rem;
font-weight: bold;
}
.canvasall_announcement_class,
.canvasall_announcement_when{
font-size: 0.75rem;
}
.canvasall_announcement_class>a{
color: grey;
}
.canvasall_class_grade_wrapper:nth-child(2n+1){
background: white;
}
.canvasall_class_grade_wrapper:nth-child(2n){
background: #eee;
}
.canvasall_class_grade_wrapper{
flex: 1;
display: flex;
border-radius: 0.5rem;
}
.canvasall_class_grade_wrapper>div{
flex: 1;
padding: 0.5rem;
word-break: break-all;
}
.canvasall_assignment_wrapper:nth-child(2n+1){
background: rgba(255,255,255,0.8);
}
.canvasall_assignment_wrapper:nth-child(2n){
background: rgba(255,255,255,0.4);
}
.canvasall_assignment_wrapper{
display: flex;
padding: 0.5rem;
border-radius: 0.5rem;
}
.canvasall_assignment_wrapper>div{
flex: 1;
padding-right: 0.25rem;
padding-left: 0.25rem;
}
.canvasall_assignment_title{
display: flex;
align-items: center;
}
.canvasall_assignment_title>img{
height: 1.5rem;
width: 1.5rem;
margin-right: 0.5rem;
}
.canvasall_assignment_icon {
min-height: 1.5rem;
min-width: 1.5rem;
margin-right: 0.5rem;
}
.canvasall_assignment_type_assignment:before {
content: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgeD0iMCIgeT0iMCIgdmlld0JveD0iMCAwIDI4MCAyNTkiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDI4MCAyNTkiIHhtbDpzcGFjZT0icHJlc2VydmUiPjxwYXRoIGQ9Ik03My4zMSwxOThjLTExLjkzLDAtMjIuMjIsOC0yNCwxOC43M2EyNi42NywyNi42NywwLDAsMC0uMywzLjYzdi4zYTIyLDIyLDAsMCwwLDUuNDQsMTQuNjUsMjIuNDcsMjIuNDcsMCwwLDAsMTcuMjIsOEgyMDBWMjI4LjE5aC0xMzRWMjEzLjA4SDIwMFYxOThabTIxLTEwNS43NGg5MC42NFY2Mkg5NC4zWk03OS4xOSwxMDcuMzRWNDYuOTJIMjAwdjYwLjQyWm03LjU1LDMwLjIxVjEyMi40NUgxOTIuNDl2MTUuMTFa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it,
.canvasall_status_submit a{
color: green;
}
.canvasall_status_done{
text-decoration: line-through;
}
.canvasall_status_late{
background: orange !important;
color: white;
}
.canvasall_status_late a{
color: white;
}
.canvasall_status_missing{
background: red !important;
color: white;
}
.canvasall_status_missing a{
color: white;
}
.canvasall_status_feedback>.canvasall_assignment_title::after{
content: " (Feedback available)"
}
</style>
<span id="canvasall_fetching_information">Fetching information... please wait...</span>
<div id="canvasall_main_wrapper">
<div>
<div id="canvasall_class_wrapper">
<!-- Courses, Grades, etc. -->
<h3>Courses</h3>
<div id="canvasall_class_grades">
<div id="canvasall_class_grade_header" class="canvasall_class_grade_wrapper">
<div><span>Class</span></div>
<div><span>Grade</span></div>
<div><span>Professor</span></div>
</div>
</div>
</div>
<h3>Current Assignments</h3>
<div>
<span>Filters:</span>
<select id="canvasall_assignment_filter_status">
<option value="">Select</option>
<option value="submit">Hide Submitted</option>
<option value="done">Hide Graded</option>
<option value="late">Hide Late</option>
<option value="missing">Hide Missing</option>
<option value="quiz">Hide Quiz</option>
<option value="assignment">Hide Assignment</option>
</select>
<div id="canvasall_assignment_filter_list_chosen">
</div>
</div>
<div id="canvasall_assignments_wrapper">
<div class="canvasall_assignment_wrapper">
<div>
<span>Assignment Name</span>
</div>
<div>
<span>Class</span>
</div>
<div>
<span>Due Date</span>
</div>
</div>
</div>
</div>
<div id="canvasall_announcement_wrapper">
<h3>Announcements</h3>
</div>
</div>`;
iFrameLoader.id = "canvas-all-iframe-loader";
mainElement.append(iFrameLoader);
/**
* courses - Class information
* classAssignments - Assignments for courses
* mainFrame - The main iframe
* ENV - Global variables with useful data
* currentUserID - The current user id
*/
log("Getting courses");
const courses = await getCourses(),
courseAssignments = [],
courseGrades = {},
{ ENV } = window,
{ currentUserID } = ENV,
courseGradeDiv = mainElement.querySelector("#canvasall_class_grades"),
assignmentsDiv = mainElement.querySelector("#canvasall_assignments_wrapper"),
announcementsDiv = mainElement.querySelector(
"#canvasall_announcement_wrapper"
),
statusFilter = mainElement.querySelector(
"#canvasall_assignment_filter_status"
),
statusFilterList = mainElement.querySelector(
"#canvasall_assignment_filter_list_chosen"
),
localStorageConfigStr = localStorage.canvasAllConfig ?? "{}",
localStorageConfig = JSON.parse(localStorageConfigStr);
function hideType(value) {
if (value === "") {
// ignore reset to empty value
return;
}
const elem = statusFilter.querySelector(
`option[value="${value}"]`
),
temp = document.createElement("template"),
now = `${Math.random()}`.substr(2);
if (!elem) {return;}
temp.innerHTML = `<style id="canvasall_filter_${now}">
.canvasall_status_${value}{
display: none;
}
</style>`;
document.body.append(temp.content.cloneNode(true));
statusFilterList.append(elem);
localStorageConfig[value] = true;
localStorage.canvasAllConfig = JSON.stringify(localStorageConfig);
statusFilter.value = "";
function click() {
localStorageConfig[value] = false;
localStorage.canvasAllConfig = JSON.stringify(localStorageConfig);
// remove style
statusFilter.append(elem);
document.querySelector(`#canvasall_filter_${now}`).remove();
statusFilter.value = "";
elem.removeEventListener("click", click);
}
elem.addEventListener("click", click);
}
// Filters
statusFilter.addEventListener("change", () => {
hideType(statusFilter.value);
});
// Begin writing class information
for (const [i, course] of Object.entries(courses)) {
const template = document.createElement("template");
template.innerHTML = `<div class="canvasall_class_grade_wrapper" canvasall-class-id="${
course.id
}">
<div class="canvasall_class_grade_name">
<span>${+i + 1}. <a href="/courses/${course.id}">${
course.name
}</a></span>
</div>
<div class="canvasall_class_grade_score">
<span>(Loading scores...)</span>
</div>
<div class="canvasall_class_grade_instructor">
<span>(Loading instructors...)</span>
</div>
</div>`;
courseGradeDiv.append(template.content.cloneNode(true));
}
log("Getting course assignments and grades");
let courseCount = 0,
finishedCollections = 0;
for (const course of courses) {
courseCount++;
getCourseAssignments(course.id, currentUserID).then(assignments => {
courseAssignments.push.apply(
courseAssignments,
assignments
);
finishedCollections++;
if (finishedCollections === courseCount) {
// Write assignments
courseAssignments.sort((a, b) => {
// sort by "due date"
// also places non-due-date at end. (+1 week)
const dueA = new Date(
a.plannable.due_at || b.plannable.created_at || Date.now() + 604800e3
),
dueB = new Date(
b.plannable.due_at || b.plannable.created_at || Date.now() + 604800e3
);
return dueA.getTime() - dueB.getTime();
});
log("Compiling assignments");
for (const assignment of courseAssignments) {
const template = document.createElement("template");
if (assignment.plannable_type === "announcement") {
// Put in announcement thing
template.innerHTML = `<div class="canvasall_announcement_wrapper">
<div class="canvasall_announcement_title">
<a href="${assignment.html_url}">${assignment.plannable.title}</a>
</div>
<div class="canvasall_announcement_class">
<a href="/courses/${assignment.course_id}">${
assignment.context_name
}</a>
</div>
<div class="canvasall_announcement_when">
<span>${new Date(assignment.plannable.created_at)
.toString()
.split(" ")
.slice(0, 5)
.join(" ")
.replace(/:\d{2}$/, "")
.replace(/\s(?=\w{3}\s\d{2})/, ", ")
.replace(/\d{4}/, "at")}</span>
</div>
</div>`;
announcementsDiv.append(template.content.cloneNode(true));
continue;
}
const divClasses = [],
{ submissions } = assignment;
if (submissions) {
const { excused, graded, has_feedback, late, missing, submitted } =
submissions;
if (excused || graded) {
divClasses.push("canvasall_status_done");
}
if (submitted) {
divClasses.push("canvasall_status_submit");
}
if (late) {
divClasses.push("canvasall_status_late");
}
if (missing) {
divClasses.push("canvasall_status_missing");
}
if (has_feedback) {
divClasses.push("canvasall_status_feedback");
}
}
divClasses.push("canvasall_status_" + assignment.plannable_type);
template.innerHTML = `<div class="canvasall_assignment_wrapper ${divClasses.join(
" "
)}" class-id="${assignment.course_id}">
<div class="canvasall_assignment_title">
<div class="canvasall_assignment_icon canvasall_assignment_type_${
assignment.plannable_type
}"></div>
<a href="${assignment.html_url}">${assignment.plannable.title}</a>
</div>
<div class="canvasall_assignment_class">
<a href="/courses/${assignment.course_id}">${
assignment.context_name
}</a>
</div>
<div class="canvasall_assignment_due">
<span>${
assignment.plannable.due_at
? new Date(assignment.plannable.due_at)
.toString()
.split(" ")
.slice(0, 5)
.join(" ")
.replace(/:\d{2}$/, "")
.replace(/\s(?=\w{3}\s\d{2})/, ", ")
.replace(/\d{4}/, "at")
: "No due date"
}</span>
</div>
</div>`;
assignmentsDiv.append(template.content.cloneNode(true));
}
// Restore hide
for (const [key, value] of Object.entries(localStorageConfig)) {
if (value && key !== "") {
hideType(key);
}
}
courseAssignments.splice(0); // Free up memory
document.querySelector("#canvasall_fetching_information").outerHTML = "";
}
});
// Get grades
loadFrame(iFrameLoader, `/courses/${course.id}/grades`).then(
(ClassGradeFrame) => {
const { document: d, window: w, frame } = ClassGradeFrame;
let overallGrade = d
.querySelector(
"#student-grades-right-content .student_assignment.final_grade > .grade"
)
?.textContent?.replace(/%|\s/g, ""),
titles = d.querySelectorAll(".title"),
possiblePoints = d.querySelectorAll(".points_possible"),
dueDates = d.querySelectorAll(".due");
courseGrades[course.id] = {
Grades: overallGrade + "%",
Titles: titles,
PossiblePoints: possiblePoints,
DueDates: dueDates,
};
// Write grades
const gradeDiv = courseGradeDiv.querySelector(
`[canvasall-class-id="${course.id}"] > .canvasall_class_grade_score`
),
{ ENV } = w,
{ grading_scheme } = ENV,
[Letter] =
grading_scheme.find((scheme) => {
try {
return +overallGrade / 100 >= scheme[1];
} catch (e) {
console.error(e);
}
}) || "?";
gradeDiv.innerHTML =
overallGrade !== "N/A"
? `<span>${Letter} (${overallGrade}%)</span>`
: `<span>N/A</span>`;
// Done using data from iframe, attempt to clean up memory usage
overallGrade = titles = possiblePoints = dueDates = null;
for (const i in courseGrades) {
delete courseGrades[i];
}
w.location = "about:blank";
setTimeout(() => {
frame.remove();
}, 500);
}
);
// Get instructors
getCourseTeacher(course.id)
.then((teacher) => {
const teacherDiv = courseGradeDiv.querySelector(
`[canvasall-class-id="${course.id}"] > .canvasall_class_grade_instructor`
);
teacherDiv.innerHTML = `<span>${teacher.name}</span>`;
})
.catch(() => {
// no teacher, or failed to get teacher
const teacherDiv = courseGradeDiv.querySelector(
`[canvasall-class-id="${course.id}"] > .canvasall_class_grade_instructor`
);
teacherDiv.innerHTML = "<span>No instructor found.</span>";
});
}
}
// /api/v1/users/:user_id/communication_channels
/**
* getCourses - Gets all the classes of the user
*
* @returns {Promise<Array>} A list of class information
*/
function getCourses() {
return new Promise((res, rej) => {
const x = new XMLHttpRequest();
x.open(
"GET",
"/api/v1/users/self/favorites/courses?include[]=term&exclude[]=enrollments&sort=nickname"
);
x.setRequestHeader("X-Requested-With", "XMLHttpRequest");
x.setRequestHeader(
"accept",
"application/json, text/javascript, application/json+canvas-string-ids, */*; q=0.01"
);
x.onload = () => {
res(JSON.parse(x.responseText));
};
x.onerror = () => {
rej();
};
x.send();
});
}
/**
* GetClassAssignments - Gets the class assignments
*
* @param {String} courseID The class id
* @param {String} userID The user id
* @returns {Promise<Array>} The list of assignments
*/
function getCourseAssignments(courseID, userID) {
const x = new XMLHttpRequest(),
now = new Date(),
offset = now.getTimezoneOffset() / 60,
nextUrlRegex = /[^<>]*(?=>; rel="next")/;
now.addDays(-14); // To get assignments from 2 weeks ago
now.setHours(8 - offset);
now.setMinutes(0);
now.setSeconds(0);
now.setMilliseconds(0);
function makeHttpRequest(url) {
return new Promise((res, rej) => {
x.open("GET", url);
x.setRequestHeader("X-Requested-With", "XMLHttpRequest");
x.setRequestHeader(
"accept",
"application/json+canvas-string-ids, application/json+canvas-string-ids, application/json, text/plain, */*"
);
x.onerror = () => {rej();}
x.onload = () => {
res(x);
}
x.send();
});
}
async function gatherRecursiveRequests(url, list = []) {
const response = await makeHttpRequest(url),
data = JSON.parse(response.responseText),
linkHeader = response.getResponseHeader("link");
list.push(...data);
if (linkHeader) {
const lastLink = linkHeader.match(nextUrlRegex);
if (lastLink) {
return gatherRecursiveRequests(lastLink[0], list);
} else {
return list;
}
} else {
return list;
}
}
return gatherRecursiveRequests(`/api/v1/planner/items?start_date=${now.toISOString()}&order=asc&context_codes[]=course_${courseID}`) //&context_codes[]=user_${userID}
.catch(() => []);
}
/**
* getCourseTeacher - Gets the teacher of the course
*
* @param {String} courseID The class id
* @returns {Object} The teacher
*/
function getCourseTeacher(courseID) {
return new Promise((res, rej) => {
const x = new XMLHttpRequest();
x.open(
"GET",
`/api/v1/search/recipients?search=&per_page=20&permissions[]=send_messages_all&messageable_only=true&synthetic_contexts=true&context=course_${courseID}_teachers`
);
x.setRequestHeader("X-Requested-With", "XMLHttpRequest");
x.setRequestHeader(
"Accept",
"application/json, text/javascript, application/json+canvas-string-ids, */*; q=0.01"
);
x.onload = () => {
res(JSON.parse(x.responseText)[0]);
};
x.onerror = () => {
rej();
};
x.send();
});
}
/**
* loadFrame - Loads an iframe
*
* @param {HTMLElement} iFrameLoader The element to append iframes to
* @param {String} src The iframe url to load
* @returns {Promise<Object>} returns an object with the "window" and "document" of the iframe
*/
function loadFrame(iFrameLoader, src) {
return new Promise((res) => {
const mainFrame = document.createElement("iframe");
mainFrame.src = src || "/";
iFrameLoader.append(mainFrame);
mainFrame.addEventListener("load", () => {
const frameContext = {
document: mainFrame.contentDocument,
window: mainFrame.contentWindow,
frame: mainFrame
};
res(frameContext);
});
});
}
load();
/*end original, start improvements
thanks to melvas on Stack Overflow for this improvement (change title to "Dashboard")*/
var x=document.getElementsByClassName("mobile-header-title"); // Find the elements
for(var i = 0; i < x.length; i++){
x[i].innerText="Dashboard"; // Change the content
}
/* thanks to Paul Bui on Greasyfork (buttons on top)*/
'use strict';
//YOU SHOULD MODIFY THE FOLLOWING LIST OF COURSE NAMES AND COURSE ID NUMBERS!
//"COURSE_NAME" : COURSE_ID # that is found in the URL after the word "courses"
//A comma should be at the end of the line unless it's the last entry
var courseNumDict = {
"Drawing" : 43165,
"Argumentation" : 42953
//You can add more courses...
};
//DO NOT MODIFY ANYTHING BELOW THIS COMMENT
if (document.location.href.indexOf("speed_grader") != -1
|| document.body.classList.contains("quizzes-speedgrader")
|| document.body.classList.contains("is-inside-submission-frame"))
{
return;
}
var wrapper = document.getElementById("wrapper");
if (wrapper)
{
var newDiv = document.createElement("div");
newDiv.setAttribute("style", "margin-left: 24px");
for (let courseStr in courseNumDict)
{
var newA = document.createElement("a");
newA.innerHTML = courseStr;
newA.setAttribute("class", "btn btn-primary class_button");
newA.setAttribute("style", "margin-right: 4px");
newA.href = "javascript:void(0)";
newA.onclick = function() {
const regex = /(.*\/courses\/)\d+(.*)/;
const URL = document.location.href;
const newURL = URL.replace(regex, "$1"+courseNumDict[courseStr]+"$2");
window.location.href = newURL;
};
newDiv.append(newA);
}
wrapper.insertAdjacentElement('afterbegin', newDiv);
}