color-test-hack

try press H button when you play the game

目前為 2023-11-28 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name color-test-hack
  3. // @namespace https://www.webhek.com/post/color-test/
  4. // @version 1.0.20231128
  5. // @description try press H button when you play the game
  6. // @author Yang
  7. // @match https://www.webhek.com/post/color-test/
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=undefined.
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. // Your code here...
  16. alert("try press H button when you play the game");
  17. document.onkeydown = function (e) {
  18. var keyNum = window.event ? e.keyCode : e.which;
  19. if (keyNum == 72) {
  20. console.log('您按下了H');
  21. console.log("click")
  22. let box = document.getElementById("box");
  23. let tmp1Color = "";
  24. let tmp2Color = "";
  25. let tmp1Arr = [];
  26. let tmp2Arr = [];
  27. let tmp = "";
  28. if (box && box.childNodes.length > 1) {
  29. let length = box.childNodes.length;
  30.  
  31. for (let index = 0; index < length; index++) {
  32. const element = box.childNodes[index];
  33. if (element.style) {
  34. tmp = element.style.backgroundColor;
  35. if (tmp1Color === "") {
  36. tmp1Color = tmp;
  37. }
  38.  
  39. if (tmp === tmp1Color) {
  40. tmp1Arr.push(index);
  41. } else {
  42. tmp2Color = tmp;
  43. }
  44. if (tmp === tmp2Color) {
  45. tmp2Arr.push(index);
  46. }
  47. }
  48. }
  49. if (tmp1Arr.length < tmp2Arr.length) {
  50. tmp = tmp1Arr[0];
  51. } else {
  52. tmp = tmp2Arr[0];
  53. }
  54. let len = Math.sqrt(length);
  55. let x = (tmp + 1) % len;
  56. let y = Math.ceil((tmp + 1) / len);
  57.  
  58. console.log('test ' + tmp);
  59. console.log('other is ' + x + "," + y);
  60. const testDom = box.childNodes[tmp];
  61. testDom.style.border = "solid 5px #000000";
  62. }
  63. }
  64. }
  65. })();