Kahoot Namerator and Name Length Bypass

Bypasses kahoot nickname generator as well as the maximum name length

  1. // ==UserScript==
  2. // @name Kahoot Namerator and Name Length Bypass
  3. // @author slither
  4. // @version 2.3.0
  5. // @license MIT
  6. // @description Bypasses kahoot nickname generator as well as the maximum name length
  7. // @match https://kahoot.it/*
  8. // @grant none
  9. // @run-at document-start
  10. // @namespace https://greasyfork.org/users/964173
  11. // ==/UserScript==
  12.  
  13. let nick = "";
  14.  
  15. const nativeSend = XMLHttpRequest.prototype.send;
  16. XMLHttpRequest.prototype.send = function() {
  17. const oldCallback = this.onreadystatechange;
  18.  
  19. this.onreadystatechange = function() {
  20. if (this.readyState === 4) {
  21. try {
  22. const response = JSON.parse(this.responseText);
  23.  
  24. if (response.namerator === true)
  25. response.namerator = false;
  26.  
  27. Object.defineProperty(this, "responseText",{
  28. writable: false,
  29. configurable: true,
  30. value: JSON.stringify(response)
  31. });
  32. } catch (e) {
  33. console.error(e);
  34. }
  35. }
  36.  
  37. if (oldCallback)
  38. return oldCallback.apply(this, arguments);
  39. };
  40.  
  41. return nativeSend.apply(this, arguments);
  42. };
  43.  
  44. const nativeWebSocket = window.WebSocket;
  45. window.WebSocket = function() {
  46. const ws = new nativeWebSocket(...arguments);
  47. const nativeSend = ws.send;
  48.  
  49. ws.send = function() {
  50. const interceptedMessage = JSON.parse(arguments[0]);
  51.  
  52. if (interceptedMessage[0] && interceptedMessage[0].data) {
  53. if (JSON.parse(interceptedMessage[0].data.content).usingNamerator === false)
  54. interceptedMessage[0].data.content = JSON.stringify({ ...JSON.parse(interceptedMessage[0].data.content), usingNamerator: true });
  55.  
  56. if (nick && interceptedMessage[0].data.name) {
  57. interceptedMessage[0].data.name = nick;
  58. nick = "";
  59. }
  60. }
  61.  
  62. return nativeSend.apply(this, [JSON.stringify(interceptedMessage)]);
  63. };
  64.  
  65. return ws;
  66. };
  67.  
  68. const nativePushState = history.pushState;
  69. history.pushState = function() {
  70. const ret = nativePushState.apply(history, arguments);
  71.  
  72. if (location.href.includes("kahoot.it/join")) {
  73. const observer = new MutationObserver(function() {
  74. if (document.getElementById("nickname")) {
  75. const input = document.createElement("input");
  76. const nickname = document.getElementById("nickname");
  77. const reactProps = Object.keys(nickname).find(v => v.includes("__reactProps"));
  78. input.className = nickname.className;
  79. input.type = "text";
  80. input.placeholder = "Nickname";
  81. nickname.replaceWith(input);
  82.  
  83. input.nextElementSibling.addEventListener("click", function() {
  84. nick = input.value;
  85. nickname[reactProps].onChange({ target: { value: nick.slice(0, 15) } });
  86. });
  87.  
  88. observer.disconnect();
  89. }
  90. });
  91.  
  92. observer.observe(document.body, {
  93. childList: true,
  94. subtree: true
  95. });
  96. }
  97.  
  98. return ret;
  99. };