Skip to content

Commit 8a6579a

Browse files
committed
ans key whitespace removed and added toast
1 parent 52e5220 commit 8a6579a

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

content.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ let inter = null;
44

55
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
66
if (request.message === "start") {
7+
if (Object.keys(request.answer_key).length === 0) {
8+
toast("Please enter the answer key", "error");
9+
return;
10+
}
11+
712
attempt(request.answer_key, request.time);
813
} else if (request.message === "stop") {
914
stopAttempt();
@@ -15,12 +20,14 @@ const attempt = (ans_key, time) => {
1520
const len = ans.length;
1621
let i = 0;
1722

23+
toast("Started attempting the test");
1824
function attemptQuestion() {
1925
document.querySelector(`#${ans[i]}_${i + 1}`).click();
2026
document.querySelector("#main_div > div.tableWidthPercent > div.onlineTestLeftDiv > div.qnav > span.saveNextButton > a").click();
2127
i++;
2228

2329
if (i === len) {
30+
toast("Finished attempting the test");
2431
clearInterval(inter);
2532
document.querySelector('#activator').click();
2633
document.querySelector('input[name="rd"][value="Y"]').click();
@@ -36,6 +43,30 @@ const attempt = (ans_key, time) => {
3643
function stopAttempt() {
3744
if (inter) {
3845
clearInterval(inter);
39-
console.log("Stopped the attempt");
46+
toast("Stopped attempting the test");
4047
}
48+
}
49+
50+
function toast(message, type = "success") {
51+
const div = document.createElement("div");
52+
div.id = "toast";
53+
const text = document.createTextNode(message);
54+
div.appendChild(text);
55+
const styleList = [
56+
'background-color: ' + (type === 'success' ? '#350054' : '#ff0000'),
57+
'color: ' + (type === 'success' ? '#fff' : '#fff'),
58+
];
59+
div.style.cssText = styleList.join(";");
60+
document.body.appendChild(div);
61+
setTimeout(() => {
62+
div.style.opacity = "1";
63+
div.style.transform = "translateY(0)";
64+
}, 1);
65+
setTimeout(() => {
66+
div.style.opacity = "0";
67+
div.style.transform = "translateY(-100%)";
68+
setTimeout(() => {
69+
document.body.removeChild(div);
70+
}, 500);
71+
}, 2000);
4172
}

popup/popup.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,18 @@ footer span {
130130

131131
footer span a {
132132
font-size: 0.8rem;
133+
}
134+
135+
#toast {
136+
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
137+
position: fixed;
138+
bottom: 1%;
139+
left: 1%;
140+
transform: translateY(100%);
141+
padding: 1rem;
142+
border-radius: 0.25rem;
143+
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.5);
144+
opacity: 0;
145+
transition: all 0.5s ease-in-out;
146+
z-index: 9999;
133147
}

popup/popup.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ document.addEventListener('DOMContentLoaded', function () {
22
const start = document.getElementById("start");
33
const stop = document.getElementById("stop");
44
const time = document.getElementById("time");
5+
let ans_key = document.getElementById("test_answer_key");
56
const time_value = document.getElementById("time_value");
67
time_value.innerText = time.value + "s";
78

@@ -10,16 +11,17 @@ document.addEventListener('DOMContentLoaded', function () {
1011
});
1112

1213
start.addEventListener("click", function () {
13-
const ans_key = document.getElementById("test_answer_key").value.replace(/\s/g, "");
14-
15-
if (ans_key == "") {
16-
alert("Please enter the answer key");
17-
return;
18-
}
14+
let ans_key = document.getElementById("test_answer_key").value;
1915

2016
chTab("start", ans_key, time.value);
2117
start.disabled = true;
2218
});
19+
20+
ans_key.addEventListener("input", function () {
21+
ans_key.value = ans_key.value.toUpperCase().replace(/\s/g, "");
22+
start.disabled = false;
23+
});
24+
2325
stop.addEventListener("click", function () {
2426
chTab("stop", "", 0);
2527
start.disabled = true;

0 commit comments

Comments
 (0)