-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
134 lines (123 loc) · 5.6 KB
/
index.html
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
<html>
<head>
<link rel="stylesheet"
href="https://du11hjcvx0uqb.cloudfront.net/dist/brandable_css/289606ed00d3518a0ed0dc2afd44d6f0/new_styles_normal_contrast/bundles/common-bc0cf2950d.css"/>
<link rel="stylesheet"
href="https://du11hjcvx0uqb.cloudfront.net/dist/brandable_css/289606ed00d3518a0ed0dc2afd44d6f0/new_styles_normal_contrast/bundles/dashboard-c42271f6c4.css"/>
<link rel="stylesheet"
href="https://du11hjcvx0uqb.cloudfront.net/dist/brandable_css/289606ed00d3518a0ed0dc2afd44d6f0/new_styles_normal_contrast/bundles/dashboard_card-ef8fe1913e.css"/>
<link rel="stylesheet"
href="https://instructure-uploads.s3.amazonaws.com/account_190000000088968/attachments/71158649/new_ui_override.css?AWSAccessKeyId=AKIAJFNFXH2V2O7RPCAA&Expires=1945583226&Signature=CWzLFjL0BA2oRCgkWNfKoQSeVJ8%3D&response-cache-control=Cache-Control%3Amax-age%3D473364000.0%2C%20public&response-expires=473364000.0"/>
<link rel="stylesheet"
href="https://du11hjcvx0uqb.cloudfront.net/dist/brandable_css/289606ed00d3518a0ed0dc2afd44d6f0/new_styles_normal_contrast/bundles/common-bc0cf2950d.css"/>
<link rel="stylesheet"
href="https://du11hjcvx0uqb.cloudfront.net/dist/brandable_css/no_variables/jst/tinymce/InsertUpdateImageView-576a8e7d68.css"/>
<link rel="stylesheet"
href="https://du11hjcvx0uqb.cloudfront.net/dist/brandable_css/289606ed00d3518a0ed0dc2afd44d6f0/new_styles_normal_contrast/jst/TreeBrowser-4d31810d2d.css"/>
<link rel="stylesheet"
href="https://du11hjcvx0uqb.cloudfront.net/dist/brandable_css/289606ed00d3518a0ed0dc2afd44d6f0/new_styles_normal_contrast/jst/FindFlickrImageView-3605dd74b1.css"/>
<link rel="stylesheet" href="InstructureIcons-Line.css"/>
<style>
body, #body, #right-side {
min-width: 200px;
position: absolute;
margin-right: 0px;
padding-right: 0px;
width: 98%;
}
</style>
</head>
<body style="min-width: 200px !important;">
<div id="body" style="margin: .5em; visible: hidden;">
<h1>Please Read!</h1>
<h2>First time setup</h2>
<p>We need to know how your school talks to Canvas.</p>
<p>We also need your permission to talk to Canvas.</p>
<p>On the next page please check 'Stay signed in'!</p>
<p>After you see your grades start to load<br> please close and reopen this window.</p>
<h3 style="margin-top: 3em;">Please enter your school's Canvas url:</h3>
<p><i>TCNJ's is provided as an example...</i></p>
<form>
<input id="url" type="text" value="tcnj.instructure.com">
<br>
<button id="login-submit">Submit</button>
</form>
<br>
<h4 style="visibility: hidden;" id="loading">Thanks, loading Canvas...</h4>
</div>
</body>
<script>
let body = document.getElementById('body')
body.style.visibility = 'hidden'
let shell = require('electron').shell
const openExternal = (url) => {
shell.openExternal(url)
}
let ipc = require('electron').ipcRenderer
let baseUrl = ''
const loadCanvas = (url) => {
let xhr = new XMLHttpRequest()
xhr.open('GET', url, true)
xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 400) {
body.innerHTML = getDOM(xhr.response)
body.style.visibility = 'visible'
appendGrades()
}
}
xhr.send()
}
const appendGrades = () => {
let xhr = new XMLHttpRequest()
xhr.open('GET', baseUrl + 'grades', true)
xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 400) {
let bottom = document.getElementsByClassName('button-sidebar-wide')[0]
let gradesHtml = xhr.response.split('<table class="course_details student_grades">')[1].split('</table>')[0].split('<tr>')
let total = ''
const end = '</strong></p></div><div class="clear"></div></a><div class="clear"></div></li>'
const start = '<li style="margin-top: .75em;" class="event"><div class="event-details"><p>'
for (let i = 1; i < gradesHtml.length; i++) {
total += (start + gradesHtml[i].split('<td class="course">')[1].split('</td>')[0].trim() + '</p><p><strong>' + gradesHtml[i].split('<td class="percent">')[1].split('</td>')[0].trim() + end)
}
bottom.outerHTML = wrapGrades(total)
fixLinks()
}
}
xhr.send()
}
document.getElementById('login-submit').addEventListener('click', (e) => {
e.preventDefault()
const school = document.getElementById('url').value
const toLoad = 'https://' + school.trim() + '/dashboard-sidebar'
baseUrl = 'https://' + school.trim() + '/'
document.getElementById('loading').style.visibility = 'visible'
ipc.send('schoolUrl', toLoad)
window.location.href = baseUrl + '/grades'
})
if (window.location.href.split('#')[1] !== '') {
baseUrl = window.location.href.split('#')[1].split('dashboard-sidebar')[0]
loadCanvas(window.location.href.split('#')[1])
} else {
body.style.visibility = 'visible'
}
const getDOM = (content) => {
return '<div id="right-side" role="complementary" style="opacity: 1; display: block;">' + content + '</div>'
}
const fixLinks = () => {
let links = document.getElementsByTagName('a')
for (let i = 0; i < links.length; i++) {
links[i].addEventListener('click', (e) => {
e.preventDefault()
openExternal(baseUrl + e.target.href.split('file://')[1]);
})
links[i].href = '#'
}
}
const wrapGrades = (grades) => {
const first = '<div class="events_list recent_feedback"><h2>Grades</h2><ul class="right-side-list events">'
const last = '</ul></div>'
return (first + grades + last)
}
</script>
</html>