-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.user.js
118 lines (98 loc) · 4.16 KB
/
script.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
// ==UserScript==
// @name Class Information Selector
// @namespace http://tampermonkey.net/
// @version 0.9
// @description Download the class timetable
// @author [email protected]
// @match https://fap.fpt.edu.vn/*
// ==/UserScript==
(function () {
'use strict';
function getSelectedIndex() {
var classSelect = document.getElementById('ctl00_mainContent_dllCourse');
return classSelect.selectedIndex;
}
function setSelectedIndex(index) {
var classSelect = document.getElementById('ctl00_mainContent_dllCourse');
classSelect.selectedIndex = index;
classSelect.dispatchEvent(new Event('change'));
}
function downloadTextContent(className) {
var textContent = document.getElementById('ctl00_mainContent_lblNewSlot').innerHTML;
var parser = new DOMParser();
var doc = parser.parseFromString(textContent, 'text/html');
var lines = doc.body.textContent.split(',');
var output = '"' + className + '",';
for (var i = 0; i < lines.length; i++) {
var line = lines[i].trim();
var parts = line.split(':');
if (parts.length < 3) continue;
var day = parts[0].trim();
var slot = doc.getElementsByTagName('b')[i*3].textContent.trim();
var dayNumber;
switch (day) {
case 'Mon': dayNumber = 'Mon'; break;
case 'Tue': dayNumber = 'Tue'; break;
case 'Wed': dayNumber = 'Wed'; break;
case 'Thu': dayNumber = 'Thu'; break;
case 'Fri': dayNumber = 'Fri'; break;
case 'Sat': dayNumber = 'Mon'; break;
default: continue;
}
output += '"' + dayNumber + slot + '",';
}
var allClassesContent = localStorage.getItem('allClassesContent') || '';
allClassesContent += output.slice(0, -1) + '\n'; // Remove the last comma and add a newline
localStorage.setItem('allClassesContent', allClassesContent);
}
function downloadAllClasses() {
var allClassesContent = localStorage.getItem('allClassesContent') || '';
const blob = new Blob([allClassesContent], { type: 'text/csv' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = 'AllClasses.csv';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
var customButton = document.createElement('button');
customButton.innerHTML = 'Download All Classes';
customButton.style.position = 'fixed';
customButton.style.top = '10px';
customButton.style.left = '10px';
customButton.addEventListener('click', function () {
localStorage.setItem('scriptRunning', 'true');
setSelectedIndex(0);
});
document.body.appendChild(customButton);
var scriptRunning = localStorage.getItem('scriptRunning');
if (scriptRunning === 'true') {
var classSelect = document.getElementById('ctl00_mainContent_dllCourse');
var currentIndex = getSelectedIndex();
var className = classSelect.options[currentIndex].text;
downloadTextContent(className);
var nextIndex = (currentIndex + 1) % classSelect.options.length;
if (nextIndex !== 0) {
setSelectedIndex(nextIndex);
} else {
downloadAllClasses();
localStorage.removeItem('scriptRunning');
localStorage.removeItem('allClassesContent');
}
}
})();
var btn = document.createElement("button");
btn.innerHTML = "Feedback";
btn.style.position = 'fixed';
btn.style.top = '10px';
btn.style.left = '170px';
document.body.appendChild(btn);
btn.addEventListener("click", function() {
var radios = document.querySelectorAll('input[type="radio"]');
for (var i = 0; i < radios.length; i++) {
if (radios[i].value == "3") {
radios[i].checked = true;
}
}
document.getElementById("ctl00_mainContent_btSendFeedback").click();
});