-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
92 lines (71 loc) · 2.46 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
<html>
<head>
<title>Schedule.</title>
<style>
html
{
white-space: pre;
}
</style>
<body>
<script>
function httpPostAsync(theUrl, callback, postContent) // thanks https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send#Example_POST
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("POST", theUrl, true); // true for asynchronous
xmlHttp.send( postContent );
}
function httpGetAsync(theUrl, callback) // thanks https://stackoverflow.com/a/4033310
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
var urlSearchParams = ( new URL( document.location ) ).searchParams;
var urlCourses = urlSearchParams.get( "classes" );
var urlTerm = urlSearchParams.get( "term" );
var srcdb = 2191; // TODO DO SOMETHING TO GET THIS VIA urlTerm !
// console.log( urlCourses )
var courseSections = {};
for( var course of urlCourses.split( "," ) )
{
var codesection = course.split( "-" );
if( !( codesection[0] in courseSections ) ) courseSections[ codesection[0] ] = [];
courseSections[ codesection[0] ].push( codesection[1] );
}
var dbSearchResults = {};
if( d=sessionStorage.getItem( "dbSearch" + srcdb ) )
{
dbSearchResults = JSON.parse( d );
console.log( "(loaded dbSearchResults from sessionStorage)" );
hasDbSearchResults();
}
else
httpPostAsync( "https://cors-anywhere.herokuapp.com/https://classes.colorado.edu/api/?page=fose&route=search", function( data )
{
data = JSON.parse( data );
dbSearchResults = data;
sessionStorage.setItem( "dbSearch" + srcdb, JSON.stringify( data ) );
hasDbSearchResults();
},
`{"other":{"srcdb":"${srcdb}"},"criteria":[]}` ); // collect entire db search results in one query, maybe faster even though bigger payload. also allows to add courses after initial load
function hasDbSearchResults()
{
console.log( "check sessionStorage for the course database search results" );
console.log( "dbSearchResults", dbSearchResults );
for( var res of dbSearchResults.results )
{
var codeOn = res.code.replace( " ", "" ).toLowerCase();
if( codeOn in courseSections && courseSections[ codeOn ].includes( res.no ) )
document.body.innerHTML += "\n\n" + JSON.stringify( res, null, 2 );
}
}
</script>