-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcontent.js
executable file
·208 lines (191 loc) · 9.69 KB
/
content.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
function chrome_() {
try {
chrome !== undefined && browser !== undefined;
return browser;
} catch (e) {
console.log(e.message);
return chrome;
}
}
chrome_().storage.local.set({ VTOP_URI: window.location.origin }, function () {
console.log("SET THE URL");
});
document.addEventListener("DOMContentLoaded", change_navbar);
function change_navbar() {
try {
// var nodes =
// document.getElementsByClassName("btn-group-vertical")[0].children;
// for (var i = 1; i < nodes.length; i++) {
// nodes[i].setAttribute("style", "transition-delay: 10s");
// }
var coursePage = document.createElement("div");
coursePage.className = "btn-group dropend";
coursePage.style = style =
"margin-top: 12px; background-color: red; padding: 3px";
coursePage.innerHTML = `
<button
type="button"
class="btn btn-outline-primary p-1 border-0 text-dark SideBarMenuBtn"
data-bs-toggle="dropdown"
data-bs-auto-close="outside"
aria-expanded="false"
>
<i style="background-color: red"
class="fa fa-star"></i>
</button>
<div
class="dropdown-menu border-0 py-0 shadow-lg dropdownMenuBoxWidth text-nowrap SideBarMenuDropDown"
>
<a onclick='document.querySelector("#sidePanel > div > div > div:nth-child(6) > div > a:nth-child(16)").click()'
data-url="examinations/StudentDA" class="dropdown-item menuFontStyle systemBtnMenu " href="javascript:void(0);"> <i class="fa fa-dot-circle-o iconSpace "></i> Digital Assignment Upload</a>
<a onclick='document.querySelector("#sidePanel > div > div > div:nth-child(6) > div > a:nth-child(13)").click()'
data-url="academics/common/StudentCoursePage" class="dropdown-item menuFontStyle systemBtnMenu " href="javascript:void(0);"> <i class="fa fa-dot-circle-o iconSpace "></i> Course Page</a>
<a onclick= 'document.querySelector("#sidePanel > div > div > div:nth-child(6) > div > a:nth-child(5)").click()'
data-url="academics/common/StudentClassMessage" class="dropdown-item menuFontStyle systemBtnMenu " href="javascript:void(0);"> <i class="fa fa-dot-circle-o iconSpace "></i> Class Messages</a>
<a onclick='document.querySelector("#sidePanel > div > div > div:nth-child(6) > div > a:nth-child(12)").click()'
data-url="academics/common/StudentAttendance" class="dropdown-item menuFontStyle systemBtnMenu " href="javascript:void(0);"> <i class="fa fa-dot-circle-o iconSpace "></i> Class Attendance</a>
<a onclick='document.querySelector("#sidePanel > div > div > div:nth-child(5) > div > a:nth-child(2)").click()'
data-url="proctor/viewProctorDetails" class="dropdown-item menuFontStyle systemBtnMenu " href="javascript:void(0);"> <i class="fa fa-dot-circle-o iconSpace "></i> Proctor Details</a>
<a onclick='document.querySelector("#sidePanel > div > div > div:nth-child(6) > div > a:nth-child(9)").click()'
data-url="academics/common/StudentTimeTable" class="dropdown-item menuFontStyle systemBtnMenu " href="javascript:void(0);"> <i class="fa fa-dot-circle-o iconSpace "></i> Time Table</a>
<a onclick='document.querySelector("#sidePanel > div > div > div:nth-child(8) > div > a:nth-child(3)").click()'
data-url="examinations/StudentMarkView" class="dropdown-item menuFontStyle systemBtnMenu " href="javascript:void(0);"> <i class="fa fa-dot-circle-o iconSpace "></i> Marks</a>
</div>
`;
var dropdown = document.getElementsByClassName("btn-group-vertical");
dropdown[0].insertBefore(coursePage, dropdown[0].children[0]);
} catch (err) {}
}
function find_right_due(table_inner) {
return new Promise((resolve) => {
const dueDates = [];
for (let i = 0; i < table_inner.children.length; i++) {
var check = table_inner.children[i].children[6].children[0].innerHTML;
if (check === "") {
var dwnld = table_inner.children[i].children[5].children.length;
dueDates.push({
due: table_inner.children[i].children[4].children[0].innerHTML,
download:
dwnld > 0
? table_inner.children[i].children[5].children[0].children[0]
: document.createElement("div"),
});
}
}
if (dueDates.length > 0) {
dueDates.sort((a, b) => {
return new Date(a.due).getTime() < new Date(b.due).getTime();
});
resolve(dueDates[0]);
}
resolve({
due: "Nothing Left. Cheers!",
download: document.createElement("div"),
});
});
}
async function assignments() {
try {
var regNo = document.getElementById("authorizedIDX").value;
var table = document.getElementsByClassName("customTable")[0].children[0];
var now_ = new Date().getTime();
var dis = document.getElementsByClassName("icon-button");
var scripts = document.getElementsByTagName("noscript");
var csrf = scripts[0].nextElementSibling.textContent.split('"')[3];
for (let i = 0; i < dis.length; i++) {
dis[i].disabled = true;
}
for (let i = 1; i < table.children.length; i++) {
var classid = table.children[i].children[1].innerHTML;
if (table.children[i].children[3].children.length != 1) {
await fetch(
`${window.location.origin}/vtop/examinations/processDigitalAssignment`,
{
method: "POST",
headers: {
"Content-Type":
"application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
},
body: `authorizedID=${regNo}&x=${new Date().toGMTString()}&classId=${classid}&_csrf=${csrf}`,
}
)
.then((res) => res.text())
.then(async (data) => {
var parser = new DOMParser();
var doc = parser.parseFromString(data, "text/html");
var table_inner =
doc.getElementsByClassName("customTable")[1].children[1];
var due_date = await find_right_due(table_inner).then(
(data) => data
);
var due = new Date(due_date.due.replace(/-/g, " ")).getTime();
var color =
(due - now_) / (3600 * 24 * 1000) <= 2 ? "red" : "green";
table.children[
i
].children[3].innerHTML += `<span style="display:inline; float:right; color:${color};">${due_date.due}</span>`;
table.children[i].children[3].children[0].appendChild(
due_date.download
);
})
.catch((err) => console.log(err));
}
}
for (let i = 0; i < dis.length; i++) {
dis[i].disabled = false;
}
} catch (err) {
console.log(err);
}
}
function sendingResponse() {
return new Promise((resolve) => {
resolve(document.documentElement);
});
}
// Message passing between background and content
// This removes the need for clicking in body to see due dates as it checks URL requests to find whether user has visited DA page.
var loaded = false;
chrome_().runtime.onMessage.addListener(function (
request,
sender,
sendResponse
) {
if (request.urlVisited && !loaded) {
loaded = true;
chrome_().storage.local.get(["pause"], function (data) {
if (!data.pause) {
assignments();
}
});
chrome_().storage.local.get(["token"], function (data) {
var head = document.getElementsByClassName("box-header with-border")[0];
if (!data.token) {
var text = document.createElement("p");
text.innerHTML =
"Sign in to Google via Extension to sync your assign with your Google Calendar.";
head.appendChild(text);
} else {
var btn = document.createElement("button");
btn.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" data-name="Layer 1" viewBox="0 0 141.7 141.7" width="24" height="24"><path fill="#fff" d="M95.8,45.9H45.9V95.8H95.8Z"/><path fill="#34a853" d="M95.8,95.8H45.9v22.5H95.8Z"/><path fill="#4285f4" d="M95.8,23.4H30.9a7.55462,7.55462,0,0,0-7.5,7.5V95.8H45.9V45.9H95.8Z"/><path fill="#188038" d="M23.4,95.8v15a7.55462,7.55462,0,0,0,7.5,7.5h15V95.8Z"/><path fill="#fbbc04" d="M118.3,45.9H95.8V95.8h22.5Z"/><path fill="#1967d2" d="M118.3,45.9v-15a7.55462,7.55462,0,0,0-7.5-7.5h-15V45.9Z"/><path fill="#ea4335" d="M95.8,118.3l22.5-22.5H95.8Z"/><polygon fill="#2a83f8" points="77.916 66.381 75.53 63.003 84.021 56.868 87.243 56.868 87.243 85.747 82.626 85.747 82.626 62.772 77.916 66.381"/><path fill="#2a83f8" d="M67.29834,70.55785A7.88946,7.88946,0,0,0,70.78,64.12535c0-4.49-4-8.12-8.94-8.12a8.77525,8.77525,0,0,0-8.74548,6.45379l3.96252,1.58258a4.41779,4.41779,0,0,1,4.473-3.51635,4.138,4.138,0,1,1,.06256,8.24426v.00513h-.0559l-.00666.00061-.00964-.00061H59.15v3.87677h2.70642L61.88,72.65a4.70514,4.70514,0,1,1,0,9.37,5.35782,5.35782,0,0,1-3.96588-1.69354,4.59717,4.59717,0,0,1-.80408-1.2442l-.69757-1.69946L52.23005,79c.62,4.33,4.69,7.68,9.61,7.68,5.36,0,9.7-3.96,9.7-8.83A8.63346,8.63346,0,0,0,67.29834,70.55785Z"/></svg><span>Sync assignments with Google Calendar</span>`;
btn.style = `display: flex;align-items: center;gap: 1rem;font-family: inherit;justify-content: space-around;color: #535353;font-size: 13px;font-weight: 500;margin: 8px auto;cursor: pointer;background-color: white;border-radius: 32px;transition: all 0.2s ease-in-out;padding: 6px 10px;border: 1px solid rgba(0, 0, 0, 0.25);`;
head.appendChild(btn);
btn.addEventListener("click", function () {
var DOM = document.body.outerHTML;
chrome_().runtime.sendMessage(
{
message: "sync",
DOM,
},
function () {
console.log("Syncing");
}
);
});
}
});
}
return true;
});