Agma.io linesplit overlay

Linescript overlay for agma.io by Wynell

  1. // ==UserScript==
  2. // @name Agma.io linesplit overlay
  3. // @namespace eeWynell#4980
  4. // @version 1.5
  5. // @description Linescript overlay for agma.io by Wynell
  6. // @author eeWynell#4980
  7. // @match https://agma.io/*
  8. // @license GNU GPLv3
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12.  
  13. 'use strict';
  14.  
  15. let $ = window.$;
  16. const KEY_TABLE = { 0: "", 8: "BACKSPACE", 9: "TAB", 12: "CLEAR", 13: "ENTER", 16: "SHIFT", 17: "CTRL", 18: "ALT", 19: "PAUSE", 20: "CAPSLOCK", 27: "ESC", 32: "SPACE", 33: "PAGEUP", 34: "PAGEDOWN", 35: "END", 36: "HOME", 37: "LEFT", 38: "UP", 39: "RIGHT", 40: "DOWN", 44: "PRTSCN", 45: "INS", 46: "DEL", 65: "A", 66: "B", 67: "C", 68: "D", 69: "E", 70: "F", 71: "G", 72: "H", 73: "I", 74: "J", 75: "K", 76: "L", 77: "M", 78: "N", 79: "O", 80: "P", 81: "Q", 82: "R", 83: "S", 84: "T", 85: "U", 86: "V", 87: "W", 88: "X", 89: "Y", 90: "Z", 91: "WIN", 92: "WIN", 93: "CONTEXTMENU", 96: "NUM 0", 97: "NUM 1", 98: "NUM 2", 99: "NUM 3", 100: "NUM 4", 101: "NUM 5", 102: "NUM 6", 103: "NUM 7", 104: "NUM 8", 105: "NUM 9", 106: "NUM *", 107: "NUM +", 109: "NUM -", 110: "NUM .", 111: "NUM /", 144: "NUMLOCK", 145: "SCROLLLOCK" };
  17. class Settings {
  18. constructor(name, default_value) {
  19. this.settings = {};
  20. this.name = name;
  21. this.load(default_value);
  22. }
  23. load(default_value) {
  24. let raw_settings = localStorage.getItem(this.name);
  25. this.settings = Object.assign({}, default_value, this.settings, JSON.parse(raw_settings));
  26. }
  27. save() {
  28. localStorage.setItem(this.name, JSON.stringify(this.settings));
  29. }
  30. set(key, value) {
  31. if (value === undefined) {
  32. this.settings = key;
  33. } else {
  34. this.settings[key] = value;
  35. }
  36. this.save();
  37. }
  38. get(key) {
  39. if (key === undefined) {
  40. return this.settings;
  41. } else {
  42. return this.settings[key];
  43. }
  44. }
  45. }
  46.  
  47. let settings = new Settings("linesplit_overlay", {
  48. enabled: true,
  49. binding: null
  50. });
  51. let current_key = false, pressing = false;
  52.  
  53. $("head").append(`<style>
  54. .hotkey-input-2.selected {
  55. background-color: #ff4;
  56. color: #444;
  57. }
  58. .hotkey-input-2:hover:not(.selected) {
  59. background-color: #f1a02d;
  60. }
  61. .hotkey-input-2 {
  62. background-color: #df901c;
  63. color: #fff;
  64. cursor: pointer;
  65. text-align: center;
  66. min-width: 40px;
  67. max-width: 60px;
  68. height: 18px;
  69. line-height: 18px;
  70. vertical-align: middle;
  71. border-radius: 9px;
  72. right: 5px;
  73. position: absolute;
  74. display: inline-block;
  75. padding: 0 5px;
  76. overflow: hidden;
  77. opacity: 1;
  78. }
  79. </style>`);
  80.  
  81. let [w, h] = [, window.innerHeight];
  82. $("body").append(`<div id="linesplit_overlay" style="z-index: 999999999;display:${settings.get("enabled") ? "block" : "none"}">
  83. <div id="point-top" style="border: 2px solid white; border-radius: 50%; width: 10px; height: 10px; position: fixed; left: ${window.innerWidth / 2}px; top: ${0}px; transform: translate(-50%, -50%);"></div>
  84. <div id="point-right" style="border: 2px solid white; border-radius: 50%; width: 10px; height: 10px; position: fixed; left: ${window.innerWidth}px; top: ${window.innerHeight / 2}px; transform: translate(-50%, -50%);"></div>
  85. <div id="point-bottom" style="border: 2px solid white; border-radius: 50%; width: 10px; height: 10px; position: fixed; left: ${window.innerWidth / 2}px; top: ${window.innerHeight}px; transform: translate(-50%, -50%);"></div>
  86. <div id="point-left" style="border: 2px solid white; border-radius: 50%; width: 10px; height: 10px; position: fixed; left: ${0}px; top: ${window.innerHeight / 2}px; transform: translate(-50%, -50%);"></div>
  87. </div>`);
  88.  
  89. $("#settingTab3,.rab-radius").click(function(e) {
  90. $("#roleSettings").css("display", "block");
  91. $("#cLinesplitOverlay").removeAttr("disabled").parent().parent().css("display", "block");
  92. });
  93.  
  94. $(".hotkey-col").eq(1).append(`Linesplit overlay <div id="keyLinesplitOverlay" class="hotkey-input-2"></div><br>`);
  95. $("#roleSettings").append(`<div class="role-setting"><label><input id="cLinesplitOverlay" type="checkbox"}><span> Linesplit overlay</span></label><br></div>`);
  96.  
  97. $("#cLinesplitOverlay").change(function(e) {
  98. let enabled = $(this).is(':checked');
  99. settings.set("enabled", enabled);
  100. $("#linesplit_overlay").css("display", enabled ? "block" : "none");
  101. });
  102.  
  103. if (settings.get('enabled')) $("#cLinesplitOverlay").attr("checked", "");
  104.  
  105. $("#keyLinesplitOverlay").html(KEY_TABLE[settings.get("binding")]);
  106.  
  107. $("#keyLinesplitOverlay").click(function(e) {
  108. $(this).addClass("selected");
  109. current_key = true;
  110. });
  111.  
  112. $("#keyLinesplitOverlay").contextmenu(function(e) {
  113. $(this).addClass("selected");
  114. settings.set("binding", null);
  115. $(this).html("");
  116. setTimeout(() => {
  117. $(this).removeClass("selected");
  118. }, 50);
  119. current_key = false;
  120. return false;
  121. });
  122.  
  123. $(window).keyup(function(e) {
  124. if (e.keyCode == settings.get("binding")) {
  125. $("#linesplit_overlay").css("display", settings.get("enabled") ? "block" : "none");
  126. pressing = false;
  127. }
  128. });
  129.  
  130. $(window).keydown(function(e) {
  131. if (current_key) {
  132. $("#keyLinesplitOverlay").html(KEY_TABLE[e.keyCode]);
  133. settings.set("binding", e.keyCode);
  134. setTimeout(() => {
  135. $("#keyLinesplitOverlay").removeClass("selected");
  136. }, 50);
  137. current_key = false;
  138. } else {
  139. if (e.keyCode == settings.get("binding") && document.activeElement == document.body) {
  140. $("#linesplit_overlay").css("display", !settings.get("enabled") ? "block" : "none");
  141. pressing = true;
  142. }
  143. }
  144. });
  145.  
  146. $(window).resize(function(e) {
  147. let [w, h] = [window.innerWidth, window.innerHeight];
  148. $("#point-top").css("left", `${window.innerWidth / 2}px`).css("top", `${0}px`);
  149. $("#point-right").css("left", `${window.innerWidth}px`).css("top", `${window.innerHeight / 2}px`);
  150. $("#point-bottom").css("left", `${window.innerWidth / 2}px`).css("top", `${window.innerHeight}px`);
  151. $("#point-left").css("left", `${0}px`).css("top", `${window.innerHeight / 2}px`);
  152. });