-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathresources.html
68 lines (66 loc) · 2.5 KB
/
resources.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
---
layout: default
title: Resources
permalink: /resources/
description: Browse through the resources our members have curated<br>for various modules offered by NUS Electrical Engineering department.
---
<!-- Add new section here -->
<!-- Find past year paper solutions by module code.
Solution files to be added under (new) folder "past year papers/~ MOD CODE (in caps)~"
E.g. past year papers/CS1010E/CS1010E AY1920 S2.pdf
Please do not create empty folders.-->
<section class="wrapper style5" id="searchPYP">
<div class="inner">
<h2>ECE Past Year Papers</h2>
<p>We are updating our database. Do look out for it in the near future!</p>
<input id="pyp_form" onkeydown="if (event.keyCode == 13) find_pyp()" type="text" name="modCode" placeholder="Enter module code" value="" style="margin: 0 0 0.5em; width: 85%; display:inline-block">
<button onclick="find_pyp()">Search</button>
<div id="pyp_list"></div>
<!-- <a href="past year papers/CS1010E"></a> -->
<script>
var user_input = document.getElementById("pyp_form");
var pyp_list = document.getElementById("pyp_list");
function find_pyp() {
var insertHTML = "";
var modCode = user_input.value;
if (modCode != "") {
modCode = modCode.toUpperCase();
var dir = "past year papers/" + modCode;
var xhttp = new XMLHttpRequest;
xhttp.open('GET', dir);
xhttp.send();
xhttp.onload = function() {
if (xhttp.status == 404) {
insertHTML += "<br>Past year papers not found for " + modCode + ".";
} else {
var txt = xhttp.responseText;
var lines = txt.split('\n');
for (i = 0;i < lines.length;i++) {
if (lines[i].includes('<a href=') && lines[i].includes('.pdf')) {
if (insertHTML == "") insertHTML += "<br><ul>";
// console.log(lines[i]);
var regExp = /\a href="[^"]*\.pdf/g;
var match = lines[i].match(regExp)[0].slice(8);
// console.log(match);
var filename = match;
if (match.includes('past%20year%20papers')) {
filename = match.split("/");
filename = filename[filename.length-1];
}
filename = filename.replace(/%20/g," ");
// console.log(filename);
insertHTML += "<li><a href='"+dir+"/"+filename+"'>"+filename+"</a></li>";
}
}
insertHTML += "</ul>"
}
pyp_list.innerHTML = insertHTML;
}
} else {
insertHTML += "<br>Please enter a module code."
pyp_list.innerHTML = insertHTML;
}
}
</script>
</div>
</section>