G1h - generals.io 1v1 helper

1v1、custotm辅助脚本,持续更新中

  1. // ==UserScript==
  2. // @name G1h - generals.io 1v1 helper
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.1.0
  5. // @description 1v1、custotm辅助脚本,持续更新中
  6. // @author itray25
  7. // @match *://generals.io/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=generals.io
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. let color;
  15. let color_dict={"lightblue":"#4363d8","red":"red"}
  16. let first=1
  17. let tileObserver = new MutationObserver(function (mutations) {
  18. mutations.forEach(function (mutation) {
  19. window.setTimeout(function () {
  20. var target=mutation.target
  21. //console.log([target.classList.length,target.classList])
  22. if(target.classList[1]=="general" && (target.classList[0]==color?false : true)){
  23. let sheet = document.styleSheets[1];
  24. if(first==1){
  25. sheet.deleteRule(0);
  26. sheet.insertRule("#null {background-color:"+color_dict[target.classList[0]]+" !important;background-image: url(\"\/\/generals.io\/crown.png\") !important;background-repeat: no-repeat !important;background-size: 100% 100% !important;border-color:cyan !important}",0);
  27. first=0
  28. target.id="gen"
  29. }
  30. else{
  31. target.id="gen"}
  32.  
  33. //console.log(target)
  34. }
  35. },1000)
  36.  
  37.  
  38. });
  39. });
  40. let gameObserver = new MutationObserver(function (mutations) {
  41. mutations.forEach(function (mutation) {
  42. if (
  43. mutation.addedNodes.length > 0 &&
  44. mutation.addedNodes[0].id === "game-page"
  45. ) {
  46. tileObserver.disconnect();
  47. setTimeout(function () {}, 400);
  48. setTimeout(function () {
  49. console.log("loading map");
  50.  
  51. let map = document.getElementById("gameMap");
  52. let tiles = map.getElementsByTagName("td");
  53. let col = map.getElementsByTagName("tr").length;
  54. let row=tiles.length/col
  55. let d_map = [];
  56. let sheet = document.styleSheets[1];
  57. let player_sum=document.getElementById("game-leaderboard").childNodes[0].childNodes.length
  58. let mode;
  59. let main_dist;
  60. if(player_sum==3){
  61. mode="solo"
  62. main_dist=15
  63. }else if(player_sum==9){
  64. mode = "ffa"
  65. main_dist=10
  66. }else {
  67. mode="teams"
  68. main_dist=10
  69. }
  70. sheet.insertRule(".imp {background-color:#006c66 !important}",0);
  71. //gen_index=tiles.indexOf(map.getElementsByClassName("general"))
  72. //console.log("gen_index")
  73. for (var j = 0; j < col; j++) {
  74. d_map.push([]);
  75. }
  76. var gen_row, gen_col;
  77. console.log(d_map);
  78. //1st loop, binarify map[effect not known]
  79. for (var i = 0; i < tiles.length; i++) {
  80. let target = tiles[i];
  81. let classN = target.classList;
  82. let t_col = Math.trunc((i * col) / tiles.length);
  83. let t_row = i % (tiles.length / col);
  84. target.id = t_col + " " + t_row;
  85. //console.log(classN);
  86. if (classN[1] == "general") {
  87. d_map[t_col].push(2);
  88. gen_row = t_row;
  89. gen_col = t_col;
  90. color = classN[0]
  91. } else if (classN[1] == "obstacle") {
  92. d_map[t_col].push(1);
  93. } else {
  94. d_map[t_col].push(0);
  95. }
  96.  
  97. let config = { attributes: true, childList: false, characterData: true };
  98. tileObserver.observe(target, config);
  99. }
  100. console.log(d_map);
  101. // 2nd loop, locate possible gen region
  102. for (i = 0; i < tiles.length; i++) {
  103. let target = tiles[i];
  104. let t_col = parseInt(target.id.split(" ")[0]);
  105. let t_row = parseInt(target.id.split(" ")[1]);
  106. //designed for 1v1
  107. if (
  108. Math.abs(t_col - gen_col) + Math.abs(t_row - gen_row) >= main_dist &&
  109. target.classList[1] != "obstacle"
  110. && !((t_col==0 ? true : t_col!=0 ? d_map[t_col-1][t_row]!=0 :true)&&
  111. (t_col==col-1 ? true : t_col!=col-1 ? d_map[t_col+1][t_row]!=0 :true)&&
  112. (t_row==0 ? true : t_row!=0 ? d_map[t_col][t_row-1]!=0 :true)&&
  113. (t_row==row-1 ? true : t_row!=row-1 ? d_map[t_col][t_row+1]!=0 :true))
  114. ) {
  115. target.classList.add("imp");
  116. }
  117. }
  118. }, 100);
  119. }
  120. });
  121. });
  122. let gameConfig = { attributes: true, childList: true, characterData: true };
  123. let gameTarget = document.getElementById("react-container").children[0];
  124. gameObserver.observe(gameTarget, gameConfig);
  125. //with regards to O.O
  126. })();

QingJ © 2025

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