-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
180 lines (151 loc) · 5.61 KB
/
app.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
// console.clear();
credits();
/*--------------------------------------------------------------
TABLE OF CONTENTS
----------------------------------------------------------------
1.0 SET-UP
1.1 FADERS
1.2 DROPDOWNS
2.0 PAPERSSS
2.1 DOM ELEMENTS
2.2 VARIABLES
2.3 FUNCTIONS
2.4 EVENT LISTENERS
--------------------------------------------------------------*/
/*--------------------------------------------------------------
1.0 SET-UP
--------------------------------------------------------------*/
/*------------------------------------------------------------
|
| 1.1 FADERS
|
------------------------------------------------------------*/
const headerText = document.querySelector('.header-text');
const headerDescription = document.querySelector('.header-description');
const headerArrow = document.querySelector('.arrow');
const form = document.querySelector('.form');
fadeIn(headerText, 200);
fadeIn(headerDescription, 800);
fadeIn(form, 200);
if (window.innerWidth < 1000) {
fadeIn(headerArrow, 1000);
}
/*------------------------------------------------------------
|
| 1.2 DROPDOWNS
|
------------------------------------------------------------*/
const dropdowns = document.querySelectorAll('.dropdown');
dropdowns.forEach((dropdown) => {
const options = dropdown.querySelectorAll('span');
options.forEach((options) => {
options.addEventListener('click', updateDropdown);
})
})
dropdowns.forEach((dropdown) => {
const input = dropdown.querySelector('input')
input.addEventListener('focus', () => {
input.nextElementSibling.classList.add('show');
})
input.addEventListener('blur', async () => {
await sleep(200);
input.nextElementSibling.classList.remove('show');
})
})
function updateDropdown() {
let dropdownInput = this.parentElement.previousElementSibling;
dropdownInput.value = this.textContent;
this.parentElement.classList.remove('show');
}
function filterFunction() {
let input = event.target;
let content = input.nextElementSibling;
let a = content.querySelectorAll("a");
let filter = input.value.toUpperCase();
for (i = 0; i < a.length; i++) {
txtValue = a[i].textContent || a[i].innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
a[i].style.display = "";
} else {
a[i].style.display = "none";
}
}
}
/*--------------------------------------------------------------
2.0 PAPERSSS
--------------------------------------------------------------*/
/*------------------------------------------------------------
|
| 2.1 DOM ELEMENTS
|
------------------------------------------------------------*/
const searchButton = document.querySelector('#search-button');
const typeInput = document.querySelector('.type.switch input');
const tierInput = document.querySelector('.tier.switch input');
const typeSwitch = document.querySelector('.type.switch');
const tierSwitch = document.querySelector('.tier.switch');
const switches = [[typeSwitch, typeInput], [tierSwitch, tierInput]];
/*------------------------------------------------------------
|
| 2.2 VARIABLES
|
------------------------------------------------------------*/
const script = `s=document.createElement('script');s.src='https://cdn.jsdelivr.net/gh/alexlostorto/magic-notes@v3.0.0/console/inject.js';document.head.appendChild(s);`;
const HTML = "<body style='height: 100%; width: 100%; overflow: hidden; margin:0px; background-color: rgb(82, 86, 89);'><embed name='ABB25BBED00233C3197B40436C445BE3' style='position:absolute; left: 0; top: 0;'width='100%' height='100%' src='about:blank' type='application/pdf' internalid='ABB25BBED00233C3197B40436C445BE3'></body>";
let FILE = {
'year': '2019',
'month': 'november',
'paper': '3',
'tier': 'H',
'type': 'W-MS'
}
/*------------------------------------------------------------
|
| 2.3 FUNCTIONS
|
------------------------------------------------------------*/
function getFileData() {
FILE.year = document.querySelector('#year').value;
FILE.month = document.querySelector('#month').value.toLowerCase();
FILE.paper = document.querySelector('#paper').value;
if (typeInput.checked) {
FILE.type = 'W-MS';
} else {
FILE.type = 'QP';
}
if (tierInput.checked) {
FILE.tier = 'F';
} else {
FILE.tier = 'H';
}
}
function getSource() {
let URL = `https://filestore.aqa.org.uk/sample-papers-and-mark-schemes/${FILE.year}/${FILE.month}/AQA-8300${FILE.paper}${FILE.tier.toUpperCase()}-${FILE.type}-${FILE.month.substring(0, 3).toUpperCase()}${FILE.year.substring(2, 4)}.PDF`;
return URL;
}
function loadPDF() {
getFileData();
let url = getSource();
document.querySelector('body').innerHTML = HTML;
document.querySelector('embed').src = url;
}
/*------------------------------------------------------------
|
| 2.4 EVENT LISTENERS
|
------------------------------------------------------------*/
searchButton.addEventListener('click', loadPDF);
switches.forEach((element) => {
element[0].addEventListener('change', () => {
const labels = element[0].querySelectorAll('span');
console.log(element)
console.log(labels);
if (element[1].checked) {
labels[2].classList.add('active');
labels[0].classList.remove('active');
} else {
labels[0].classList.add('active');
labels[2].classList.remove('active');
}
})
})