Cauull

Auto Answer Quiziz

Oct 27th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.84 KB | None | 0 0
  1. if (window.location.href.search("quizizz.com/join/game/") == -1 && window.location.href.search("gameType=") == -1) {
  2. if (window.location.href.search("quizizz.com/join/pre-game/") != -1) {
  3. alert("You cannot execute this while paused. If you are not paused please DM East_Arctica#9238 on discord!")
  4. throw new Error("You cannot execute this while paused. If you think this is an error please DM East_Arctica#9238 on discord!");
  5. } else if (window.location.href.search("quizizz.com/join/quiz/") != -1) {
  6. alert("You need to start the game before running this script. If you think this is an error please DM East_Arctica#9238 on discord!")
  7. throw new Error("You need to start the game before running this script. If you think this is an error please DM East_Arctica#9238 on discord!");
  8. } else {
  9. alert("You aren't on a quizizz quiz. If you think this is an error please DM East_Arctica#9238 on discord!")
  10. throw new Error("You aren't on a quizizz quiz. If you think this is an error please DM East_Arctica#9238 on discord!");
  11. }
  12. }
  13.  
  14. if (typeof jQuery == 'undefined') {
  15. let script = document.createElement('script');
  16. script.src = 'https://code.jquery.com/jquery-3.4.1.min.js';
  17. script.type = 'text/javascript';
  18. document.getElementsByTagName('head')[0].appendChild(script);
  19. }
  20.  
  21. let WaitTime = prompt("Please enter the number of seconds to wait before each answer.")
  22. if (Number(WaitTime) === NaN) {
  23. alert("You did not enter a valid number. Reload and try again")
  24. throw new Error("Invalid number");
  25. } else {
  26. WaitTime = Number(WaitTime) * 1000
  27. }
  28.  
  29. document.head.insertAdjacentHTML('beforeend', `<style type="text/css">
  30. correct-answer-x3Ca8B {
  31. color: lime !important;
  32. }
  33. </style>`);
  34.  
  35. class Encoding {
  36. static encodeRaw(t, e, o = "quizizz.com") {
  37. let s = 0;
  38. s = e ? o.charCodeAt(0) : o.charCodeAt(0) + o.charCodeAt(o.length - 1);
  39. let r = [];
  40. for (let o = 0; o < t.length; o++) {
  41. let n = t[o].charCodeAt(0)
  42. , c = e ? this.safeAdd(n, s) : this.addOffset(n, s, o, 2);
  43. r.push(String.fromCharCode(c))
  44. }
  45. return r.join("")
  46. }
  47.  
  48. static decode(t, e = !1) {
  49. if (e) {
  50. let e = this.extractHeader(t);
  51. return this.decodeRaw(e, !0)
  52. }
  53. {
  54. let e = this.decode(this.extractHeader(t), !0)
  55. , o = this.extractData(t);
  56. return this.decodeRaw(o, !1, e)
  57. }
  58. }
  59.  
  60. static decodeRaw(t, e, o = "quizizz.com") {
  61. let s = this.extractVersion(t);
  62. let r = 0;
  63. r = e ? o.charCodeAt(0) : o.charCodeAt(0) + o.charCodeAt(o.length - 1),
  64. r = -r;
  65. let n = [];
  66. for (let o = 0; o < t.length; o++) {
  67. let c = t[o].charCodeAt(0)
  68. , a = e ? this.safeAdd(c, r) : this.addOffset(c, r, o, s);
  69. n.push(String.fromCharCode(a))
  70. }
  71. return n.join("")
  72. }
  73.  
  74. static addOffset(t, e, o, s) {
  75. return 2 === s ? this.verifyCharCode(t) ? this.safeAdd(t, o % 2 == 0 ? e : -e) : t : this.safeAdd(t, o % 2 == 0 ? e : -e)
  76. }
  77.  
  78. static extractData(t) {
  79. let e = t.charCodeAt(t.length - 2) - 33;
  80. return t.slice(e, -2)
  81. }
  82.  
  83. static extractHeader(t) {
  84. let e = t.charCodeAt(t.length - 2) - 33;
  85. return t.slice(0, e)
  86. }
  87.  
  88. static extractVersion(t) {
  89. if ("string" == typeof t && t[t.length - 1]) {
  90. let e = parseInt(t[t.length - 1], 10);
  91. if (!isNaN(e))
  92. return e
  93. }
  94. return null
  95. }
  96.  
  97. static safeAdd(t, e) {
  98. let o = t + e;
  99. return o > 65535 ? o - 65535 + 0 - 1 : o < 0 ? 65535 - (0 - o) + 1 : o
  100. }
  101.  
  102. static verifyCharCode(t) {
  103. if ("number" == typeof t)
  104. return !(t >= 55296 && t <= 56319 || t >= 56320 && t <= 57343)
  105. }
  106. }
  107.  
  108. function GetSetData() {
  109. let URL = window.location.href
  110. , GameType = URL.slice(URL.search("gameType=") + 9, URL.length)
  111. , prevConx = localStorage.getItem("previousContext")
  112. , parsedConx = JSON.parse(prevConx)
  113. , encodedRoomHash = parsedConx.game.roomHash
  114. , roomHash = Encoding.decode(encodedRoomHash.split("-")[1])
  115. , data = {
  116. roomHash: roomHash,
  117. type: GameType
  118. };
  119.  
  120. let xhttp = new XMLHttpRequest
  121. xhttp.open("POST", "https://game.quizizz.com/play-api/v3/getQuestions", false)
  122. xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
  123. xhttp.send(JSON.stringify(data))
  124. return JSON.parse(xhttp.responseText)
  125. }
  126.  
  127. function GetAnswer(Question) {
  128. switch (Question.structure.kind) {
  129. case "BLANK":
  130. // Text Response, we have no need for image detection in answers
  131. let ToRespond = []
  132. for (let i = 0; i < Question.structure.options.length; i++) {
  133. ToRespond.push(Question.structure.options[i].text)
  134. }
  135. return ToRespond;
  136. case "MSQ":
  137. // Multiple Choice
  138. let Answers = Encoding.decode(Question.structure.answer)
  139. Answers = JSON.parse(Answers)
  140. let TextArray = []
  141. for (let i = 0; i < Answers.length; i++) {
  142. if (Answers[i].text == "") {
  143. TextArray.push(Question.structure.options[Answers[i]].media[0].url)
  144. } else {
  145. TextArray.push(Question.structure.options[Answers[i]].text)
  146. }
  147. }
  148. return TextArray;
  149. case "MCQ":
  150. // Single Choice
  151. let AnswerNum = Encoding.decode(Question.structure.answer)
  152. let Answer = Question.structure.options[AnswerNum].text
  153. if (Answer == "") {
  154. Answer = Question.structure.options[AnswerNum].media[0].url
  155. }
  156. return Answer;
  157. }
  158. }
  159.  
  160. function GetQuestion(Set) {
  161. for (let v of Object.keys(Set.questions)) {
  162. v = Set.questions[v]
  163. switch (GetQuestionType()) {
  164. case "Both":
  165. let BothSRC = document.getElementsByClassName("question-media")[0].children[0].src
  166. BothSRC = BothSRC.slice(0, BothSRC.search("/?w=") - 1)
  167. if (v.structure.query.media[0]) {
  168. if (v.structure.query.media[0].url == BothSRC) {
  169. let BothQuestion = document.getElementsByClassName("question-text")[0].children[0].children[0].innerHTML
  170. if (Fix(BothQuestion) == Fix(v.structure.query.text)) {
  171. return (v)
  172. }
  173. }
  174. }
  175. break
  176. case "Media":
  177. let CurrentSRC = document.getElementsByClassName("question-media")[0].children[0].src
  178. CurrentSRC = CurrentSRC.slice(0, CurrentSRC.search("/?w=") - 1)
  179. if (v.structure.query.media[0]) {
  180. if (v.structure.query.media[0].url == CurrentSRC) {
  181. return (v)
  182. }
  183. }
  184. break
  185. case "Text":
  186. let ToSearchA = document.getElementsByClassName("question-text")[0].children[0].children[0].innerHTML
  187. let ToSearchB = v.structure.query.text
  188. ToSearchB = ToSearchB
  189. ToSearchA = ToSearchA
  190. if (Fix(ToSearchA) == Fix(ToSearchB)) {
  191. return (v)
  192. }
  193. break
  194. }
  195. }
  196. return "Error: No question found"
  197. }
  198.  
  199. function GetQuestionType() {
  200. if (document.getElementsByClassName("question-media")[0]) {
  201. // Media was detected, check if text is too
  202. if (document.getElementsByClassName("question-text")[0]) {
  203. // Detected text aswell, send it to the onchanged
  204. return ("Both")
  205. } else {
  206. // Failed to detect text aswell, Media is all that we need to send
  207. return ("Media")
  208. }
  209. } else {
  210. // Media wasn't detected, no need to check if text was because it has to be
  211. return ("Text")
  212. }
  213. }
  214.  
  215. let CurrentQuestionNum = ""
  216. let LastRedemption
  217.  
  218. function Fix(s) {
  219. sEnd = s.lastIndexOf("&nbsp;")
  220. if (sEnd == s.length - 6) {
  221. s = s.substring(0, sEnd)
  222. }
  223. s = s.replace(/&nbsp;/g, " ")
  224. s = s.replace(/&#8203;/g, "‍")
  225. s = jQuery('<div>').html(String(s))[0].innerHTML
  226. s = s.replace(/\s+/g, ' ')
  227. return s
  228. }
  229.  
  230. function QuestionChangedLoop() {
  231. setTimeout(function () {
  232. let NewNum = document.getElementsByClassName("current-question")[0]
  233. let RedemptionQues = document.getElementsByClassName("redemption-marker")[0]
  234. if (NewNum) {
  235. if (NewNum.innerHTML != CurrentQuestionNum) {
  236. setTimeout(function () {
  237. if (document.getElementsByClassName("typed-option-input")[0]) {
  238. let Question = GetQuestion(GetSetData())
  239. if (Question == "Error: No question found") {
  240. alert("Failed to find question!")
  241. } else {
  242. let Answer = GetAnswer(Question)
  243. if (Array.isArray(Answer)) {
  244. // We are on a question with multiple answers
  245. let ToShow = ""
  246. for (let x = 0; x < Answer.length; x++) {
  247. if (ToShow == "") {
  248. ToShow = Answer[x]
  249. } else {
  250. ToShow = ToShow + " | " + Answer[x]
  251. }
  252. }
  253. let ToShowNew = "Press Ctrl+C to copy (Answers are seperated by ' | ')"
  254. prompt(ToShowNew, ToShow)
  255. } else {
  256. let NewAnswer = "Press Ctrl+C to copy."
  257. prompt(NewAnswer, Answer);
  258. }
  259. }
  260. } else {
  261. let Choices = document.getElementsByClassName("options-container")[0].children[0].children
  262. let Question = GetQuestion(GetSetData())
  263. if (Question === "Error: No question found") {
  264. setTimeout(function() {
  265. Question = GetQuestion(GetSetData())
  266. }, 500)
  267. }
  268. if (Question === "Error: No question found") {
  269. alert("Failed to find question!")
  270. } else {
  271. for (let i = 0; i < Choices.length; i++) {
  272. if (!Choices[i].classList.contains("emoji")) {
  273. let Choice = Choices[i].children[0].children[0].children[0].children[0]
  274. let Answer = GetAnswer(Question)
  275. if (Array.isArray(Answer)) {
  276. // We are on a question with multiple answers
  277. for (let x = 0; x < Answer.length; x++) {
  278. if (Fix(Choice.innerHTML) == Answer[x]) {
  279. setTimeout(function () {
  280. Choice.parentElement.click()
  281. }, WaitTime)
  282. }
  283. }
  284. } else {
  285. if (Fix(Choice.innerHTML) == Answer) {
  286. setTimeout(function () {
  287. Choice.parentElement.click()
  288. }, WaitTime)
  289. } else if (Choice.style.backgroundImage.slice(5, Choice.style.backgroundImage.length - 2).slice(0, Choice.style.backgroundImage.slice(5, Choice.style.backgroundImage.length - 2).search("/?w=") - 1) == GetAnswer(GetQuestion(GetSetData()))) {
  290. setTimeout(function () {
  291. Choice.parentElement.click()
  292. }, WaitTime)
  293. }
  294. }
  295. }
  296. }
  297. }
  298. }
  299. }, 1000)
  300. CurrentQuestionNum = NewNum.innerHTML
  301. }
  302. } else if (RedemptionQues) {
  303. if (LastRedemption != GetQuestion(GetSetData())) {
  304. let Choices = document.getElementsByClassName("options-container")[0].children[0].children
  305. for (let i = 0; i < Choices.length; i++) {
  306. if (!Choices[i].classList.contains("emoji")) {
  307. let Choice = Choices[i].children[0].children[0].children[0].children[0]
  308. if (Fix(Choice.innerHTML) == GetAnswer(GetQuestion(GetSetData()))) {
  309. setTimeout(function () {
  310. Choice.parentElement.click()
  311. }, WaitTime)
  312. }
  313. }
  314. }
  315. LastRedemption = GetQuestion(GetSetData())
  316. }
  317. }
  318. QuestionChangedLoop()
  319. }, 100)
  320. }
  321.  
  322. function sleep(ms) {
  323. return new Promise(resolve => setTimeout(resolve, ms))
  324. }
  325.  
  326. async function wait() {
  327. await sleep(1000);
  328. QuestionChangedLoop();
  329. }
  330.  
  331. wait()
Add Comment
Please, Sign In to add comment