Advertisement
Guest User

Untitled

a guest
Apr 12th, 2024
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. (async () => {
  2. //Retrieve Shift Information and format as DDs1 or DDs2
  3. let [date, shift] = Array.from(document.querySelector("table tbody")/*first table*/
  4. .children).slice(3, 5).map(tr => tr.lastElementChild.textContent.trim());
  5. date = date.split("/").shift();
  6. shift = shift.toLowerCase().includes("am") ? "1" : "2";
  7. let paper = date + "s" + shift;
  8.  
  9. //ADD NEW PAPER
  10. /*
  11. 1. Get Question Id mapped to Option Id / Answer Number
  12. 2. Take that Object and put in extendsclass.com and copy bin id
  13. 3. Map bin id in paper_map
  14. 4. Good to go
  15. */
  16. let paper_map = {
  17. "08s1":"https://json.extendsclass.com/bin/36173b2e7bea"
  18. };
  19.  
  20. //FETCH ANSWER KE
  21. let ans_map;
  22. try {
  23. ans_map = await fetch(paper_map[paper]);
  24. ans_map = await ans_map.json();
  25. } catch (e) {
  26. console.error(e);
  27. console.error("FAILED to fetch answer keys. Most probably because keys are yet to be uploaded.");
  28. }
  29.  
  30. let qs = [];
  31.  
  32. //RETRIEVE QUESTIONS
  33. for (let tbody of document.querySelectorAll("table.menu-tbl > tbody")) {
  34. let trs = tbody.children,
  35. tds = Array.from(trs).map(tr => tr.lastChild.textContent.trim());
  36.  
  37. let is_mcq = tds[0] === "MCQ";
  38.  
  39. let marked = tbody.parentNode.parentElement.firstChild.firstChild.lastChild.lastChild.textContent.trim();
  40. marked = is_mcq
  41. ? ("Not Answered" === tds[6] ? null : tds.slice(2, 6)[parseInt(tds[7]) - 1])
  42. : ("Not Answered" === tds[2] ? null : marked);
  43.  
  44. qs.push({
  45. type: tds[0],
  46. id: tds[1],
  47. opts: is_mcq ? tds.slice(2, 6) : [],
  48. marked,
  49. score: ans_map[tds[1]] === marked ? 4 : marked ? -1 : 0
  50. });
  51. }
  52.  
  53. let attempted = 0, unattempted = 0,
  54. correct = 0, wrong = 0;
  55.  
  56. //CREATE OUTPUT
  57. let [m, ms] = loop("MAT", 0);
  58. let [p, ps] = loop("PHY", 30);
  59. let [c, cs] = loop("CHE", 60);
  60. let total = m + p + c;
  61. let sw = [ms, ps, cs].join("\n\n");
  62.  
  63. function loop(sub, start) {
  64. let total = 0;
  65.  
  66. let s = sub;
  67.  
  68. qs.slice(start, start + 30).forEach(({ score }, i) => {
  69. total += score;
  70.  
  71. if (i % 10 === 0) s += "\n"
  72. s += pad(i + start, get_emo(score), 5);
  73. });
  74.  
  75. return [total, s];
  76. }
  77.  
  78. function pad(i, e, space) {
  79. let s = `${i < 10 ? "0" : ""}${i+1}${e}`;
  80.  
  81. while (s.length < space) { s += " " }
  82. return s;
  83. }
  84.  
  85. function get_emo(score) {
  86. attempted++;
  87.  
  88. switch (score) {
  89. case 4:
  90. correct++;
  91. return "✅";
  92. case -1:
  93. wrong++;
  94. return "❌";
  95. case 0:
  96. attempted--;
  97. unattempted++;
  98. return "❔"
  99. }
  100. }
  101.  
  102. let output = `
  103. ${paper}
  104. TOTAL: ${total}/300
  105.  
  106. Correct: ${correct}
  107. Incorrect: ${wrong}
  108. Attempted: ${attempted}
  109. Unattempted: ${unattempted}
  110.  
  111. Physics: ${p}/100
  112. Chemistry: ${c}/100
  113. Maths: ${m}/100
  114.  
  115. ${sw}`;
  116.  
  117. let box = document.createElement("div");
  118. box.style = "background: black; color: white; padding: 1rem; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); box-shadow: 3px 3px 10px #00000055;";
  119.  
  120. let el = document.createElement("pre");
  121. el.style = "font-family: sans-serif;";
  122. el.textContent = output;
  123.  
  124. let button = document.createElement("button");
  125. button.addEventListener("click", e => {
  126. window.navigator.clipboard.writeText(output);
  127. e.target.textContent = "copied";
  128. });
  129. button.style = "width: fit-content; display: block; margin: 1rem 0 0 auto;";
  130. button.textContent = "COPY";
  131.  
  132. box.append(el, button);
  133.  
  134. document.body.appendChild(box);
  135. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement