Kahoot Cheat (Beta) (Working Dec 2024)

Skibidi Toilet approved, made by floidAI

  1. // ==UserScript==
  2. // @name Kahoot Cheat (Beta) (Working Dec 2024)
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.02.1
  5. // @description Skibidi Toilet approved, made by floidAI
  6. // @author You
  7. // @match https://kahoot.it/*
  8. // @grant GM.xmlHttpRequest
  9. // @run-at document-idle
  10. // @license Unlicense
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. const selectors = [
  17. 'answer-0',
  18. 'answer-1',
  19. 'answer-2',
  20. 'answer-3'
  21. ];
  22. const questionSelector = '.question-title__Title-sc-12qj0yr-1';
  23. const imageAnswerSelector = '[data-functional-selector="image-answer"]';
  24.  
  25. let quizData = null;
  26. let currentUrl = location.href;
  27.  
  28. const observeUrlChange = () => {
  29. setInterval(() => {
  30. if (location.href !== currentUrl) {
  31. currentUrl = location.href;
  32. if (currentUrl === 'https://kahoot.it/gameblock') {
  33. extractAndSendData();
  34. }
  35. }
  36. }, 500);
  37. };
  38.  
  39. const extractAndSendData = () => {
  40. try {
  41. const questionElement = document.querySelector(questionSelector);
  42. const answerElements = selectors
  43. .map(selector => document.querySelector(`[data-functional-selector="${selector}"]`))
  44. .filter(el => el);
  45.  
  46. if (!questionElement || answerElements.length === 0) {
  47. throw new Error('Required elements not found or no answers available.');
  48. }
  49.  
  50. const question = questionElement.innerText.trim();
  51. const answers = answerElements.map(el => el.innerText.trim());
  52.  
  53. if (quizData) {
  54. processQuestionData(question, answers);
  55. } else {
  56. const query = question;
  57. const apiUrl = `https://create.kahoot.it/rest/kahoots/?query=${encodeURIComponent(query)}&limit=20&orderBy=relevance&cursor=0&searchCluster=1&includeExtendedCounters=false&inventoryItemId=ANY`;
  58.  
  59. GM.xmlHttpRequest({
  60. method: 'GET',
  61. url: apiUrl,
  62. onload: function (response) {
  63. try {
  64. const jsonResponse = JSON.parse(response.responseText);
  65. if (jsonResponse.entities && jsonResponse.entities.length > 0) {
  66. const quizId = jsonResponse.entities[0].card.uuid;
  67. const quizDetailsUrl = `https://create.kahoot.it/rest/kahoots/${quizId}/card/?includeKahoot=true`;
  68.  
  69. GM.xmlHttpRequest({
  70. method: 'GET',
  71. url: quizDetailsUrl,
  72. onload: function (response) {
  73. try {
  74. quizData = JSON.parse(response.responseText);
  75. processQuestionData(question, answers);
  76. } catch (err) {
  77. console.error('Error parsing quiz details response:', err);
  78. }
  79. },
  80. onerror: function (error) {
  81. console.error('Error fetching quiz details:', error);
  82. }
  83. });
  84. } else {
  85. console.error('No matching quizzes found.');
  86. }
  87. } catch (err) {
  88. console.error('Error parsing API response:', err);
  89. }
  90. },
  91. onerror: function (error) {
  92. console.error('Error making API request:', error);
  93. }
  94. });
  95. }
  96. } catch (error) {
  97. console.error('An error occurred in extractAndSendData:', error.message);
  98. }
  99. };
  100.  
  101. const processQuestionData = (question, answers) => {
  102. try {
  103. let matchedQuestion = quizData.kahoot.questions.find(questionInData => {
  104. if (!questionInData || !questionInData.question || typeof questionInData.question.trim !== 'function') {
  105. throw new Error('Invalid question data encountered in quizData.kahoot.questions.');
  106. }
  107. return questionInData.question.trim() === question;
  108. });
  109.  
  110. if (!matchedQuestion) {
  111. console.warn('Exact match failed. Attempting fuzzy matching...');
  112. matchedQuestion = fuzzyMatchQuestion(question);
  113.  
  114. if (!matchedQuestion) {
  115. console.error('No match found after fuzzy matching.');
  116. throw new Error('Unable to find a matching question.');
  117. }
  118. }
  119.  
  120. const correctChoice = matchedQuestion.choices.find(choice => choice.correct);
  121.  
  122. if (correctChoice) {
  123. if (correctChoice.image) {
  124. highlightCorrectImageAnswer(correctChoice.image.id);
  125. } else {
  126. const correctAnswerText = correctChoice.answer.trim();
  127. answers.forEach((answerText, index) => {
  128. if (answerText === correctAnswerText) {
  129. const answerElement = document.querySelector(`[data-functional-selector="answer-${index}"]`);
  130. if (answerElement) {
  131. answerElement.innerText = answerText + '.';
  132. }
  133. }
  134. });
  135. }
  136. }
  137. } catch (error) {
  138. console.error('An error occurred while processing question data:', error.message);
  139. }
  140. };
  141.  
  142. const highlightCorrectImageAnswer = (imageId) => {
  143. try {
  144. const imageElements = document.querySelectorAll(imageAnswerSelector);
  145. imageElements.forEach(imgElement => {
  146. const ariaLabel = imgElement.getAttribute('aria-label');
  147. if (ariaLabel && ariaLabel.includes(imageId)) {
  148. imgElement.style.border = '5px solid green';
  149. }
  150. });
  151. } catch (error) {
  152. console.error('An error occurred while highlighting the correct image answer:', error.message);
  153. }
  154. };
  155.  
  156. const fuzzyMatchQuestion = (inputQuestion) => {
  157. try {
  158. const threshold = 0.8; // Similarity threshold
  159. const similarity = (str1, str2) => {
  160. const normalize = s => s.toLowerCase().replace(/\s+/g, '');
  161. str1 = normalize(str1);
  162. str2 = normalize(str2);
  163. const length = Math.max(str1.length, str2.length);
  164. if (!length) return 1;
  165. const editDistance = levenshtein(str1, str2);
  166. return 1 - editDistance / length;
  167. };
  168.  
  169. const levenshtein = (a, b) => {
  170. const matrix = Array.from({ length: a.length + 1 }, (_, i) => Array(b.length + 1).fill(0));
  171. for (let i = 0; i <= a.length; i++) matrix[i][0] = i;
  172. for (let j = 0; j <= b.length; j++) matrix[0][j] = j;
  173. for (let i = 1; i <= a.length; i++) {
  174. for (let j = 1; j <= b.length; j++) {
  175. matrix[i][j] = Math.min(
  176. matrix[i - 1][j] + 1,
  177. matrix[i][j - 1] + 1,
  178. matrix[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1)
  179. );
  180. }
  181. }
  182. return matrix[a.length][b.length];
  183. };
  184.  
  185. let bestMatch = null;
  186. let bestScore = 0;
  187.  
  188. quizData.kahoot.questions.forEach(questionInData => {
  189. const score = similarity(inputQuestion, questionInData.question);
  190. if (score >= threshold && score > bestScore) {
  191. bestMatch = questionInData;
  192. bestScore = score;
  193. }
  194. });
  195.  
  196. return bestMatch;
  197. } catch (error) {
  198. console.error('An error occurred during fuzzy matching:', error.message);
  199. return null;
  200. }
  201. };
  202.  
  203. observeUrlChange();
  204. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址