Hordes UI Mod

Various UI mods for Hordes.io.

当前为 2019-12-31 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hordes UI Mod
  3. // @version 1.1.4
  4. // @description Various UI mods for Hordes.io.
  5. // @author Sakaiyo & Chandog#6373 & Cullen
  6. // @match https://hordes.io/play
  7. // @grant GM_addStyle
  8. // @namespace https://greasyfork.org/users/160017
  9. // ==/UserScript==
  10.  
  11. GM_addStyle(`/* Custom css for settings page, duplicates preexisting settings pane grid */
  12. .uimod-settings {
  13. display: grid;
  14. grid-template-columns: 2fr 3fr;
  15. grid-gap: 8px;
  16. align-items: center;
  17. max-height: 390px;
  18. margin: 0 20px;
  19. overflow-y: auto; }
  20. /* Custom chat context menu, invisible by default */
  21. .js-chat-context-menu {
  22. display: none; }
  23.  
  24. .js-chat-context-menu .name {
  25. color: white;
  26. padding: 2px 4px; }
  27.  
  28. /* Allow names in chat to be clicked (textf1 = BL, textf0 = VG) */
  29. #chat .name,
  30. .textwhisper .textf1,
  31. .textwhisper .textf0 {
  32. pointer-events: all !important; }
  33. /* Custom chat filter colors */
  34. .js-chat-gm {
  35. color: #a6dcd5; }
  36.  
  37. /* Class that hides chat lines */
  38. .js-line-hidden,
  39. .js-line-blocked {
  40. display: none; }
  41. /* Custom chat tabs */
  42. .uimod-chat-tabs {
  43. position: fixed;
  44. margin-top: -22px;
  45. left: 5px;
  46. pointer-events: all;
  47. color: #5b858e;
  48. font-size: 12px;
  49. font-weight: bold; }
  50.  
  51. .uimod-chat-tabs > div {
  52. cursor: pointer;
  53. background-color: rgba(0, 0, 0, 0.4);
  54. border-top-right-radius: 4px;
  55. border-top-left-radius: 4px;
  56. display: inline-block;
  57. border: 1px black solid;
  58. border-bottom: 0;
  59. margin-right: 2px;
  60. padding: 3px 5px; }
  61.  
  62. .uimod-chat-tabs > div:not(.js-selected-tab):hover {
  63. border-color: #aaa; }
  64.  
  65. .uimod-chat-tabs > .js-selected-tab {
  66. color: #fff; }
  67.  
  68. /* Chat tab custom config */
  69. .uimod-chat-tab-config {
  70. position: absolute;
  71. z-index: 9999999;
  72. background-color: rgba(0, 0, 0, 0.6);
  73. color: white;
  74. border-radius: 3px;
  75. text-align: center;
  76. padding: 8px 12px 8px 6px;
  77. width: 175px;
  78. font-size: 14px;
  79. border: 1px solid black;
  80. display: none; }
  81.  
  82. .uimod-chat-tab-config-grid {
  83. grid-template-columns: 35% 65%;
  84. display: grid;
  85. grid-gap: 6px;
  86. align-items: center; }
  87.  
  88. .uimod-chat-tab-config h1 {
  89. font-size: 16px;
  90. margin-top: 0; }
  91.  
  92. .uimod-chat-tab-config .btn,
  93. .uimod-chat-tab-config input {
  94. font-size: 12px; }
  95. /* Allows windows to be moved */
  96. .window {
  97. position: relative; }
  98.  
  99. /* All purpose hidden class */
  100. .js-hidden {
  101. display: none; }
  102. /* Friends list CSS, similar to settings but supports 4 columns */
  103. .uimod-friends {
  104. display: grid;
  105. grid-template-columns: 2fr 1.1fr 1.5fr 0.33fr 3fr;
  106. grid-gap: 8px;
  107. align-items: center;
  108. max-height: 390px;
  109. margin: 0 20px;
  110. overflow-y: auto; }
  111. .js-map-btns {
  112. position: absolute;
  113. top: 46px;
  114. right: 12px;
  115. z-index: 999;
  116. width: 100px;
  117. height: 100px;
  118. text-align: right;
  119. display: none;
  120. pointer-events: all; }
  121.  
  122. .js-map-btns:hover {
  123. display: block; }
  124.  
  125. .js-map-btns button {
  126. border-radius: 10px;
  127. font-size: 18px;
  128. padding: 0 5px;
  129. background: rgba(0, 0, 0, 0.4);
  130. border: 0;
  131. color: white;
  132. font-weight: bold;
  133. cursor: pointer; }
  134.  
  135. /* On hover of map, show opacity controls */
  136. .js-map:hover .js-map-btns {
  137. display: block; }
  138. /* Mirror styles of other merchant inputs */
  139. .uidom-merchant-input {
  140. margin: 4px 0;
  141. align-self: center; }
  142.  
  143. /* Add 225px column for new filters input */
  144. .uidom-merchant-with-filters .search {
  145. grid-template-columns: 120px auto 50px auto 50px 225px 1fr auto auto; }
  146. .js-chat-resize {
  147. resize: both;
  148. overflow: auto; }
  149. .js-map {
  150. /* This makes sure scroll bars don't appear when resizing the map */
  151. overflow: hidden; }
  152.  
  153. .js-map-resize:hover {
  154. resize: both;
  155. overflow: auto;
  156. direction: rtl; }
  157. /* Allows last clicked window to appear above all other windows */
  158. .js-is-top {
  159. z-index: 9998 !important; }
  160.  
  161. .panel.context:not(.commandlist) {
  162. z-index: 9999 !important; }
  163.  
  164. /* The item icon being dragged in the inventory */
  165. .container.svelte-120o2pb {
  166. z-index: 9999 !important; }
  167. .container.uimod-xpmeter-1 {
  168. z-index: 6; }
  169.  
  170. .window.uimod-xpmeter-2 {
  171. padding: 5px;
  172. height: 100%;
  173. display: grid;
  174. grid-template-rows: 30px 1fr;
  175. grid-gap: 4px;
  176. transform-origin: inherit;
  177. min-width: fit-content; }
  178.  
  179. .titleframe.uimod-xpmeter-2 {
  180. line-height: 1em;
  181. display: flex;
  182. align-items: center;
  183. position: relative;
  184. letter-spacing: 0.5px; }
  185.  
  186. .titleicon.uimod-xpmeter-2 {
  187. margin: 3px; }
  188.  
  189. .title.uimod-xpmeter-2 {
  190. width: 100%;
  191. padding-left: 4px;
  192. font-weight: bold; }
  193.  
  194. .slot.uimod-xpmeter-2 {
  195. min-height: 0; }
  196.  
  197. .wrapper.uimod-xpmeter-1 {
  198. width: 200px; }
  199.  
  200. .bar.uimod-xpmeter-3 {
  201. background-color: rgba(45, 66, 71, 0.7);
  202. border-radius: 1.5px;
  203. position: relative;
  204. color: #DAE8EA;
  205. overflow: hidden;
  206. text-shadow: 1px 1px 2px #10131d;
  207. white-space: nowrap;
  208. text-transform: capitalize;
  209. font-weight: bold; }
  210.  
  211. .buttons.uimod-xpmeter-1 {
  212. line-height: 1;
  213. font-size: 13px; }
  214.  
  215. .left.uimod-xpmeter-3 {
  216. padding-left: 4px;
  217. position: relative;
  218. z-index: 1; }
  219.  
  220. .right.uimod-xpmeter-3 {
  221. position: absolute;
  222. right: 7px;
  223. z-index: 1; }
  224. /* This file is for CSS mods that don't fit in any other individual mod folder */
  225. /* Transparent chat bg color */
  226. .frame.svelte-1vrlsr3 {
  227. background: rgba(0, 0, 0, 0.4); }
  228.  
  229. /* Our mod's chat message color */
  230. .textuimod {
  231. color: #00dd33; }
  232.  
  233. /* The browser resize icon */
  234. *::-webkit-resizer {
  235. background: linear-gradient(to right, rgba(51, 77, 80, 0), rgba(203, 202, 165, 0.5));
  236. border-radius: 8px;
  237. box-shadow: 0 1px 1px black; }
  238.  
  239. *::-moz-resizer {
  240. background: linear-gradient(to right, rgba(51, 77, 80, 0), rgba(203, 202, 165, 0.5));
  241. border-radius: 8px;
  242. box-shadow: 0 1px 1px black; }
  243.  
  244. /* Our custom window, closely mirrors main settings window */
  245. .uimod-custom-window {
  246. position: absolute;
  247. top: 100px;
  248. left: 50%;
  249. transform: translate(-50%, 0);
  250. min-width: 350px;
  251. max-width: 600px;
  252. width: 90%;
  253. height: 80%;
  254. min-height: 350px;
  255. max-height: 500px;
  256. z-index: 9;
  257. padding: 0px 10px 5px; }
  258. `);
  259.  
  260. (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  261. "use strict";
  262.  
  263. var _mods = _interopRequireDefault(require("./mods"));
  264.  
  265. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  266.  
  267. function initialize() {
  268. // If the Hordes.io tab isn't active for long enough, it reloads the entire page, clearing this mod
  269. // We check for that and reinitialize the mod if that happens
  270. const $layout = document.querySelector('.layout');
  271.  
  272. if ($layout.classList.contains('uimod-initd')) {
  273. return;
  274. }
  275.  
  276. $layout.classList.add('uimod-initd');
  277. const rerunning = {
  278. // MutationObserver running whenever .layout changes
  279. onDomChange: [],
  280. // Mutation observer running whenever #chat changes
  281. onChatChange: [],
  282. // `click` Event listener running on document.body
  283. onLeftClick: [],
  284. // `contextmenu` Event listener running on document.body
  285. onRightClick: []
  286. }; // Run all our mods
  287.  
  288. const registerOnDomChange = callback => rerunning.onDomChange.push(callback);
  289.  
  290. const registerOnChatChange = callback => rerunning.onChatChange.push(callback);
  291.  
  292. const registerOnLeftClick = callback => rerunning.onLeftClick.push(callback);
  293.  
  294. const registerOnRightClick = callback => rerunning.onRightClick.push(callback);
  295.  
  296. _mods.default.forEach(mod => {
  297. mod.run({
  298. registerOnDomChange,
  299. registerOnChatChange,
  300. registerOnLeftClick,
  301. registerOnRightClick
  302. });
  303. }); // Continuously re-run specific mods methods that need to be executed on UI change
  304.  
  305.  
  306. const rerunObserver = new MutationObserver(() => {
  307. // If new window appears, e.g. even if window is closed and reopened, we need to rewire it
  308. // Fun fact: Some windows always exist in the DOM, even when hidden, e.g. Inventory
  309. // But some windows only exist in the DOM when open, e.g. Interaction
  310. rerunning.onDomChange.forEach(callback => callback());
  311. });
  312. rerunObserver.observe(document.querySelector('.layout > .container'), {
  313. attributes: false,
  314. childList: true
  315. }); // Rerun only on chat messages changing
  316.  
  317. const chatRerunObserver = new MutationObserver(() => {
  318. rerunning.onChatChange.forEach(callback => callback());
  319. });
  320. chatRerunObserver.observe(document.querySelector('#chat'), {
  321. attributes: false,
  322. childList: true
  323. }); // Event listeners for document.body might be kept when the game reloads, so don't reinitialize them
  324.  
  325. if (!document.body.classList.contains('js-uimod-initd')) {
  326. document.body.classList.add('js-uimod-initd');
  327. rerunning.onLeftClick.forEach(callback => document.body.addEventListener('click', callback));
  328. rerunning.onRightClick.forEach(callback => document.body.addEventListener('contextmenu', callback));
  329. }
  330. } // Initialize mods once UI DOM has loaded
  331. // Rerunning updates on every call to initialize
  332.  
  333.  
  334. const pageObserver = new MutationObserver(() => {
  335. const isUiLoaded = !!document.querySelector('.layout');
  336.  
  337. if (isUiLoaded) {
  338. initialize();
  339. }
  340. });
  341. pageObserver.observe(document.body, {
  342. attributes: true,
  343. childList: true
  344. });
  345.  
  346. },{"./mods":13}],2:[function(require,module,exports){
  347. "use strict";
  348.  
  349. Object.defineProperty(exports, "__esModule", {
  350. value: true
  351. });
  352. exports.default = void 0;
  353.  
  354. var _state = require("../../utils/state");
  355.  
  356. // Note: For a split second after these event handlers are added,
  357. // They may not actually be listening.
  358. // e.g. Refresh page with inventory open, immediately control+right click item
  359. // to copy its stats. It won't work because `keydown` didn't register the keydown event yet
  360. // Doesn't look like there's anything we can do about it, just something to keep in mind.
  361. function keyPressTracker() {
  362. const tempState = (0, _state.getTempState)();
  363. window.addEventListener('keydown', keyEvent => {
  364. if (keyEvent.key === 'Control') {
  365. tempState.keyModifiers.control = true;
  366. } else if (keyEvent.key === 'Alt') {
  367. tempState.keyModifiers.alt = true;
  368. } else if (keyEvent.key === 'Shift') {
  369. // Shouldn't set keyModifiers.shift if we're programatically doing it while getting tooltip content
  370. // tempState.gettingTooltipContentShiftPress should only be `true` if user already isn't pressing shift
  371. // See game.js `getTooltipContent` for more details
  372. if (tempState.gettingTooltipContentShiftPress) {
  373. return;
  374. }
  375.  
  376. tempState.keyModifiers.shift = true;
  377. }
  378. });
  379. window.addEventListener('keyup', keyEvent => {
  380. if (keyEvent.key === 'Control') {
  381. tempState.keyModifiers.control = false;
  382. } else if (keyEvent.key === 'Alt') {
  383. tempState.keyModifiers.alt = false;
  384. } else if (keyEvent.key === 'Shift') {
  385. tempState.keyModifiers.shift = false;
  386. }
  387. }); // If page ever regains focus, e.g. tabbing back in after tabbing out, make sure we reset our modifiers.
  388. // This prevents things like holding control, leaving the tab without releasing it, then coming back in and
  389. // the game will think you are still holding it, even if you're not.
  390.  
  391. window.addEventListener('focus', () => {
  392. tempState.keyModifiers.control = false;
  393. tempState.keyModifiers.alt = false;
  394. tempState.keyModifiers.shift = false;
  395. });
  396. }
  397.  
  398. var _default = {
  399. name: '[REQUIRED] Key press tracker',
  400. description: 'Identifies when you are pressing Ctrl/etc key modifiers, which is used by some other mods',
  401. run: keyPressTracker
  402. };
  403. exports.default = _default;
  404.  
  405. },{"../../utils/state":29}],3:[function(require,module,exports){
  406. "use strict";
  407.  
  408. Object.defineProperty(exports, "__esModule", {
  409. value: true
  410. });
  411. exports.default = void 0;
  412.  
  413. var chat = _interopRequireWildcard(require("../../utils/chat"));
  414.  
  415. var _version = require("../../utils/version");
  416.  
  417. var _state = require("../../utils/state");
  418.  
  419. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  420.  
  421. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  422.  
  423. function modStart() {
  424. chat.addChatMessage(`Hordes UI Mod v${_version.VERSION} is now running.`);
  425. (0, _state.loadState)();
  426. }
  427.  
  428. var _default = {
  429. name: '[REQUIRED] UI Mod Startup',
  430. description: 'Do not remove this! This displays a welcome message, loads saved state, and includes misc styles.',
  431. run: modStart
  432. };
  433. exports.default = _default;
  434.  
  435. },{"../../utils/chat":25,"../../utils/state":29,"../../utils/version":31}],4:[function(require,module,exports){
  436. "use strict";
  437.  
  438. Object.defineProperty(exports, "__esModule", {
  439. value: true
  440. });
  441. exports.default = void 0;
  442.  
  443. var _misc = require("../../utils/misc");
  444.  
  445. var _ui = require("../../utils/ui");
  446.  
  447. var _state = require("../../utils/state");
  448.  
  449. function blockedPlayerSettings() {
  450. const state = (0, _state.getState)();
  451. const $settings = document.querySelector('.divide:not(.js-settings-initd)');
  452.  
  453. if (!$settings) {
  454. return;
  455. }
  456.  
  457. $settings.classList.add('js-settings-initd');
  458. const $settingsChoiceList = $settings.querySelector('.choice').parentNode;
  459. $settingsChoiceList.appendChild((0, _misc.makeElement)({
  460. element: 'div',
  461. class: 'choice js-blocked-players',
  462. content: 'Blocked players'
  463. })); // Upon click, we display our custom settings window UI
  464.  
  465. document.querySelector('.js-blocked-players').addEventListener('click', _ui.createBlockList); // If it was open when the game last closed keep it open
  466.  
  467. if (state.openWindows.openBlockList) {
  468. (0, _ui.createBlockList)();
  469. }
  470. }
  471.  
  472. var _default = {
  473. name: 'Blocked Players List',
  474. description: 'Allows you to view and remove blocked players from the Settings window',
  475. run: ({
  476. registerOnDomChange
  477. }) => {
  478. blockedPlayerSettings(); // If the settings window becomes visible/invisible, we want to update it
  479.  
  480. registerOnDomChange(blockedPlayerSettings);
  481. }
  482. };
  483. exports.default = _default;
  484.  
  485. },{"../../utils/misc":27,"../../utils/state":29,"../../utils/ui":30}],5:[function(require,module,exports){
  486. "use strict";
  487.  
  488. Object.defineProperty(exports, "__esModule", {
  489. value: true
  490. });
  491. exports.showChatContextMenu = showChatContextMenu;
  492.  
  493. var _state = require("../../utils/state");
  494.  
  495. // Makes chat context menu visible and appear under the mouse
  496. function showChatContextMenu(name, mousePos) {
  497. const state = (0, _state.getState)(); // Right before we show the context menu, we want to handle showing/hiding Friend/Unfriend
  498.  
  499. const $contextMenu = document.querySelector('.js-chat-context-menu');
  500. $contextMenu.querySelector('[name="friend"]').classList.toggle('js-hidden', !!state.friendsList[name]);
  501. $contextMenu.querySelector('[name="unfriend"]').classList.toggle('js-hidden', !state.friendsList[name]);
  502. $contextMenu.querySelector('.js-name').textContent = name;
  503. $contextMenu.setAttribute('style', `display: block; left: ${mousePos.x}px; top: ${mousePos.y}px;`);
  504. }
  505.  
  506. },{"../../utils/state":29}],6:[function(require,module,exports){
  507. "use strict";
  508.  
  509. Object.defineProperty(exports, "__esModule", {
  510. value: true
  511. });
  512. exports.default = void 0;
  513.  
  514. var _state = require("../../utils/state");
  515.  
  516. var _misc = require("../../utils/misc");
  517.  
  518. var helpers = _interopRequireWildcard(require("./helpers"));
  519.  
  520. var chat = _interopRequireWildcard(require("../../utils/chat"));
  521.  
  522. var player = _interopRequireWildcard(require("../../utils/player"));
  523.  
  524. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  525.  
  526. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  527.  
  528. // This creates the initial chat context menu DOM (which starts as hidden)
  529. function createChatContextMenu() {
  530. const tempState = (0, _state.getTempState)();
  531.  
  532. if (document.querySelector('.js-chat-context-menu')) {
  533. return;
  534. }
  535.  
  536. let contextMenuHTML = `
  537. <div class="js-name">...</div>
  538. <div class="choice" name="party">Party invite</div>
  539. <div class="choice" name="whisper">Whisper</div>
  540. <div class="choice" name="friend">Friend</div>
  541. <div class="choice" name="unfriend">Unfriend</div>
  542. <div class="choice" name="copy">Copy name</div>
  543. <div class="choice" name="block">Block</div>
  544. `;
  545. document.body.appendChild((0, _misc.makeElement)({
  546. element: 'div',
  547. class: 'panel context border grey js-chat-context-menu',
  548. content: contextMenuHTML
  549. }));
  550. const $chatContextMenu = document.querySelector('.js-chat-context-menu');
  551. $chatContextMenu.querySelector('[name="party"]').addEventListener('click', () => {
  552. chat.partyPlayer(tempState.chatName);
  553. });
  554. $chatContextMenu.querySelector('[name="whisper"]').addEventListener('click', () => {
  555. chat.whisperPlayer(tempState.chatName);
  556. });
  557. $chatContextMenu.querySelector('[name="friend"]').addEventListener('click', () => {
  558. player.friendPlayer(tempState.chatName);
  559. });
  560. $chatContextMenu.querySelector('[name="unfriend"]').addEventListener('click', () => {
  561. player.unfriendPlayer(tempState.chatName);
  562. });
  563. $chatContextMenu.querySelector('[name="copy"]').addEventListener('click', () => {
  564. navigator.clipboard.writeText(tempState.chatName);
  565. });
  566. $chatContextMenu.querySelector('[name="block"]').addEventListener('click', () => {
  567. player.blockPlayer(tempState.chatName);
  568. });
  569. } // This opens a context menu when you click a user's name in chat
  570.  
  571.  
  572. function chatContextMenu() {
  573. const tempState = (0, _state.getTempState)();
  574.  
  575. const addContextMenu = ($name, name) => {
  576. $name.classList.add('js-is-context-menu-initd'); // Add name to element so we can target it in CSS when filtering chat for block list
  577.  
  578. $name.setAttribute('data-chat-name', name);
  579.  
  580. const showContextMenu = clickEvent => {
  581. // TODO: Is there a way to pass the name to showChatContextMenumethod, instead of storing in tempState?
  582. tempState.chatName = name;
  583. helpers.showChatContextMenu(name, {
  584. x: clickEvent.pageX,
  585. y: clickEvent.pageY
  586. });
  587. };
  588.  
  589. $name.addEventListener('click', showContextMenu); // Left click
  590.  
  591. $name.addEventListener('contextmenu', showContextMenu); // Right click works too
  592. };
  593.  
  594. Array.from(document.querySelectorAll('#chat .name:not(.js-is-context-menu-initd)')).forEach($name => {
  595. addContextMenu($name, $name.textContent);
  596. }); // `textf0` is the VG faction, `textf1` is the BL faction - we want to support both with our whisper context menu
  597.  
  598. Array.from(document.querySelectorAll('.textwhisper .textf1:not(.js-is-context-menu-initd), .textwhisper .textf0:not(.js-is-context-menu-initd)')).forEach($whisperName => {
  599. // $whisperName's textContent is "to [name]" or "from [name]", so we cut off the first word
  600. let name = $whisperName.textContent.split(' ');
  601. name.shift(); // Remove the first word
  602.  
  603. name = name.join(' ');
  604. addContextMenu($whisperName, name);
  605. });
  606. } // Close chat context menu if clicking outside of it
  607.  
  608.  
  609. function closeChatContextMenu(clickEvent) {
  610. const $target = clickEvent.target; // If clicking on name or directly on context menu, don't close it
  611. // Still closes if clicking on context menu item
  612.  
  613. if ($target.classList.contains('js-is-context-menu-initd') || $target.classList.contains('js-chat-context-menu')) {
  614. return;
  615. }
  616.  
  617. const $contextMenu = document.querySelector('.js-chat-context-menu');
  618. $contextMenu.style.display = 'none';
  619. }
  620.  
  621. var _default = {
  622. name: 'Chat Context Menu',
  623. description: 'Displays a menu when you click on a player, allowing you to whisper/party/friend/block them',
  624. run: ({
  625. registerOnLeftClick,
  626. registerOnChatChange
  627. }) => {
  628. createChatContextMenu();
  629. chatContextMenu(); // When we click anywhere on the page outside of our chat context menu, we want to close the menu
  630.  
  631. registerOnLeftClick(closeChatContextMenu); // Register event listeners for each name when a new chat message appears
  632.  
  633. registerOnChatChange(chatContextMenu);
  634. }
  635. };
  636. exports.default = _default;
  637.  
  638. },{"../../utils/chat":25,"../../utils/misc":27,"../../utils/player":28,"../../utils/state":29,"./helpers":5}],7:[function(require,module,exports){
  639. "use strict";
  640.  
  641. Object.defineProperty(exports, "__esModule", {
  642. value: true
  643. });
  644. exports.default = void 0;
  645.  
  646. var chat = _interopRequireWildcard(require("../../utils/chat"));
  647.  
  648. var _state = require("../../utils/state");
  649.  
  650. var _misc = require("../../utils/misc");
  651.  
  652. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  653.  
  654. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  655.  
  656. // Creates DOM elements for custom chat filters
  657. function newChatFilters() {
  658. const state = (0, _state.getState)();
  659. const $channelselect = document.querySelector('.channelselect');
  660.  
  661. if (!document.querySelector(`.js-chat-gm`)) {
  662. const $gm = (0, _misc.makeElement)({
  663. element: 'small',
  664. class: `btn border black js-chat-gm ${state.chat.GM ? '' : 'textgrey'}`,
  665. content: 'GM'
  666. });
  667. $channelselect.appendChild($gm);
  668. }
  669. } // Wire up new chat buttons to toggle in state+ui
  670.  
  671.  
  672. function newChatFilterButtons() {
  673. const state = (0, _state.getState)();
  674. const $chatGM = document.querySelector(`.js-chat-gm`);
  675. $chatGM.addEventListener('click', () => {
  676. chat.setGMChatVisibility(!state.chat.GM);
  677. });
  678. }
  679.  
  680. var _default = {
  681. name: 'Chat filters',
  682. description: 'Enables custom chat filters: GM chat',
  683. run: ({
  684. registerOnChatChange
  685. }) => {
  686. newChatFilters();
  687. newChatFilterButtons(); // Whenever chat changes, we want to filter it
  688.  
  689. registerOnChatChange(chat.filterAllChat);
  690. }
  691. };
  692. exports.default = _default;
  693.  
  694. },{"../../utils/chat":25,"../../utils/misc":27,"../../utils/state":29}],8:[function(require,module,exports){
  695. "use strict";
  696.  
  697. Object.defineProperty(exports, "__esModule", {
  698. value: true
  699. });
  700. exports.showChatTabConfigWindow = showChatTabConfigWindow;
  701. exports.addChatTab = addChatTab;
  702. exports.selectChatTab = selectChatTab;
  703. exports.getCurrentChatFilters = getCurrentChatFilters;
  704.  
  705. var chat = _interopRequireWildcard(require("../../utils/chat"));
  706.  
  707. var _state = require("../../utils/state");
  708.  
  709. var _misc = require("../../utils/misc");
  710.  
  711. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  712.  
  713. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  714.  
  715. const DEFAULT_CHAT_TAB_NAME = 'Untitled'; // Gets current chat filters as represented in the UI
  716. // filter being true means it's invisible(filtered) in chat
  717. // filter being false means it's visible(unfiltered) in chat
  718.  
  719. function getCurrentChatFilters() {
  720. const state = (0, _state.getState)(); // Saved by the official game client
  721.  
  722. const gameFilters = JSON.parse(localStorage.getItem('filteredChannels'));
  723. return {
  724. global: gameFilters.includes('global'),
  725. faction: gameFilters.includes('faction'),
  726. party: gameFilters.includes('party'),
  727. clan: gameFilters.includes('clan'),
  728. pvp: gameFilters.includes('pvp'),
  729. inv: gameFilters.includes('inv'),
  730. GM: !state.chat.GM // state.chat.GM is whether or not GM chat is shown - we want whether or not GM chat should be hidden
  731.  
  732. };
  733. } // Shows the chat tab config window for a specific tab, displayed in a specific position
  734.  
  735.  
  736. function showChatTabConfigWindow(tabId, pos) {
  737. const state = (0, _state.getState)();
  738. const tempState = (0, _state.getTempState)();
  739. const $chatTabConfig = document.querySelector('.js-chat-tab-config');
  740. const chatTab = state.chatTabs.find(tab => tab.id === tabId); // Update position and name in chat tab config
  741.  
  742. $chatTabConfig.style.left = `${pos.x}px`;
  743. $chatTabConfig.style.top = `${pos.y}px`;
  744. $chatTabConfig.querySelector('.js-chat-tab-name').value = chatTab.name; // Store tabId in state, to be used by the Remove/Add buttons in config window
  745.  
  746. tempState.editedChatTabId = tabId; // Hide remove button if only one chat tab left - can't remove last one
  747. // Show it if more than one chat tab left
  748.  
  749. const chatTabCount = Object.keys(state.chatTabs).length;
  750. const $removeChatTabBtn = $chatTabConfig.querySelector('.js-remove-chat-tab');
  751. $removeChatTabBtn.style.display = chatTabCount < 2 ? 'none' : 'block'; // Show chat tab config
  752.  
  753. $chatTabConfig.style.display = 'block';
  754. } // Adds chat tab to DOM, sets it as selected
  755. // If argument chatTab is provided, will use that name+id
  756. // If no argument is provided, will create new tab name/id and add it to state
  757. // isInittingTab is optional boolean, if `true`, will _not_ set added tab as selected. Used when initializing all chat tabs on load
  758. // Returns newly added tabId
  759.  
  760.  
  761. function addChatTab(chatTab, isInittingTab) {
  762. const state = (0, _state.getState)();
  763. let tabName = DEFAULT_CHAT_TAB_NAME;
  764. let tabId = (0, _misc.uuid)();
  765.  
  766. if (chatTab) {
  767. tabName = chatTab.name;
  768. tabId = chatTab.id;
  769. } else {
  770. // If no chat tab was provided, create it in state
  771. state.chatTabs.push({
  772. name: tabName,
  773. id: tabId,
  774. filters: getCurrentChatFilters()
  775. });
  776. (0, _state.saveState)();
  777. }
  778.  
  779. const $tabs = document.querySelector('.js-chat-tabs');
  780. const $tab = (0, _misc.makeElement)({
  781. element: 'div',
  782. content: tabName
  783. });
  784. $tab.setAttribute('data-tab-id', tabId); // Add chat tab to DOM
  785.  
  786. $tabs.appendChild($tab); // Wire chat tab up to open config on right click
  787.  
  788. $tab.addEventListener('contextmenu', clickEvent => {
  789. const mousePos = {
  790. x: clickEvent.pageX,
  791. y: clickEvent.pageY
  792. };
  793. showChatTabConfigWindow(tabId, mousePos);
  794. }); // And select chat tab on left click
  795.  
  796. $tab.addEventListener('click', () => {
  797. selectChatTab(tabId);
  798. });
  799.  
  800. if (!isInittingTab) {
  801. // Select the newly added chat tab
  802. selectChatTab(tabId);
  803. } // Returning tabId to all adding new tab to pass tab ID to `showChatTabConfigWindow`
  804.  
  805.  
  806. return tabId;
  807. } // Selects chat tab [on click], updating client chat filters and custom chat filters
  808.  
  809.  
  810. function selectChatTab(tabId) {
  811. const state = (0, _state.getState)(); // Remove selected class from everything, then add selected class to clicked tab
  812.  
  813. Array.from(document.querySelectorAll('[data-tab-id]')).forEach($tab => {
  814. $tab.classList.remove('js-selected-tab');
  815. });
  816. const $tab = document.querySelector(`[data-tab-id="${tabId}"]`);
  817. $tab.classList.add('js-selected-tab');
  818. const tabFilters = state.chatTabs.find(tab => tab.id === tabId).filters; // Simulating clicks on the filters to turn them on/off
  819.  
  820. const $filterButtons = Array.from(document.querySelectorAll('.channelselect small'));
  821. Object.keys(tabFilters).forEach(filter => {
  822. const $filterButton = $filterButtons.find($btn => $btn.textContent === filter);
  823. const isCurrentlyFiltered = $filterButton.classList.contains('textgrey'); // If is currently filtered but filter for this tab is turned off, click it to turn filter off
  824.  
  825. if (isCurrentlyFiltered && !tabFilters[filter]) {
  826. $filterButton.click();
  827. } // If it is not currently filtered but filter for this tab is turned on, click it to turn filter on
  828.  
  829.  
  830. if (!isCurrentlyFiltered && tabFilters[filter]) {
  831. $filterButton.click();
  832. }
  833. }); // Update state for our custom chat filters to match the tab's configuration, then filter chat for it
  834.  
  835. const isGMChatVisible = !tabFilters.GM;
  836. chat.setGMChatVisibility(isGMChatVisible); // Update the selected tab in state
  837.  
  838. state.selectedChatTabId = tabId;
  839. (0, _state.saveState)();
  840. }
  841.  
  842. },{"../../utils/chat":25,"../../utils/misc":27,"../../utils/state":29}],9:[function(require,module,exports){
  843. "use strict";
  844.  
  845. Object.defineProperty(exports, "__esModule", {
  846. value: true
  847. });
  848. exports.default = void 0;
  849.  
  850. var helpers = _interopRequireWildcard(require("./helpers"));
  851.  
  852. var _state = require("../../utils/state");
  853.  
  854. var _misc = require("../../utils/misc");
  855.  
  856. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  857.  
  858. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  859.  
  860. // Creates DOM elements and wires them up for custom chat tabs and chat tab config
  861. // Note: Should be done after creating new custom chat filters
  862. function customChatTabs() {
  863. const state = (0, _state.getState)();
  864. const tempState = (0, _state.getTempState)(); // Create the chat tab configuration DOM
  865.  
  866. const $chatTabConfigurator = (0, _misc.makeElement)({
  867. element: 'div',
  868. class: 'uimod-chat-tab-config js-chat-tab-config',
  869. content: `
  870. <h1>Chat Tab Config</h1>
  871. <div class="uimod-chat-tab-config-grid">
  872. <div>Name</div><input type="text" class="js-chat-tab-name" value="untitled"></input>
  873. <div class="btn orange js-remove-chat-tab">Remove</div><div class="btn blue js-save-chat-tab">Ok</div>
  874. </div>
  875. `
  876. });
  877. document.body.append($chatTabConfigurator); // Wire it up
  878.  
  879. document.querySelector('.js-remove-chat-tab').addEventListener('click', () => {
  880. // Remove the chat tab from state
  881. const editedChatTab = state.chatTabs.find(tab => tab.id === tempState.editedChatTabId);
  882. const editedChatTabIndex = state.chatTabs.indexOf(editedChatTab);
  883. state.chatTabs.splice(editedChatTabIndex, 1); // Remove the chat tab from DOM
  884.  
  885. const $chatTab = document.querySelector(`[data-tab-id="${tempState.editedChatTabId}"]`);
  886. $chatTab.parentNode.removeChild($chatTab); // If we just removed the currently selected chat tab
  887.  
  888. if (tempState.editedChatTabId === state.selectedChatTabId) {
  889. // Select the chat tab to the left of the removed one
  890. const nextChatTabIndex = editedChatTabIndex === 0 ? 0 : editedChatTabIndex - 1;
  891. helpers.selectChatTab(state.chatTabs[nextChatTabIndex].id);
  892. } // Close chat tab config
  893.  
  894.  
  895. document.querySelector('.js-chat-tab-config').style.display = 'none';
  896. });
  897. document.querySelector('.js-save-chat-tab').addEventListener('click', () => {
  898. // Set new chat tab name in DOM
  899. const $chatTab = document.querySelector(`[data-tab-id="${state.selectedChatTabId}"]`);
  900. const newName = document.querySelector('.js-chat-tab-name').value;
  901. $chatTab.textContent = newName; // Set new chat tab name in state
  902. // `selectedChatTab` is a reference on `state.chatTabs`, so updating it above still updates it in the state - we want to save that
  903.  
  904. const selectedChatTab = state.chatTabs.find(tab => tab.id === state.selectedChatTabId);
  905. selectedChatTab.name = newName;
  906. (0, _state.saveState)(); // Close chat tab config
  907.  
  908. document.querySelector('.js-chat-tab-config').style.display = 'none';
  909. }); // Create the initial chat tabs HTML
  910.  
  911. const $chat = document.querySelector('#chat');
  912. const $chatTabs = (0, _misc.makeElement)({
  913. element: 'div',
  914. class: 'uimod-chat-tabs js-chat-tabs',
  915. content: '<div class="js-chat-tab-add">+</div>'
  916. }); // Add them to the DOM
  917.  
  918. $chat.parentNode.insertBefore($chatTabs, $chat); // Add all our chat tabs from state
  919.  
  920. state.chatTabs.forEach(chatTab => {
  921. const isInittingTab = true;
  922. helpers.addChatTab(chatTab, isInittingTab);
  923. }); // Wire up the add chat tab button
  924.  
  925. document.querySelector('.js-chat-tab-add').addEventListener('click', clickEvent => {
  926. const chatTabId = helpers.addChatTab();
  927. const mousePos = {
  928. x: clickEvent.pageX,
  929. y: clickEvent.pageY
  930. };
  931. helpers.showChatTabConfigWindow(chatTabId, mousePos);
  932. }); // If initial chat tab doesn't exist, create it based off current filter settings
  933.  
  934. if (!Object.keys(state.chatTabs).length) {
  935. const tabId = (0, _misc.uuid)();
  936. const chatTab = {
  937. name: 'Main',
  938. id: tabId,
  939. filters: helpers.getCurrentChatFilters()
  940. };
  941. state.chatTabs.push(chatTab);
  942. (0, _state.saveState)();
  943. helpers.addChatTab(chatTab);
  944. } // Wire up click event handlers onto the filters to update the selected chat tab's filters in state
  945.  
  946.  
  947. document.querySelector('.channelselect').addEventListener('click', clickEvent => {
  948. const $elementMouseIsOver = document.elementFromPoint(clickEvent.clientX, clickEvent.clientY); // We only want to change the filters if the user manually clicks the filter button
  949. // If they clicked a chat tab and we programatically set filters, we don't want to update
  950. // the current tab's filter state
  951.  
  952. if (!$elementMouseIsOver.classList.contains('btn')) {
  953. return;
  954. }
  955.  
  956. const selectedChatTab = state.chatTabs.find(tab => tab.id === state.selectedChatTabId);
  957. selectedChatTab.filters = helpers.getCurrentChatFilters();
  958. (0, _state.saveState)();
  959. }); // Select the currently selected tab in state on mod initialization
  960.  
  961. if (state.selectedChatTabId) {
  962. helpers.selectChatTab(state.selectedChatTabId);
  963. }
  964. }
  965.  
  966. var _default = {
  967. name: 'Chat tabs',
  968. description: 'Enables support for multiple chat tabs',
  969. run: customChatTabs
  970. };
  971. exports.default = _default;
  972.  
  973. },{"../../utils/misc":27,"../../utils/state":29,"./helpers":8}],10:[function(require,module,exports){
  974. "use strict";
  975.  
  976. Object.defineProperty(exports, "__esModule", {
  977. value: true
  978. });
  979. exports.dragElement = dragElement;
  980.  
  981. // Credit: https://stackoverflow.com/a/14234618 (Has been slightly modified)
  982. // $draggedElement is the item that will be dragged.
  983. // $dragTrigger is the element that must be held down to drag $draggedElement
  984. function dragElement($draggedElement, $dragTrigger) {
  985. let offset = [0, 0];
  986. let isDown = false;
  987. $dragTrigger.addEventListener('mousedown', function (e) {
  988. isDown = true;
  989. offset = [$draggedElement.offsetLeft - e.clientX, $draggedElement.offsetTop - e.clientY];
  990. }, true);
  991. document.addEventListener('mouseup', function () {
  992. isDown = false;
  993. }, true);
  994. document.addEventListener('mousemove', function (e) {
  995. e.preventDefault();
  996.  
  997. if (isDown) {
  998. $draggedElement.style.left = e.clientX + offset[0] + 'px';
  999. $draggedElement.style.top = e.clientY + offset[1] + 'px';
  1000. }
  1001. }, true);
  1002. }
  1003.  
  1004. },{}],11:[function(require,module,exports){
  1005. "use strict";
  1006.  
  1007. Object.defineProperty(exports, "__esModule", {
  1008. value: true
  1009. });
  1010. exports.default = void 0;
  1011.  
  1012. var helpers = _interopRequireWildcard(require("./helpers"));
  1013.  
  1014. var _state = require("../../utils/state");
  1015.  
  1016. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  1017.  
  1018. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  1019.  
  1020. // Drag all windows by their header
  1021. function draggableUIWindows() {
  1022. Array.from(document.querySelectorAll('.window:not(.js-can-move)')).forEach($window => {
  1023. $window.classList.add('js-can-move');
  1024. helpers.dragElement($window, $window.querySelector('.titleframe'));
  1025. });
  1026. } // Save dragged UI windows position to state
  1027.  
  1028.  
  1029. function saveDraggedUIWindows() {
  1030. const state = (0, _state.getState)();
  1031. Array.from(document.querySelectorAll('.window:not(.js-window-is-saving)')).forEach($window => {
  1032. $window.classList.add('js-window-is-saving');
  1033. const $draggableTarget = $window.querySelector('.titleframe');
  1034. const windowName = $draggableTarget.querySelector('[name="title"]').textContent;
  1035. $draggableTarget.addEventListener('mouseup', () => {
  1036. state.windowsPos[windowName] = $window.getAttribute('style');
  1037. (0, _state.saveState)();
  1038. });
  1039. });
  1040. } // Loads draggable UI windows position from state
  1041.  
  1042.  
  1043. function loadDraggedUIWindowsPositions() {
  1044. const state = (0, _state.getState)();
  1045. Array.from(document.querySelectorAll('.window:not(.js-has-loaded-pos)')).forEach($window => {
  1046. $window.classList.add('js-has-loaded-pos');
  1047. const windowName = $window.querySelector('[name="title"]').textContent;
  1048. const pos = state.windowsPos[windowName];
  1049.  
  1050. if (pos) {
  1051. $window.setAttribute('style', pos);
  1052. }
  1053. });
  1054. }
  1055.  
  1056. var _default = {
  1057. name: 'Draggable Windows',
  1058. description: 'Allows you to drag windows in the UI',
  1059. run: ({
  1060. registerOnDomChange
  1061. }) => {
  1062. draggableUIWindows();
  1063. saveDraggedUIWindows();
  1064. loadDraggedUIWindowsPositions(); // As windows open, we want to make them draggable
  1065.  
  1066. registerOnDomChange(saveDraggedUIWindows);
  1067. registerOnDomChange(draggableUIWindows);
  1068. registerOnDomChange(loadDraggedUIWindowsPositions);
  1069. }
  1070. };
  1071. exports.default = _default;
  1072.  
  1073. },{"../../utils/state":29,"./helpers":10}],12:[function(require,module,exports){
  1074. "use strict";
  1075.  
  1076. Object.defineProperty(exports, "__esModule", {
  1077. value: true
  1078. });
  1079. exports.default = void 0;
  1080.  
  1081. var _misc = require("../../utils/misc");
  1082.  
  1083. var _ui = require("../../utils/ui");
  1084.  
  1085. var _state = require("../../utils/state");
  1086.  
  1087. // The F icon and the UI that appears when you click it
  1088. function customFriendsList() {
  1089. const state = (0, _state.getState)();
  1090. var friendsIconElement = (0, _misc.makeElement)({
  1091. element: 'div',
  1092. class: 'btn border black js-friends-list-icon',
  1093. content: 'F'
  1094. }); // Add the icon to the right of Elixir icon
  1095.  
  1096. const $elixirIcon = document.querySelector('#sysgem');
  1097. $elixirIcon.parentNode.insertBefore(friendsIconElement, $elixirIcon.nextSibling); // Create the friends list UI
  1098.  
  1099. document.querySelector('.js-friends-list-icon').addEventListener('click', _ui.createFriendsList); // If it was open when the game last closed keep it open
  1100.  
  1101. if (state.openWindows.openFriendsList) {
  1102. (0, _ui.createFriendsList)();
  1103. }
  1104. }
  1105.  
  1106. var _default = {
  1107. name: 'Friends list',
  1108. description: 'Allows access to your friends list from the top right F icon',
  1109. run: customFriendsList
  1110. };
  1111. exports.default = _default;
  1112.  
  1113. },{"../../utils/misc":27,"../../utils/state":29,"../../utils/ui":30}],13:[function(require,module,exports){
  1114. "use strict";
  1115.  
  1116. Object.defineProperty(exports, "__esModule", {
  1117. value: true
  1118. });
  1119. exports.default = void 0;
  1120.  
  1121. var _modStart = _interopRequireDefault(require("./_modStart"));
  1122.  
  1123. var _blockedPlayerSettings = _interopRequireDefault(require("./blockedPlayerSettings"));
  1124.  
  1125. var _chatContextMenu = _interopRequireDefault(require("./chatContextMenu"));
  1126.  
  1127. var _chatFilters = _interopRequireDefault(require("./chatFilters"));
  1128.  
  1129. var _chatTabs = _interopRequireDefault(require("./chatTabs"));
  1130.  
  1131. var _draggableUI = _interopRequireDefault(require("./draggableUI"));
  1132.  
  1133. var _friendsList = _interopRequireDefault(require("./friendsList"));
  1134.  
  1135. var _mapControls = _interopRequireDefault(require("./mapControls"));
  1136.  
  1137. var _resizableChat = _interopRequireDefault(require("./resizableChat"));
  1138.  
  1139. var _resizableMap = _interopRequireDefault(require("./resizableMap"));
  1140.  
  1141. var _selectedWindowIsTop = _interopRequireDefault(require("./selectedWindowIsTop"));
  1142.  
  1143. var _xpMeter = _interopRequireDefault(require("./xpMeter"));
  1144.  
  1145. var _merchantFilter = _interopRequireDefault(require("./merchantFilter"));
  1146.  
  1147. var _itemStatsCopy = _interopRequireDefault(require("./itemStatsCopy"));
  1148.  
  1149. var _keyPressTracker = _interopRequireDefault(require("./_keyPressTracker"));
  1150.  
  1151. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1152.  
  1153. // The array here dictates the order of which mods are executed, from top to bottom
  1154. var _default = [_modStart.default, _keyPressTracker.default, _resizableMap.default, _mapControls.default, _friendsList.default, _blockedPlayerSettings.default, _resizableChat.default, _chatFilters.default, _chatContextMenu.default, _chatTabs.default, _draggableUI.default, _selectedWindowIsTop.default, _xpMeter.default, _merchantFilter.default, _itemStatsCopy.default];
  1155. exports.default = _default;
  1156.  
  1157. },{"./_keyPressTracker":2,"./_modStart":3,"./blockedPlayerSettings":4,"./chatContextMenu":6,"./chatFilters":7,"./chatTabs":9,"./draggableUI":11,"./friendsList":12,"./itemStatsCopy":14,"./mapControls":16,"./merchantFilter":18,"./resizableChat":19,"./resizableMap":21,"./selectedWindowIsTop":22,"./xpMeter":24}],14:[function(require,module,exports){
  1158. "use strict";
  1159.  
  1160. Object.defineProperty(exports, "__esModule", {
  1161. value: true
  1162. });
  1163. exports.default = void 0;
  1164.  
  1165. var chat = _interopRequireWildcard(require("../../utils/chat"));
  1166.  
  1167. var _game = require("../../utils/game");
  1168.  
  1169. var _state = require("../../utils/state");
  1170.  
  1171. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  1172.  
  1173. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  1174.  
  1175. async function itemStatsCopy(clickEvent) {
  1176. const tempState = (0, _state.getTempState)(); // This mod only triggers if you alt+right click
  1177.  
  1178. if (!tempState.keyModifiers.alt) {
  1179. return;
  1180. }
  1181.  
  1182. const $elementMouseIsOver = document.elementFromPoint(clickEvent.clientX, clickEvent.clientY); // It grabs the .overlay class, which is child of the .slot class we need to grab to get the tooltip
  1183.  
  1184. const $bagSlot = $elementMouseIsOver.parentNode; // No item in slot
  1185.  
  1186. if (!$bagSlot.querySelector('img')) {
  1187. return;
  1188. } // Once we confirm we want to copy to clipboard, hide context menu
  1189.  
  1190.  
  1191. const $itemContextMenuChoice = document.body.querySelector('.container > .panel > .choice');
  1192.  
  1193. if (!$itemContextMenuChoice) {
  1194. // If context menu isn't open, something is not right - stop what we're doing and exit
  1195. // Seen this happen very rarely when testing
  1196. return;
  1197. }
  1198.  
  1199. const $itemContextMenu = $itemContextMenuChoice.parentNode;
  1200.  
  1201. if ($itemContextMenu) {
  1202. $itemContextMenu.style.display = 'none';
  1203. } // Get the texts we want from the tooltip
  1204.  
  1205.  
  1206. const getDetailedTooltips = true;
  1207. const $tooltip = await (0, _game.getTooltipContent)($bagSlot, getDetailedTooltips);
  1208.  
  1209. if (!$tooltip) {
  1210. // This _shouldn't_ happen, but very occasionally there is a (likely timing-related) problem getting the tooltip
  1211. return;
  1212. } // We get the detailed tooltip, which may have a second comparison tooltip. Remove the comparison tooltip if we have it.
  1213.  
  1214.  
  1215. const $comparisonTooltip = $tooltip.querySelector('.slotdescription');
  1216. if ($comparisonTooltip) $comparisonTooltip.parentNode.removeChild($comparisonTooltip); // Collect item name/stats into strings
  1217.  
  1218. const itemName = $tooltip.querySelector('.slottitle').textContent;
  1219. const $itemQuality = $tooltip.querySelector('.type span');
  1220. const itemQuality = $itemQuality.textContent; // It's not a piece of equipment, just copy item name and exit
  1221.  
  1222. if (!itemQuality.includes('%')) {
  1223. let trimmedItemName = itemName; // If item name starts with T#, e.g. T1, T5, etc, then this was added onto the detailed tooltip
  1224. // It's usually unnecessary information, so we remove it
  1225. // (e.g. shows as "T94 Centrifugal Laceration Lv. 4" instead of "Centrifugal Laceration Lv. 4")
  1226.  
  1227. if (itemName.substr(0, 2).match(/T[0-9]/)) {
  1228. trimmedItemName = itemName.substr(itemName.indexOf(' ') + 1);
  1229. }
  1230.  
  1231. navigator.clipboard.writeText(trimmedItemName);
  1232. chat.addChatMessage(`Copied ${trimmedItemName} to clipboard.`);
  1233. return;
  1234. } // We only want the lvl number, so pop off the level number from the "Requires Lv. 17" line
  1235.  
  1236.  
  1237. const itemLvl = $tooltip.querySelector('.requirements').textContent.split(' ').pop(); // Grab the stats we care about, i.e. not part of the requirements or item type
  1238.  
  1239. const $stats = Array.from($tooltip.querySelectorAll(`
  1240. .container > .textpurp,
  1241. .container > .textblue,
  1242. .container > .textgreen:not(.slottitle):not(.requirements),
  1243. .container > .textwhite:not(.type)
  1244. `));
  1245. const statsText = $stats.map($stat => {
  1246. // Return quality percentage only if it exists, otherwise return normal stat
  1247. const $quality = $stat.querySelector('span');
  1248.  
  1249. if ($quality) {
  1250. const quality = $quality.textContent;
  1251. const statLineChunks = $stat.textContent.replace(/\+\s/g, '+').split(' ');
  1252. statLineChunks.pop(); // Remove quality at end
  1253.  
  1254. statLineChunks.shift(); // Remove specific +# at the beginning
  1255.  
  1256. const statName = statLineChunks.join(' ');
  1257. return `${statName} ${quality}`;
  1258. } else {
  1259. return $stat.textContent.trim();
  1260. }
  1261. }).join(', ');
  1262. navigator.clipboard.writeText(`${itemName} ${itemQuality} Lv.${itemLvl}: ${statsText}`);
  1263. chat.addChatMessage(`Copied ${itemName}'s stats to clipboard.`);
  1264. }
  1265.  
  1266. var _default = {
  1267. name: 'Items stats copy',
  1268. description: 'When ctrl+left clicking a piece of equipment in your inventory, its stats will be copied to your clipboard',
  1269. run: ({
  1270. registerOnRightClick
  1271. }) => {
  1272. registerOnRightClick(itemStatsCopy);
  1273. }
  1274. };
  1275. exports.default = _default;
  1276.  
  1277. },{"../../utils/chat":25,"../../utils/game":26,"../../utils/state":29}],15:[function(require,module,exports){
  1278. "use strict";
  1279.  
  1280. Object.defineProperty(exports, "__esModule", {
  1281. value: true
  1282. });
  1283. exports.updateMapOpacity = updateMapOpacity;
  1284.  
  1285. var _state = require("../../utils/state");
  1286.  
  1287. // On load, update map opacity to match state
  1288. // We modify the opacity of the canvas and the background color alpha of the parent container
  1289. // We do this to allow our opacity buttons to be visible on hover with 100% opacity
  1290. // (A surprisingly difficult enough task to require this implementation)
  1291. function updateMapOpacity() {
  1292. const state = (0, _state.getState)();
  1293. const $map = document.querySelector('.container canvas');
  1294. const $mapContainer = document.querySelector('.js-map');
  1295. $map.style.opacity = String(state.mapOpacity / 100);
  1296. const mapContainerBgColor = window.getComputedStyle($mapContainer, null).getPropertyValue('background-color'); // Credit for this regexp + This opacity+rgba dual implementation: https://stackoverflow.com/questions/16065998/replacing-changing-alpha-in-rgba-javascript
  1297.  
  1298. let opacity = state.mapOpacity / 100; // This is a slightly lazy browser workaround to fix a bug.
  1299. // If the opacity is `1`, and it sets `rgba` to `1`, then the browser changes the
  1300. // rgba to rgb, dropping the alpha. We could account for that and add the `alpha` back in
  1301. // later, but setting the max opacity to very close to 1 makes sure the issue never crops up.
  1302. // Fun fact: 0.99 retains the alpha, but setting this to 0.999 still causes the browser to drop the alpha. Rude.
  1303.  
  1304. if (opacity === 1) {
  1305. opacity = 0.99;
  1306. }
  1307.  
  1308. const newBgColor = mapContainerBgColor.replace(/[\d\.]+\)$/g, `${opacity})`);
  1309. $mapContainer.style['background-color'] = newBgColor; // Update the button opacity
  1310.  
  1311. const $addBtn = document.querySelector('.js-map-opacity-add');
  1312. const $minusBtn = document.querySelector('.js-map-opacity-minus'); // Hide plus button if the opacity is max
  1313.  
  1314. if (state.mapOpacity === 100) {
  1315. $addBtn.style.visibility = 'hidden';
  1316. } else {
  1317. $addBtn.style.visibility = 'visible';
  1318. } // Hide minus button if the opacity is lowest
  1319.  
  1320.  
  1321. if (state.mapOpacity === 0) {
  1322. $minusBtn.style.visibility = 'hidden';
  1323. } else {
  1324. $minusBtn.style.visibility = 'visible';
  1325. }
  1326. }
  1327.  
  1328. },{"../../utils/state":29}],16:[function(require,module,exports){
  1329. "use strict";
  1330.  
  1331. Object.defineProperty(exports, "__esModule", {
  1332. value: true
  1333. });
  1334. exports.default = void 0;
  1335.  
  1336. var _state = require("../../utils/state");
  1337.  
  1338. var helpers = _interopRequireWildcard(require("./helpers"));
  1339.  
  1340. var _misc = require("../../utils/misc");
  1341.  
  1342. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  1343.  
  1344. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  1345.  
  1346. function mapControls() {
  1347. const state = (0, _state.getState)();
  1348. const $map = document.querySelector('.container canvas');
  1349.  
  1350. if (!$map.parentNode.classList.contains('js-map')) {
  1351. $map.parentNode.classList.add('js-map');
  1352. }
  1353.  
  1354. const $mapContainer = document.querySelector('.js-map');
  1355. const $mapButtons = (0, _misc.makeElement)({
  1356. element: 'div',
  1357. class: 'js-map-btns',
  1358. content: `
  1359. <button class="js-map-opacity-add">+</button>
  1360. <button class="js-map-opacity-minus">-</button>
  1361. <button class="js-map-reset">r</button>
  1362. `
  1363. }); // Add it right before the map container div
  1364.  
  1365. $map.parentNode.insertBefore($mapButtons, $map);
  1366. helpers.updateMapOpacity();
  1367. const $addBtn = document.querySelector('.js-map-opacity-add');
  1368. const $minusBtn = document.querySelector('.js-map-opacity-minus');
  1369. const $resetBtn = document.querySelector('.js-map-reset'); // Hide the buttons if map opacity is maxed/minimum
  1370.  
  1371. if (state.mapOpacity === 100) {
  1372. $addBtn.style.visibility = 'hidden';
  1373. }
  1374.  
  1375. if (state.mapOpacity === 0) {
  1376. $minusBtn.style.visibility = 'hidden';
  1377. } // Wire it up
  1378.  
  1379.  
  1380. $addBtn.addEventListener('click', () => {
  1381. // Update opacity
  1382. state.mapOpacity += 10;
  1383. (0, _state.saveState)();
  1384. helpers.updateMapOpacity();
  1385. });
  1386. $minusBtn.addEventListener('click', () => {
  1387. // Update opacity
  1388. state.mapOpacity -= 10;
  1389. (0, _state.saveState)();
  1390. helpers.updateMapOpacity();
  1391. });
  1392. $resetBtn.addEventListener('click', () => {
  1393. state.mapOpacity = 70;
  1394. state.mapWidth = '174px';
  1395. state.mapHeight = '174px';
  1396. (0, _state.saveState)();
  1397. helpers.updateMapOpacity();
  1398. $mapContainer.style.width = state.mapWidth;
  1399. $mapContainer.style.height = state.mapHeight;
  1400. });
  1401. helpers.updateMapOpacity();
  1402. }
  1403.  
  1404. var _default = {
  1405. name: 'Map controls',
  1406. description: 'Enables hovering over the minimap to show buttons that let you increase or decrease the opacity of the map, or reset the size+transparency of it',
  1407. run: mapControls
  1408. };
  1409. exports.default = _default;
  1410.  
  1411. },{"../../utils/misc":27,"../../utils/state":29,"./helpers":15}],17:[function(require,module,exports){
  1412. "use strict";
  1413.  
  1414. Object.defineProperty(exports, "__esModule", {
  1415. value: true
  1416. });
  1417. exports.handleMerchantFilterInputChange = handleMerchantFilterInputChange;
  1418.  
  1419. var _game = require("../../utils/game");
  1420.  
  1421. function handleMerchantFilterInputChange() {
  1422. const value = document.querySelector('.js-merchant-filter-input').value; // If no filters, include single empty string, to make every item visible
  1423.  
  1424. const filters = value.split(',').map(v => v.trim()) || [''];
  1425. const $items = Array.from(document.querySelectorAll('.js-merchant-initd .items .slot'));
  1426. $items.forEach($item => {
  1427. const tooltipContentPromise = (0, _game.getTooltipContent)($item);
  1428. tooltipContentPromise.then(tooltipContent => {
  1429. if (!tooltipContent) {
  1430. // Something weird happened, probably related to lag from looking at tooltips in bulk
  1431. // In this case where we unexpectedly don't have the tooltip, just show the item rather than error out
  1432. $item.parentNode.style.display = 'grid';
  1433. return;
  1434. }
  1435.  
  1436. let filterMatchCount = 0;
  1437. filters.forEach(filter => {
  1438. const matchesFilter = tooltipContent.textContent.toLowerCase().includes(filter.toLowerCase());
  1439.  
  1440. if (matchesFilter) {
  1441. filterMatchCount++;
  1442. }
  1443. });
  1444. const matchesAllFilters = filterMatchCount === filters.length;
  1445.  
  1446. if (matchesAllFilters) {
  1447. $item.parentNode.style.display = 'grid';
  1448. } else {
  1449. $item.parentNode.style.display = 'none';
  1450. }
  1451. });
  1452. });
  1453. }
  1454.  
  1455. },{"../../utils/game":26}],18:[function(require,module,exports){
  1456. "use strict";
  1457.  
  1458. Object.defineProperty(exports, "__esModule", {
  1459. value: true
  1460. });
  1461. exports.default = void 0;
  1462.  
  1463. var _game = require("../../utils/game");
  1464.  
  1465. var _misc = require("../../utils/misc");
  1466.  
  1467. var _helpers = require("./helpers");
  1468.  
  1469. function addMerchantFilter() {
  1470. const $merchant = (0, _game.getWindow)('Merchant');
  1471.  
  1472. if (!$merchant) {
  1473. return;
  1474. }
  1475.  
  1476. $merchant.classList.add('js-merchant-initd');
  1477. $merchant.classList.add('uidom-merchant-with-filters');
  1478. const $lvMaximumField = $merchant.querySelectorAll('input[type="number"]')[1];
  1479. const $customSearchField = (0, _misc.makeElement)({
  1480. element: 'input',
  1481. class: 'js-merchant-filter-input uidom-merchant-input',
  1482. type: 'search',
  1483. placeholder: 'Filters (comma separated)'
  1484. });
  1485. $lvMaximumField.parentNode.insertBefore($customSearchField, $lvMaximumField.nextSibling);
  1486. $merchant.querySelector('.js-merchant-filter-input').addEventListener('keyup', (0, _misc.debounce)(_helpers.handleMerchantFilterInputChange, 250));
  1487. }
  1488.  
  1489. function refreshMerchantFilter() {
  1490. const $merchant = document.querySelector('.js-merchant-initd');
  1491.  
  1492. if (!$merchant) {
  1493. return;
  1494. }
  1495.  
  1496. if (!$merchant.querySelector('.js-merchant-filter-input').value) {
  1497. return;
  1498. } // Refresh filters after loading items from merchant
  1499.  
  1500.  
  1501. setTimeout(_helpers.handleMerchantFilterInputChange, 250);
  1502. }
  1503.  
  1504. var _default = {
  1505. name: 'Merchant filter',
  1506. description: 'Allows you to specify filters, or search text, for items displayed in the merchant',
  1507. run: ({
  1508. registerOnDomChange,
  1509. registerOnLeftClick
  1510. }) => {
  1511. addMerchantFilter();
  1512. registerOnDomChange(addMerchantFilter);
  1513. const debouncedRefreshMerchantFilter = (0, _misc.debounce)(refreshMerchantFilter, 250);
  1514. registerOnLeftClick(debouncedRefreshMerchantFilter);
  1515. }
  1516. };
  1517. exports.default = _default;
  1518.  
  1519. },{"../../utils/game":26,"../../utils/misc":27,"./helpers":17}],19:[function(require,module,exports){
  1520. "use strict";
  1521.  
  1522. Object.defineProperty(exports, "__esModule", {
  1523. value: true
  1524. });
  1525. exports.default = void 0;
  1526.  
  1527. var _state = require("../../utils/state");
  1528.  
  1529. function resizableChat() {
  1530. const state = (0, _state.getState)(); // Add the appropriate classes
  1531.  
  1532. const $chatContainer = document.querySelector('#chat').parentNode;
  1533. $chatContainer.classList.add('js-chat-resize'); // Load initial chat and map size
  1534.  
  1535. if (state.chatWidth && state.chatHeight) {
  1536. $chatContainer.style.width = state.chatWidth;
  1537. $chatContainer.style.height = state.chatHeight;
  1538. } // Save chat size on resize
  1539.  
  1540.  
  1541. const resizeObserverChat = new ResizeObserver(() => {
  1542. const chatWidthStr = window.getComputedStyle($chatContainer, null).getPropertyValue('width');
  1543. const chatHeightStr = window.getComputedStyle($chatContainer, null).getPropertyValue('height');
  1544. const hasWidthChanged = state.chatWidth !== chatWidthStr;
  1545. const hasHeightChanged = state.chatHeight !== chatHeightStr;
  1546. if (hasWidthChanged) state.chatWidth = chatWidthStr;
  1547. if (hasHeightChanged) state.chatHeight = chatHeightStr;
  1548. if (hasWidthChanged || hasHeightChanged) (0, _state.saveState)();
  1549. });
  1550. resizeObserverChat.observe($chatContainer);
  1551. }
  1552.  
  1553. var _default = {
  1554. name: 'Resizable chat',
  1555. description: 'Allows you to resize chat by clicking and dragging from the bottom right of chat',
  1556. run: resizableChat
  1557. };
  1558. exports.default = _default;
  1559.  
  1560. },{"../../utils/state":29}],20:[function(require,module,exports){
  1561. "use strict";
  1562.  
  1563. Object.defineProperty(exports, "__esModule", {
  1564. value: true
  1565. });
  1566. exports.mapResizeHandler = mapResizeHandler;
  1567. exports.triggerMapResize = triggerMapResize;
  1568.  
  1569. var _state = require("../../utils/state");
  1570.  
  1571. // When the map container resizes, we want to update the canvas width/height and the state
  1572. function mapResizeHandler() {
  1573. if (!document.querySelector('.layout')) {
  1574. return;
  1575. }
  1576.  
  1577. const state = (0, _state.getState)();
  1578. const tempState = (0, _state.getTempState)();
  1579. const $map = document.querySelector('.container canvas').parentNode;
  1580. const $canvas = $map.querySelector('canvas'); // Get real values of map height/width, excluding padding/margin/etc
  1581. // We round the values in this file to prevent unnecessary decimal points in our map or canvas sizes
  1582. // For some people these decimal points cause the map to constantly resize, making it pretty unusable.
  1583. // Rounding the numbers fixes this.
  1584.  
  1585. const mapWidthStr = window.getComputedStyle($map, null).getPropertyValue('width');
  1586. const mapHeightStr = window.getComputedStyle($map, null).getPropertyValue('height');
  1587. const mapWidth = Math.round(Number(mapWidthStr.slice(0, -2)));
  1588. const mapHeight = Math.round(Number(mapHeightStr.slice(0, -2))); // If height/width are 0 or unset, don't resize canvas
  1589.  
  1590. if (!mapWidth || !mapHeight) {
  1591. return;
  1592. }
  1593.  
  1594. if ($canvas.width !== mapWidth) {
  1595. $canvas.width = mapWidth;
  1596. }
  1597.  
  1598. if ($canvas.height !== mapHeight) {
  1599. $canvas.height = mapHeight;
  1600. } // If we're clicking map, i.e. manually resizing, then save state
  1601. // Don't save state when minimizing/maximizing map via [M]
  1602.  
  1603.  
  1604. if (tempState.clickingMap) {
  1605. state.mapWidth = mapWidthStr;
  1606. state.mapHeight = mapHeightStr;
  1607. (0, _state.saveState)();
  1608. } else {
  1609. const isMaximized = mapWidth > tempState.lastMapWidth && mapHeight > tempState.lastMapHeight;
  1610.  
  1611. if (!isMaximized) {
  1612. $map.style.width = state.mapWidth;
  1613. $map.style.height = state.mapHeight;
  1614. }
  1615. } // Store last map width/height in temp state, so we know if we've minimized or maximized
  1616.  
  1617.  
  1618. tempState.lastMapWidth = mapWidth;
  1619. tempState.lastMapHeight = mapHeight;
  1620. } // We need to observe canvas resizes to tell when the user presses M to open the big map
  1621. // At that point, we resize the map to match the canvas
  1622.  
  1623.  
  1624. function triggerMapResize() {
  1625. if (!document.querySelector('.layout')) {
  1626. return;
  1627. }
  1628.  
  1629. const $map = document.querySelector('.container canvas').parentNode;
  1630. const $canvas = $map.querySelector('canvas'); // Get real values of map height/width, excluding padding/margin/etc
  1631.  
  1632. const mapWidthStr = window.getComputedStyle($map, null).getPropertyValue('width');
  1633. const mapHeightStr = window.getComputedStyle($map, null).getPropertyValue('height');
  1634. const mapWidth = Math.round(Number(mapWidthStr.slice(0, -2)));
  1635. const mapHeight = Math.round(Number(mapHeightStr.slice(0, -2)));
  1636. const canvasWidth = Math.round($canvas.width);
  1637. const canvasHeight = Math.round($canvas.height); // If height/width are 0 or unset, we don't care about resizing yet
  1638.  
  1639. if (!mapWidth || !mapHeight) {
  1640. return;
  1641. }
  1642.  
  1643. if (canvasWidth !== mapWidth) {
  1644. $map.style.width = `${canvasWidth}px`;
  1645. }
  1646.  
  1647. if (canvasHeight !== mapHeight) {
  1648. $map.style.height = `${canvasHeight}px`;
  1649. }
  1650. }
  1651.  
  1652. },{"../../utils/state":29}],21:[function(require,module,exports){
  1653. "use strict";
  1654.  
  1655. Object.defineProperty(exports, "__esModule", {
  1656. value: true
  1657. });
  1658. exports.default = void 0;
  1659.  
  1660. var _state = require("../../utils/state");
  1661.  
  1662. var helpers = _interopRequireWildcard(require("./helpers"));
  1663.  
  1664. var _misc = require("../../utils/misc");
  1665.  
  1666. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  1667.  
  1668. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  1669.  
  1670. function resizableMap() {
  1671. const state = (0, _state.getState)();
  1672. const tempState = (0, _state.getTempState)();
  1673. const $map = document.querySelector('.container canvas').parentNode;
  1674. const $canvas = $map.querySelector('canvas');
  1675. $map.classList.add('js-map-resize'); // Track whether we're clicking (resizing) map or not
  1676. // Used to detect if resize changes are manually done, or from minimizing/maximizing map (with [M])
  1677.  
  1678. $map.addEventListener('mousedown', () => {
  1679. tempState.clickingMap = true;
  1680. }); // Sometimes the mouseup event may be registered outside of the map - we account for this
  1681.  
  1682. document.body.addEventListener('mouseup', () => {
  1683. tempState.clickingMap = false;
  1684. });
  1685.  
  1686. if (state.mapWidth && state.mapHeight) {
  1687. $map.style.width = state.mapWidth;
  1688. $map.style.height = state.mapHeight;
  1689. helpers.mapResizeHandler(); // Update canvas size on initial load of saved map size
  1690. } // On resize of map, resize canvas to match
  1691. // Debouncing allows map to be visible while resizing
  1692.  
  1693.  
  1694. const debouncedMapResize = (0, _misc.debounce)(helpers.mapResizeHandler, 1);
  1695. const resizeObserverMap = new ResizeObserver(debouncedMapResize);
  1696. helpers.mapResizeHandler();
  1697. resizeObserverMap.observe($map); // We debounce the canvas resize, so it doesn't resize every single
  1698. // pixel you move when resizing the DOM. If this were to happen,
  1699. // resizing would constantly be interrupted. You'd have to resize a tiny bit,
  1700. // lift left click, left click again to resize a tiny bit more, etc.
  1701. // Resizing is smooth when we debounce this canvas.
  1702.  
  1703. const debouncedTriggerResize = (0, _misc.debounce)(helpers.triggerMapResize, 50);
  1704. const resizeObserverCanvas = new ResizeObserver(debouncedTriggerResize);
  1705. resizeObserverCanvas.observe($canvas);
  1706. }
  1707.  
  1708. var _default = {
  1709. name: 'Resizable map',
  1710. description: 'Allows you to resize the map by clicking and dragging from the bottom left',
  1711. run: resizableMap
  1712. };
  1713. exports.default = _default;
  1714.  
  1715. },{"../../utils/misc":27,"../../utils/state":29,"./helpers":20}],22:[function(require,module,exports){
  1716. "use strict";
  1717.  
  1718. Object.defineProperty(exports, "__esModule", {
  1719. value: true
  1720. });
  1721. exports.default = void 0;
  1722.  
  1723. // The last clicked UI window displays above all other UI windows
  1724. // This is useful when, for example, your inventory is near the market window,
  1725. // and you want the window and the tooltips to display above the market window.
  1726. function selectedWindowIsTop() {
  1727. Array.from(document.querySelectorAll('.window:not(.js-is-top-initd)')).forEach($window => {
  1728. $window.classList.add('js-is-top-initd');
  1729. $window.addEventListener('mousedown', () => {
  1730. // First, make the other is-top window not is-top
  1731. const $otherWindowContainer = document.querySelector('.js-is-top');
  1732.  
  1733. if ($otherWindowContainer) {
  1734. $otherWindowContainer.classList.remove('js-is-top');
  1735. } // Then, make our window's container (the z-index container) is-top
  1736.  
  1737.  
  1738. $window.parentNode.classList.add('js-is-top');
  1739. });
  1740. });
  1741. }
  1742.  
  1743. var _default = {
  1744. name: 'Make Selected Window Top',
  1745. description: 'The UI window you click will always be displayed over other UI windows',
  1746. run: ({
  1747. registerOnDomChange
  1748. }) => {
  1749. selectedWindowIsTop(); // As windows are opened, we want to enable them to become the top window when they're clicked
  1750.  
  1751. registerOnDomChange(selectedWindowIsTop);
  1752. }
  1753. };
  1754. exports.default = _default;
  1755.  
  1756. },{}],23:[function(require,module,exports){
  1757. "use strict";
  1758.  
  1759. Object.defineProperty(exports, "__esModule", {
  1760. value: true
  1761. });
  1762. exports.getCurrentCharacterLvl = getCurrentCharacterLvl;
  1763. exports.getCurrentXp = getCurrentXp;
  1764. exports.getNextLevelXp = getNextLevelXp;
  1765. exports.resetXpMeterState = resetXpMeterState;
  1766. exports.msToString = msToString;
  1767.  
  1768. var _state = require("../../utils/state");
  1769.  
  1770. function getCurrentCharacterLvl() {
  1771. return Number(document.querySelector('#ufplayer .bgmana > .left').textContent.split('Lv. ')[1]);
  1772. }
  1773.  
  1774. function getCurrentXp() {
  1775. return Number(document.querySelector('#expbar .progressBar > .left').textContent.split('/')[0].trim());
  1776. }
  1777.  
  1778. function getNextLevelXp() {
  1779. return Number(document.querySelector('#expbar .progressBar > .left').textContent.split('/')[1].trim());
  1780. } // user invoked reset of xp meter stats
  1781.  
  1782.  
  1783. function resetXpMeterState() {
  1784. const state = (0, _state.getState)();
  1785. state.xpMeterState.xpGains = []; // array of xp deltas every second
  1786.  
  1787. state.xpMeterState.averageXp = 0;
  1788. state.xpMeterState.gainedXp = 0;
  1789. (0, _state.saveState)();
  1790. document.querySelector('.js-xp-time').textContent = '-:-:-';
  1791. }
  1792.  
  1793. function msToString(ms) {
  1794. const pad = value => value < 10 ? `0${value}` : value;
  1795.  
  1796. const hours = pad(Math.floor(ms / (1000 * 60 * 60) % 60));
  1797. const minutes = pad(Math.floor(ms / (1000 * 60) % 60));
  1798. const seconds = pad(Math.floor(ms / 1000 % 60));
  1799. return `${hours}:${minutes}:${seconds}`;
  1800. }
  1801.  
  1802. },{"../../utils/state":29}],24:[function(require,module,exports){
  1803. "use strict";
  1804.  
  1805. Object.defineProperty(exports, "__esModule", {
  1806. value: true
  1807. });
  1808. exports.default = void 0;
  1809.  
  1810. var _state = require("../../utils/state");
  1811.  
  1812. var helpers = _interopRequireWildcard(require("./helpers"));
  1813.  
  1814. var _ui = require("../../utils/ui");
  1815.  
  1816. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  1817.  
  1818. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  1819.  
  1820. // TODO: Consider adding start button to start interval, and stop after X minutes of no EXP
  1821. // Or maybe watch XP bar and start it once XP bar first moves?
  1822. // Adds XP Meter DOM icon and window, starts continuous interval to get current xp over time
  1823. function xpMeter() {
  1824. const state = (0, _state.getState)();
  1825. const tempState = (0, _state.getTempState)();
  1826. (0, _ui.createXpMeter)(); // If it was open when the game last closed keep it open
  1827.  
  1828. if (state.openWindows.openXpMeter) {
  1829. (0, _ui.toggleXpMeterVisibility)();
  1830. } // Wire up icon and xpmeter window
  1831.  
  1832.  
  1833. document.querySelector('.js-sysxp').addEventListener('click', _ui.toggleXpMeterVisibility);
  1834. document.querySelector('.js-xpmeter-close-icon').addEventListener('click', _ui.toggleXpMeterVisibility);
  1835. document.querySelector('.js-xpmeter-reset-button').addEventListener('click', helpers.resetXpMeterState);
  1836. const currentXp = helpers.getCurrentXp();
  1837. const currentCharLvl = helpers.getCurrentCharacterLvl();
  1838. if (currentXp !== state.xpMeterState.currentXp) state.xpMeterState.currentXp = currentXp;
  1839. if (currentCharLvl !== state.xpMeterState.currentLvl) state.xpMeterState.currentLvl = currentCharLvl;
  1840. (0, _state.saveState)();
  1841. if (tempState.xpMeterInterval) clearInterval(tempState.xpMeterInterval); // every second we run the operations for xp meter, update xps, calc delta, etc
  1842. // TODO Cleanup: This interval may not be cleaned up if the UI mod reinitializes,
  1843. // e.g. user is away from tab for a while then comes back
  1844. // Should confirm if this is an issue, and try to fix it if possible.
  1845.  
  1846. tempState.xpMeterInterval = setInterval(() => {
  1847. if (!document.querySelector('#expbar')) {
  1848. return;
  1849. } // This _shouldn't_ happen, but in case it does, reset xp meter state instead of throwing error
  1850.  
  1851.  
  1852. if (!Array.isArray(state.xpMeterState.xpGains)) {
  1853. helpers.resetXpMeterState();
  1854. }
  1855.  
  1856. const currentXp = helpers.getCurrentXp();
  1857. const nextLvlXp = helpers.getNextLevelXp();
  1858. const currentLvl = helpers.getCurrentCharacterLvl(); // Only update and save state if it has changed
  1859.  
  1860. const gainedXp = currentXp - state.xpMeterState.currentXp;
  1861. const xpGains = currentXp - state.xpMeterState.currentXp;
  1862. const averageXp = state.xpMeterState.xpGains.length > 0 ? state.xpMeterState.xpGains.reduce((a, b) => a + b, 0) / state.xpMeterState.xpGains.length : 0; // Our algorithms and session time depend on an xpGain being pushed every second, even if it is 0
  1863.  
  1864. state.xpMeterState.xpGains.push(xpGains); // array of xp deltas every second
  1865.  
  1866. if (gainedXp !== 0) state.xpMeterState.gainedXp += gainedXp;
  1867. if (currentXp !== state.xpMeterState.currentXp) state.xpMeterState.currentXp = currentXp;
  1868. if (averageXp !== state.xpMeterState.averageXp) state.xpMeterState.averageXp = averageXp;
  1869. (0, _state.saveState)();
  1870.  
  1871. if (document.querySelector('.js-xpmeter')) {
  1872. document.querySelector('.js-xpm').textContent = parseInt((state.xpMeterState.averageXp * 60).toFixed(0)).toLocaleString();
  1873. document.querySelector('.js-xph').textContent = parseInt((state.xpMeterState.averageXp * 60 * 60).toFixed(0)).toLocaleString();
  1874. document.querySelector('.js-xpg').textContent = state.xpMeterState.gainedXp.toLocaleString();
  1875. document.querySelector('.js-xpl').textContent = (nextLvlXp - currentXp).toLocaleString();
  1876. document.querySelector('.js-xp-s-time').textContent = helpers.msToString(state.xpMeterState.xpGains.length * 1000); // need a positive integer for averageXp to calc time left
  1877.  
  1878. if (state.xpMeterState.averageXp > 0) document.querySelector('.js-xp-time').textContent = helpers.msToString((nextLvlXp - currentXp) / state.xpMeterState.averageXp * 1000);
  1879. }
  1880.  
  1881. if (state.xpMeterState.currentLvl < currentLvl) {
  1882. helpers.resetXpMeterState();
  1883. state.xpMeterState.currentLvl = currentLvl;
  1884. (0, _state.saveState)();
  1885. }
  1886. }, 1000);
  1887. }
  1888.  
  1889. var _default = {
  1890. name: 'XP Meter',
  1891. description: "Tracks your XP/minute and displays how much XP you're getting and lets you know how long until you level up",
  1892. run: xpMeter
  1893. };
  1894. exports.default = _default;
  1895.  
  1896. },{"../../utils/state":29,"../../utils/ui":30,"./helpers":23}],25:[function(require,module,exports){
  1897. "use strict";
  1898.  
  1899. Object.defineProperty(exports, "__esModule", {
  1900. value: true
  1901. });
  1902. exports.setGMChatVisibility = setGMChatVisibility;
  1903. exports.filterAllChat = filterAllChat;
  1904. exports.whisperPlayer = whisperPlayer;
  1905. exports.partyPlayer = partyPlayer;
  1906. exports.addChatMessage = addChatMessage;
  1907.  
  1908. var _state = require("./state");
  1909.  
  1910. var _misc = require("./misc");
  1911.  
  1912. // Updates state.chat.GM and the DOM to make text white/grey depending on if gm chat is visible/filtered
  1913. // Then filters chat and saves updated chat state
  1914. function setGMChatVisibility(isGMChatVisible) {
  1915. const state = (0, _state.getState)();
  1916. const $chatGM = document.querySelector(`.js-chat-gm`);
  1917. state.chat.GM = isGMChatVisible;
  1918. $chatGM.classList.toggle('textgrey', !state.chat.GM);
  1919. filterAllChat();
  1920. (0, _state.saveState)();
  1921. } // Filters all chat based on custom filters
  1922.  
  1923.  
  1924. function filterAllChat() {
  1925. const state = (0, _state.getState)(); // Blocked user filter
  1926.  
  1927. Object.keys(state.blockList).forEach(blockedName => {
  1928. // Get the `.name` elements from the blocked user, if we haven't already hidden their messages
  1929. const $blockedChatNames = Array.from(document.querySelectorAll(`[data-chat-name="${blockedName}"]:not(.js-line-blocked)`)); // Hide each of their messages
  1930.  
  1931. $blockedChatNames.forEach($name => {
  1932. // Add the class name to $name so we can track whether it's been hidden in our CSS selector $blockedChatNames
  1933. $name.classList.add('js-line-blocked');
  1934. const $line = $name.parentNode.parentNode.parentNode; // Add the class name to $line so we can visibly hide the entire chat line
  1935.  
  1936. $line.classList.add('js-line-blocked');
  1937. });
  1938. }); // Custom channel filter
  1939.  
  1940. Object.keys(state.chat).forEach(channel => {
  1941. Array.from(document.querySelectorAll(`.text${channel}.content`)).forEach($textItem => {
  1942. const $line = $textItem.parentNode.parentNode;
  1943. $line.classList.toggle('js-line-hidden', !state.chat[channel]);
  1944. });
  1945. });
  1946. }
  1947.  
  1948. function enterTextIntoChat(text) {
  1949. // Open chat input
  1950. const enterEvent = new KeyboardEvent('keydown', {
  1951. bubbles: true,
  1952. cancelable: true,
  1953. keyCode: 13
  1954. });
  1955. document.body.dispatchEvent(enterEvent); // Place text into chat
  1956.  
  1957. const $input = document.querySelector('#chatinput input');
  1958. $input.value = text; // Get chat input to recognize slash commands and change the channel
  1959. // by triggering the `input` event.
  1960. // (Did some debugging to figure out the channel only changes when the
  1961. // svelte `input` event listener exists.)
  1962.  
  1963. const inputEvent = new KeyboardEvent('input', {
  1964. bubbles: true,
  1965. cancelable: true
  1966. });
  1967. $input.dispatchEvent(inputEvent);
  1968. }
  1969.  
  1970. function submitChat() {
  1971. const $input = document.querySelector('#chatinput input');
  1972. const kbEvent = new KeyboardEvent('keydown', {
  1973. bubbles: true,
  1974. cancelable: true,
  1975. keyCode: 13
  1976. });
  1977. $input.dispatchEvent(kbEvent);
  1978. } // Automated chat command helpers
  1979. // (We've been OK'd to do these by the dev - all automation like this should receive approval from the dev)
  1980.  
  1981.  
  1982. function whisperPlayer(playerName) {
  1983. enterTextIntoChat(`/${playerName} `);
  1984. }
  1985.  
  1986. function partyPlayer(playerName) {
  1987. enterTextIntoChat(`/partyinvite ${playerName}`);
  1988. submitChat();
  1989. } // Pushes message to chat
  1990. // TODO: The margins for the message are off slightly compared to other messages - why?
  1991.  
  1992.  
  1993. function addChatMessage(text) {
  1994. const newMessageHTML = `
  1995. <div class="linewrap svelte-1vrlsr3">
  1996. <span class="time svelte-1vrlsr3">00.00</span>
  1997. <span class="textuimod content svelte-1vrlsr3">
  1998. <span class="capitalize channel svelte-1vrlsr3">UIMod</span>
  1999. </span>
  2000. <span class="svelte-1vrlsr3">${text}</span>
  2001. </div>
  2002. `;
  2003. const element = (0, _misc.makeElement)({
  2004. element: 'article',
  2005. class: 'line svelte-1vrlsr3',
  2006. content: newMessageHTML
  2007. });
  2008. const $chat = document.querySelector('#chat');
  2009. $chat.appendChild(element); // Scroll to bottom of chat
  2010.  
  2011. $chat.scrollTop = $chat.scrollHeight;
  2012. }
  2013.  
  2014. },{"./misc":27,"./state":29}],26:[function(require,module,exports){
  2015. "use strict";
  2016.  
  2017. Object.defineProperty(exports, "__esModule", {
  2018. value: true
  2019. });
  2020. exports.getTooltipContent = getTooltipContent;
  2021. exports.getWindow = getWindow;
  2022.  
  2023. var _state = require("./state");
  2024.  
  2025. // Gets the node of a tooltip for any element, emulates shift keypress to get tooltip with quality details
  2026. // Must be `await`'d to use, e.g. `await getTooltipContent($element)`
  2027. // Optionally pass `getDetailedTooltips` as `true` if you want detailed tooltips by holding shift
  2028. // ^ is laggier, do not use when looking at more than one item
  2029. async function getTooltipContent($elementToHoverOver, getDetailedTooltips) {
  2030. const tempState = (0, _state.getTempState)(); // Emulate holding down shift when getting tooltip
  2031. // Don't need to emulate if user is already holding it down
  2032.  
  2033. if (getDetailedTooltips && !tempState.keyModifiers.shift) {
  2034. // Set this so the keymodifiers mod knows our shift press shouldn't be tracked in tempState
  2035. tempState.gettingTooltipContentShiftPress = true;
  2036. document.body.dispatchEvent(new KeyboardEvent('keydown', {
  2037. bubbles: true,
  2038. cancelable: true,
  2039. key: 'Shift'
  2040. }));
  2041. }
  2042.  
  2043. $elementToHoverOver.dispatchEvent(new Event('pointerenter'));
  2044. const closeTooltipPromise = new Promise(resolve => setTimeout(() => {
  2045. const resolveWithTooltip = () => {
  2046. // If there is no slotdescription at this point, the item element passed very likely has no tooltip
  2047. const $tooltip = document.querySelector('.slotdescription');
  2048.  
  2049. if (!$tooltip || !$tooltip.cloneNode) {
  2050. resolve(false);
  2051. } else {
  2052. resolve($tooltip.cloneNode(true));
  2053. }
  2054.  
  2055. if (tempState.gettingTooltipContentShiftPress) {
  2056. // Release our emulated shift press
  2057. document.body.dispatchEvent(new KeyboardEvent('keyup', {
  2058. bubbles: true,
  2059. cancelable: true,
  2060. key: 'Shift'
  2061. }));
  2062. tempState.gettingTooltipContentShiftPress = false;
  2063. }
  2064.  
  2065. $elementToHoverOver.dispatchEvent(new Event('pointerleave'));
  2066. }; // Very occasionally the 0ms wait time on our timeout doesn't show the tooltip,
  2067. // so we set a second timeout to account for this. Not the most perfect user experience,
  2068. // but it rarely hapens, and it's better than getting an error.
  2069.  
  2070.  
  2071. if (getDetailedTooltips && !document.querySelector('.slotdescription')) {
  2072. setTimeout(resolveWithTooltip, 1);
  2073. } else {
  2074. resolveWithTooltip();
  2075. }
  2076. }, 0));
  2077. const $tooltip = await closeTooltipPromise;
  2078. return $tooltip;
  2079. } // Use this to get a specific window, rather than using the svelte class, which is not preferable
  2080.  
  2081.  
  2082. function getWindow(windowTitle) {
  2083. const $specificWindowTitle = Array.from(document.querySelectorAll('.window [name="title"]')).find($windowTitle => $windowTitle.textContent.toLowerCase() === windowTitle.toLowerCase());
  2084. return $specificWindowTitle ? $specificWindowTitle.parentNode.parentNode.parentNode : $specificWindowTitle;
  2085. }
  2086.  
  2087. },{"./state":29}],27:[function(require,module,exports){
  2088. "use strict";
  2089.  
  2090. Object.defineProperty(exports, "__esModule", {
  2091. value: true
  2092. });
  2093. exports.makeElement = makeElement;
  2094. exports.debounce = debounce;
  2095. exports.uuid = uuid;
  2096. exports.deepClone = deepClone;
  2097.  
  2098. // Nicer impl to create elements in one method call
  2099. function makeElement(args) {
  2100. const $node = document.createElement(args.element);
  2101. if (args.class) $node.className = args.class;
  2102. if (args.content) $node.innerHTML = args.content;
  2103. if (args.src) $node.src = args.src;
  2104. if (args.type) $node.type = args.type;
  2105. if (args.placeholder) $node.placeholder = args.placeholder;
  2106. return $node;
  2107. } // Credit: David Walsh
  2108.  
  2109.  
  2110. function debounce(func, wait, immediate) {
  2111. var timeout;
  2112. return function () {
  2113. var context = this,
  2114. args = arguments;
  2115.  
  2116. var later = function () {
  2117. timeout = null;
  2118. if (!immediate) func.apply(context, args);
  2119. };
  2120.  
  2121. var callNow = immediate && !timeout;
  2122. clearTimeout(timeout);
  2123. timeout = setTimeout(later, wait);
  2124. if (callNow) func.apply(context, args);
  2125. };
  2126. } // Credit: https://gist.github.com/jcxplorer/823878
  2127. // Generate random UUID string
  2128.  
  2129.  
  2130. function uuid() {
  2131. var uuid = '',
  2132. i,
  2133. random;
  2134.  
  2135. for (i = 0; i < 32; i++) {
  2136. random = Math.random() * 16 | 0;
  2137.  
  2138. if (i == 8 || i == 12 || i == 16 || i == 20) {
  2139. uuid += '-';
  2140. }
  2141.  
  2142. uuid += (i == 12 ? 4 : i == 16 ? random & 3 | 8 : random).toString(16);
  2143. }
  2144.  
  2145. return uuid;
  2146. } // Credit: http://voidcanvas.com/clone-an-object-in-vanilla-js-in-depth/
  2147.  
  2148.  
  2149. function deepClone(obj) {
  2150. //in case of premitives
  2151. if (obj === null || typeof obj !== 'object') {
  2152. return obj;
  2153. } //date objects should be
  2154.  
  2155.  
  2156. if (obj instanceof Date) {
  2157. return new Date(obj.getTime());
  2158. } //handle Array
  2159.  
  2160.  
  2161. if (Array.isArray(obj)) {
  2162. var clonedArr = [];
  2163. obj.forEach(function (element) {
  2164. clonedArr.push(deepClone(element));
  2165. });
  2166. return clonedArr;
  2167. } //lastly, handle objects
  2168.  
  2169.  
  2170. let clonedObj = new obj.constructor();
  2171.  
  2172. for (var prop in obj) {
  2173. if (obj.hasOwnProperty(prop)) {
  2174. clonedObj[prop] = deepClone(obj[prop]);
  2175. }
  2176. }
  2177.  
  2178. return clonedObj;
  2179. }
  2180.  
  2181. },{}],28:[function(require,module,exports){
  2182. "use strict";
  2183.  
  2184. Object.defineProperty(exports, "__esModule", {
  2185. value: true
  2186. });
  2187. exports.friendPlayer = friendPlayer;
  2188. exports.unfriendPlayer = unfriendPlayer;
  2189. exports.blockPlayer = blockPlayer;
  2190. exports.unblockPlayer = unblockPlayer;
  2191.  
  2192. var _state = require("./state");
  2193.  
  2194. var chat = _interopRequireWildcard(require("./chat"));
  2195.  
  2196. var ui = _interopRequireWildcard(require("./ui"));
  2197.  
  2198. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  2199.  
  2200. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  2201.  
  2202. function friendPlayer(playerName) {
  2203. const state = (0, _state.getState)();
  2204.  
  2205. if (state.friendsList[playerName]) {
  2206. return;
  2207. }
  2208.  
  2209. state.friendsList[playerName] = true;
  2210. chat.addChatMessage(`${playerName} has been added to your friends list.`);
  2211. (0, _state.saveState)(); // If UI is open remake it with new changes
  2212.  
  2213. if (state.openWindows.openFriendsList) {
  2214. ui.removeFriendsList();
  2215. ui.createFriendsList();
  2216. }
  2217. }
  2218.  
  2219. function unfriendPlayer(playerName) {
  2220. const state = (0, _state.getState)();
  2221.  
  2222. if (!state.friendsList[playerName]) {
  2223. return;
  2224. }
  2225.  
  2226. delete state.friendsList[playerName];
  2227. delete state.friendNotes[playerName];
  2228. chat.addChatMessage(`${playerName} is no longer on your friends list.`);
  2229. (0, _state.saveState)(); // If UI is open remake it with new changes
  2230.  
  2231. if (state.openWindows.openFriendsList) {
  2232. ui.removeFriendsList();
  2233. ui.createFriendsList();
  2234. }
  2235. } // Adds player to block list, to be filtered out of chat
  2236.  
  2237.  
  2238. function blockPlayer(playerName) {
  2239. const state = (0, _state.getState)();
  2240.  
  2241. if (state.blockList[playerName]) {
  2242. return;
  2243. }
  2244.  
  2245. state.blockList[playerName] = true;
  2246. chat.filterAllChat();
  2247. chat.addChatMessage(`${playerName} has been blocked.`);
  2248. (0, _state.saveState)(); // If UI is open remake it with new changes
  2249.  
  2250. if (state.openWindows.openBlockList) {
  2251. ui.removeBlockList();
  2252. ui.createBlockList();
  2253. }
  2254. } // Removes player from block list and makes their messages visible again
  2255.  
  2256.  
  2257. function unblockPlayer(playerName) {
  2258. const state = (0, _state.getState)();
  2259. delete state.blockList[playerName];
  2260. chat.addChatMessage(`${playerName} has been unblocked.`);
  2261. (0, _state.saveState)(); // Make messages visible again
  2262.  
  2263. const $chatNames = Array.from(document.querySelectorAll(`.js-line-blocked[data-chat-name="${playerName}"]`));
  2264. $chatNames.forEach($name => {
  2265. $name.classList.remove('js-line-blocked');
  2266. const $line = $name.parentNode.parentNode.parentNode;
  2267. $line.classList.remove('js-line-blocked');
  2268. });
  2269. }
  2270.  
  2271. },{"./chat":25,"./state":29,"./ui":30}],29:[function(require,module,exports){
  2272. "use strict";
  2273.  
  2274. Object.defineProperty(exports, "__esModule", {
  2275. value: true
  2276. });
  2277. exports.getState = getState;
  2278. exports.getTempState = getTempState;
  2279. exports.saveState = saveState;
  2280. exports.loadState = loadState;
  2281.  
  2282. var _version = require("./version");
  2283.  
  2284. const STORAGE_STATE_KEY = 'hordesio-uimodsakaiyo-state';
  2285. let state = {
  2286. breakingVersion: _version.BREAKING_VERSION,
  2287. chat: {
  2288. GM: true
  2289. },
  2290. windowsPos: {},
  2291. blockList: {},
  2292. friendsList: {},
  2293. mapOpacity: 70,
  2294. // e.g. 70 = opacity: 0.7
  2295. friendNotes: {},
  2296. chatTabs: [],
  2297. xpMeterState: {
  2298. currentXp: 0,
  2299. xpGains: [],
  2300. // array of xp deltas every second
  2301. averageXp: 0,
  2302. gainedXp: 0,
  2303. currentLvl: 0
  2304. },
  2305. openWindows: {
  2306. openFriendsList: false,
  2307. openBlockList: false,
  2308. openXpMeter: false
  2309. }
  2310. }; // tempState is saved only between page refreshes.
  2311.  
  2312. const tempState = {
  2313. // The last name clicked in chat
  2314. chatName: null,
  2315. lastMapWidth: 0,
  2316. lastMapHeight: 0,
  2317. xpMeterInterval: null,
  2318. // tracks the interval for fetching xp data
  2319. keyModifiers: {
  2320. shift: false,
  2321. control: false,
  2322. alt: false
  2323. } // set by _keyModifiers mod
  2324.  
  2325. };
  2326.  
  2327. function getState() {
  2328. return state;
  2329. }
  2330.  
  2331. function getTempState() {
  2332. return tempState;
  2333. }
  2334.  
  2335. function saveState() {
  2336. localStorage.setItem(STORAGE_STATE_KEY, JSON.stringify(state));
  2337. }
  2338.  
  2339. function loadState() {
  2340. const storedStateJson = localStorage.getItem(STORAGE_STATE_KEY);
  2341.  
  2342. if (storedStateJson) {
  2343. const storedState = JSON.parse(storedStateJson);
  2344.  
  2345. if (storedState.breakingVersion !== _version.BREAKING_VERSION) {
  2346. localStorage.setItem(STORAGE_STATE_KEY, JSON.stringify(state));
  2347. return;
  2348. }
  2349.  
  2350. for (let [key, value] of Object.entries(storedState)) {
  2351. state[key] = value;
  2352. }
  2353. }
  2354. }
  2355.  
  2356. },{"./version":31}],30:[function(require,module,exports){
  2357. "use strict";
  2358.  
  2359. Object.defineProperty(exports, "__esModule", {
  2360. value: true
  2361. });
  2362. exports.createBlockList = createBlockList;
  2363. exports.removeBlockList = removeBlockList;
  2364. exports.createFriendsList = createFriendsList;
  2365. exports.removeFriendsList = removeFriendsList;
  2366. exports.toggleXpMeterVisibility = toggleXpMeterVisibility;
  2367. exports.createXpMeter = createXpMeter;
  2368.  
  2369. var _state = require("./state");
  2370.  
  2371. var _misc = require("./misc");
  2372.  
  2373. var player = _interopRequireWildcard(require("./player"));
  2374.  
  2375. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  2376.  
  2377. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  2378.  
  2379. function createBlockList() {
  2380. const state = (0, _state.getState)();
  2381. let blockedPlayersHTML = '';
  2382. Object.keys(state.blockList).sort().forEach(blockedName => {
  2383. blockedPlayersHTML += `
  2384. <div data-player-name="${blockedName}">${blockedName}</div>
  2385. <div class="btn orange js-unblock-player" data-player-name="${blockedName}">Unblock player</div>
  2386. `;
  2387. });
  2388. const customSettingsHTML = `
  2389. <h3 class="textprimary">Blocked players</h3>
  2390. <div class="settings uimod-settings">${blockedPlayersHTML}</div>
  2391. <p></p>
  2392. <div class="btn purp js-close-custom-settings">Close</div>
  2393. `;
  2394. const $customSettings = (0, _misc.makeElement)({
  2395. element: 'div',
  2396. class: 'menu panel-black uimod-custom-window js-blocked-list',
  2397. content: customSettingsHTML
  2398. });
  2399. document.body.appendChild($customSettings); // Save Friends List UI's state as opened
  2400.  
  2401. state.openWindows['openBlockList'] = true;
  2402. (0, _state.saveState)(); // Wire up all the unblock buttons
  2403.  
  2404. Array.from(document.querySelectorAll('.js-unblock-player')).forEach($button => {
  2405. $button.addEventListener('click', clickEvent => {
  2406. const name = clickEvent.target.getAttribute('data-player-name');
  2407. player.unblockPlayer(name); // Remove the blocked player from the list
  2408.  
  2409. Array.from(document.querySelectorAll(`.js-blocked-list [data-player-name="${name}"]`)).forEach($element => {
  2410. $element.parentNode.removeChild($element);
  2411. });
  2412. });
  2413. }); // And the close button for our custom UI
  2414.  
  2415. document.querySelector('.js-close-custom-settings').addEventListener('click', removeBlockList);
  2416. }
  2417.  
  2418. function removeBlockList() {
  2419. const state = (0, _state.getState)();
  2420. const $customSettingsWindow = document.querySelector('.js-blocked-list');
  2421. $customSettingsWindow.parentNode.removeChild($customSettingsWindow); // Save Blocked List UI's state as closed
  2422.  
  2423. state.openWindows['openBlockList'] = false;
  2424. (0, _state.saveState)();
  2425. }
  2426.  
  2427. function createFriendsList() {
  2428. const state = (0, _state.getState)();
  2429.  
  2430. if (document.querySelector('.js-friends-list')) {
  2431. // Don't open the friends list twice.
  2432. return;
  2433. }
  2434.  
  2435. let friendsListHTML = '';
  2436. Object.keys(state.friendsList).sort().forEach(friendName => {
  2437. friendsListHTML += `
  2438. <div data-player-name="${friendName}">${friendName}</div>
  2439. <div class="btn blue js-whisper-player" data-player-name="${friendName}">Whisper</div>
  2440. <div class="btn blue js-party-player" data-player-name="${friendName}">Party invite</div>
  2441. <div class="btn orange js-unfriend-player" data-player-name="${friendName}">X</div>
  2442. <input type="text" class="js-friend-note" data-player-name="${friendName}" value="${state.friendNotes[friendName] || ''}"></input>
  2443. `;
  2444. });
  2445. const customFriendsWindowHTML = `
  2446. <h3 class="textprimary">Friends list</h3>
  2447. <div class="uimod-friends">${friendsListHTML}</div>
  2448. <p></p>
  2449. <div class="btn purp js-close-custom-friends-list">Close</div>
  2450. `;
  2451. const $customFriendsList = (0, _misc.makeElement)({
  2452. element: 'div',
  2453. class: 'menu panel-black js-friends-list uimod-custom-window',
  2454. content: customFriendsWindowHTML
  2455. });
  2456. document.body.appendChild($customFriendsList); // Save Friends List UI's state as opened
  2457.  
  2458. state.openWindows['openFriendsList'] = true;
  2459. (0, _state.saveState)(); // Wire up the buttons
  2460.  
  2461. Array.from(document.querySelectorAll('.js-whisper-player')).forEach($button => {
  2462. $button.addEventListener('click', clickEvent => {
  2463. const name = clickEvent.target.getAttribute('data-player-name');
  2464. player.whisperPlayer(name);
  2465. });
  2466. });
  2467. Array.from(document.querySelectorAll('.js-party-player')).forEach($button => {
  2468. $button.addEventListener('click', clickEvent => {
  2469. const name = clickEvent.target.getAttribute('data-player-name');
  2470. player.partyPlayer(name);
  2471. });
  2472. });
  2473. Array.from(document.querySelectorAll('.js-unfriend-player')).forEach($button => {
  2474. $button.addEventListener('click', clickEvent => {
  2475. const name = clickEvent.target.getAttribute('data-player-name');
  2476. player.unfriendPlayer(name); // Remove the blocked player from the list
  2477.  
  2478. Array.from(document.querySelectorAll(`.js-friends-list [data-player-name="${name}"]`)).forEach($element => {
  2479. $element.parentNode.removeChild($element);
  2480. });
  2481. });
  2482. });
  2483. Array.from(document.querySelectorAll('.js-friend-note')).forEach($element => {
  2484. $element.addEventListener('change', clickEvent => {
  2485. const name = clickEvent.target.getAttribute('data-player-name');
  2486. state.friendNotes[name] = clickEvent.target.value;
  2487. });
  2488. }); // The close button for our custom UI
  2489.  
  2490. document.querySelector('.js-close-custom-friends-list').addEventListener('click', removeFriendsList);
  2491. }
  2492.  
  2493. function removeFriendsList() {
  2494. const state = (0, _state.getState)();
  2495. const $friendsListWindow = document.querySelector('.js-friends-list');
  2496. $friendsListWindow.parentNode.removeChild($friendsListWindow); // Save Friends List UI's state as closed
  2497.  
  2498. state.openWindows['openFriendsList'] = false;
  2499. (0, _state.saveState)();
  2500. }
  2501.  
  2502. function toggleXpMeterVisibility() {
  2503. const state = (0, _state.getState)();
  2504. const xpMeterContainer = document.querySelector('.js-xpmeter');
  2505. xpMeterContainer.style.display = xpMeterContainer.style.display === 'none' ? 'block' : 'none';
  2506. state.openWindows.openXpMeter = xpMeterContainer.style.display === 'none' ? false : true;
  2507. (0, _state.saveState)();
  2508. }
  2509.  
  2510. function createXpMeter() {
  2511. const $layoutContainer = document.querySelector('body > div.layout > div.container:nth-child(1)');
  2512. const $dpsMeterToggleElement = document.querySelector('#systrophy');
  2513. const $xpMeterToggleElement = (0, _misc.makeElement)({
  2514. element: 'div',
  2515. class: 'js-sysxp js-xpmeter-icon btn border black',
  2516. content: 'XP'
  2517. });
  2518. const xpMeterHTMLString = `
  2519. <div class="l-corner-lr container uimod-xpmeter-1 js-xpmeter" style="display: none">
  2520. <div class="window panel-black uimod-xpmeter-2">
  2521. <div class="titleframe uimod-xpmeter-2">
  2522. <img src="/assets/ui/icons/trophy.svg?v=3282286" class="titleicon svgicon uimod-xpmeter-2">
  2523. <div class="textprimary title uimod-xpmeter-2">
  2524. <div name="title">Experience / XP</div>
  2525. </div>
  2526. <img src="/assets/ui/icons/cross.svg?v=3282286" class="js-xpmeter-close-icon btn black svgicon">
  2527. </div>
  2528. <div class="slot uimod-xpmeter-2" style="">
  2529. <div class="wrapper uimod-xpmeter-1">
  2530. <div class="bar uimod-xpmeter-3" style="z-index: 0;">
  2531. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  2532. <span class="left uimod-xpmeter-3">XP per minute:</span>
  2533. <span class="right uimod-xpmeter-3 js-xpm">-</span>
  2534. </div>
  2535. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  2536. <span class="left uimod-xpmeter-3">XP per hour:</span>
  2537. <span class="right uimod-xpmeter-3 js-xph">-</span>
  2538. </div>
  2539. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  2540. <span class="left uimod-xpmeter-3">XP Gained:</span>
  2541. <span class="right uimod-xpmeter-3 js-xpg">-</span>
  2542. </div>
  2543. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  2544. <span class="left uimod-xpmeter-3">XP Left:</span>
  2545. <span class="right uimod-xpmeter-3 js-xpl">-</span>
  2546. </div>
  2547. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  2548. <span class="left uimod-xpmeter-3">Session Time: </span>
  2549. <span class="right uimod-xpmeter-3 js-xp-s-time">-</span>
  2550. </div>
  2551. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  2552. <span class="left uimod-xpmeter-3">Time to lvl: </span>
  2553. <span class="right uimod-xpmeter-3 js-xp-time">-</span>
  2554. </div>
  2555. </div>
  2556. </div>
  2557. <div class="grid buttons marg-top uimod-xpmeter-1 js-xpmeter-reset-button">
  2558. <div class="btn grey">Reset</div>
  2559. </div>
  2560. </div>
  2561. </div>
  2562. </div>
  2563. `;
  2564. $dpsMeterToggleElement.parentNode.insertBefore($xpMeterToggleElement, $dpsMeterToggleElement.nextSibling);
  2565. const $xpMeterElement = (0, _misc.makeElement)({
  2566. element: 'div',
  2567. content: xpMeterHTMLString.trim()
  2568. });
  2569. $layoutContainer.appendChild($xpMeterElement.firstChild);
  2570. }
  2571.  
  2572. },{"./misc":27,"./player":28,"./state":29}],31:[function(require,module,exports){
  2573. "use strict";
  2574.  
  2575. Object.defineProperty(exports, "__esModule", {
  2576. value: true
  2577. });
  2578. exports.VERSION = exports.BREAKING_VERSION = void 0;
  2579. // If this version is different from the user's stored state,
  2580. // e.g. they have upgraded the version of this script and there are breaking changes,
  2581. // then their stored state will be deleted.
  2582. const BREAKING_VERSION = 1; // Used for initialization message in chat, and userscript version
  2583.  
  2584. exports.BREAKING_VERSION = BREAKING_VERSION;
  2585. const VERSION = '1.1.4';
  2586. exports.VERSION = VERSION;
  2587.  
  2588. },{}]},{},[1]);