Join Random Game Mode

Join a new game on your region with the highest player count for a random game mode that is not full when you press a certain key

当前为 2024-01-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Join Random Game Mode
  3. // @namespace violentmonkey
  4. // @version 1.3.3.7
  5. // @description Join a new game on your region with the highest player count for a random game mode that is not full when you press a certain key
  6. // @author hitthemoney, moongazer07
  7. // @match *://krunker.io/*
  8. // @exclude *://krunker.io/social.html*
  9. // @exclude *://krunker.io/editor.html*
  10. // @grant GM_xmlhttpRequest
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. const joinKey = "F5"; // Join game shortcut key, case sensitive
  15.  
  16. const getRandomGameMode = async () => {
  17. return new Promise((resolve, reject) => {
  18. GM_xmlhttpRequest({
  19. method: "GET",
  20. url: "https://www.random.org/integers/?num=1&min=0&max=14&col=1&base=10&format=plain&rnd=new",
  21. onload: function(response) {
  22. if (response.status === 200) {
  23. resolve(parseInt(response.responseText.trim()));
  24. } else {
  25. reject(new Error("Failed to fetch random number from Random.org"));
  26. }
  27. },
  28. onerror: function(error) {
  29. reject(new Error("Failed to fetch random number from Random.org"));
  30. }
  31. });
  32. });
  33. };
  34.  
  35. const getTopGame = async () => {
  36. const region = window.localStorage.pingRegion7 || (await fetch(`https://matchmaker.krunker.io/game-info?game=${encodeURIComponent(window.getGameActivity().id)}`).then(res => res.json()));
  37. const gameData = (await fetch(`https://matchmaker.krunker.io/game-list?hostname=${window.location.hostname}`).then(res => res.json())).games;
  38.  
  39. const targetGameMode = await getRandomGameMode();
  40.  
  41. const filData = gameData.filter(game =>
  42. game[1] === region &&
  43. game[4].g === targetGameMode &&
  44. game[4].c === 0 &&
  45. game[2] < game[3]
  46. ).sort((x, y) => y[2] - x[2]);
  47.  
  48. return filData[0];
  49. }
  50.  
  51. const joinTopGame = async () => {
  52. const targetGame = await getTopGame();
  53. window.location.href = `/?game=${targetGame[0]}`;
  54. }
  55.  
  56. window.addEventListener("keydown", async (event) => {
  57. switch (event.key) {
  58. case joinKey: {
  59. await joinTopGame();
  60. break;
  61. }
  62. }
  63. });