Advertisement
nerdforneurons

Untitled

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