Hordes UI Mod

Various UI mods for Hordes.io.

当前为 2020-01-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hordes UI Mod
  3. // @version 1.2.6.1
  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 chat context menu, invisible by default */
  12. .js-chat-context-menu {
  13. display: none; }
  14.  
  15. .js-chat-context-menu .name {
  16. color: white;
  17. padding: 2px 4px; }
  18.  
  19. /* Allow names in chat to be clicked (textf1 = BL, textf0 = VG) */
  20. #chat .name,
  21. .textwhisper .textf1,
  22. .textwhisper .textf0 {
  23. pointer-events: all !important; }
  24. /* Custom chat filter colors */
  25. .js-chat-gm {
  26. color: #a6dcd5; }
  27.  
  28. /* Class that hides chat lines */
  29. .js-line-hidden,
  30. .js-line-blocked {
  31. display: none; }
  32. /* Custom chat tabs */
  33. .uimod-chat-tabs {
  34. position: fixed;
  35. margin-top: -22px;
  36. left: 5px;
  37. pointer-events: all;
  38. color: #5b858e;
  39. font-size: 12px;
  40. font-weight: bold; }
  41.  
  42. .uimod-chat-tabs > div {
  43. cursor: pointer;
  44. background-color: rgba(0, 0, 0, 0.4);
  45. border-top-right-radius: 4px;
  46. border-top-left-radius: 4px;
  47. display: inline-block;
  48. border: 1px black solid;
  49. border-bottom: 0;
  50. margin-right: 2px;
  51. padding: 3px 5px; }
  52.  
  53. .uimod-chat-tabs > div:not(.js-selected-tab):hover {
  54. border-color: #aaa; }
  55.  
  56. .uimod-chat-tabs > .js-selected-tab {
  57. color: #fff; }
  58.  
  59. /* Chat tab custom config */
  60. .uimod-chat-tab-config {
  61. position: absolute;
  62. z-index: 9999999;
  63. background-color: rgba(0, 0, 0, 0.6);
  64. color: white;
  65. border-radius: 3px;
  66. text-align: center;
  67. padding: 8px 12px 8px 6px;
  68. width: 175px;
  69. font-size: 14px;
  70. border: 1px solid black;
  71. display: none; }
  72.  
  73. .uimod-chat-tab-config-grid {
  74. grid-template-columns: 35% 65%;
  75. display: grid;
  76. grid-gap: 6px;
  77. align-items: center; }
  78.  
  79. .uimod-chat-tab-config h1 {
  80. font-size: 16px;
  81. margin-top: 0; }
  82.  
  83. .uimod-chat-tab-config .btn,
  84. .uimod-chat-tab-config input {
  85. font-size: 12px; }
  86. /* Lazy way to get tables to display side by side, given they share their container with various other elements */
  87. .uimod-clan-lastseen-table {
  88. float: right;
  89. width: 25%;
  90. /* Make the last seen table look like its part of the main clan members table */
  91. position: relative;
  92. right: 1px;
  93. border-top-left-radius: 0;
  94. border-bottom-left-radius: 0; }
  95. .uimod-clan-lastseen-table tr.js-offline-member {
  96. opacity: 0.5; }
  97.  
  98. .uimod-clan-members-table {
  99. float: left;
  100. width: 75%; }
  101. /* Custom css for settings page, duplicates preexisting settings pane grid */
  102. .uimod-settings {
  103. display: grid;
  104. grid-template-columns: 2fr 3fr;
  105. grid-gap: 8px;
  106. align-items: center;
  107. max-height: 390px;
  108. margin: 0 20px;
  109. overflow-y: auto; }
  110. /* Allows windows and frames to be moved */
  111. .window,
  112. .partyframes,
  113. #ufplayer,
  114. #uftarget,
  115. #skillbar,
  116. .js-map {
  117. position: relative; }
  118.  
  119. /* Retaining the default party frame with so we can override the "style" property */
  120. .partyframes {
  121. width: 200px; }
  122.  
  123. /* All purpose hidden class */
  124. .js-hidden {
  125. display: none; }
  126. /* Friends list CSS, similar to settings but supports 4 columns */
  127. .uimod-friends {
  128. display: grid;
  129. grid-template-columns: 2fr 1.1fr 1.5fr 0.33fr 3fr;
  130. grid-gap: 8px;
  131. align-items: center;
  132. max-height: 390px;
  133. margin: 0 20px;
  134. overflow-y: auto; }
  135.  
  136. /* Helps imitate normal UI window */
  137. .uimod-friends-list-helper.titleframe {
  138. line-height: 1em;
  139. display: flex;
  140. align-items: start;
  141. position: relative;
  142. letter-spacing: 0.5px;
  143. margin-top: 8px; }
  144.  
  145. .uimod-friends-list-helper.titleicon {
  146. margin: 3px; }
  147.  
  148. .uimod-friends-list-helper.title {
  149. width: 100%;
  150. padding-left: 4px;
  151. font-weight: bold; }
  152.  
  153. .uimod-friends-intro {
  154. width: 100%;
  155. margin: 4px 0 14px;
  156. text-align: center;
  157. border-bottom: 2px solid #999;
  158. padding-bottom: 6px;
  159. font-weight: bold;
  160. user-select: none; }
  161. .uimod-locked-slot {
  162. pointer-events: all;
  163. z-index: 10;
  164. background: rgba(255, 0, 0, 0.4);
  165. position: absolute;
  166. width: 46px;
  167. height: 46px; }
  168. .js-map-btns {
  169. position: absolute;
  170. top: 8px;
  171. right: 8px;
  172. z-index: 999;
  173. width: 100px;
  174. height: 100px;
  175. text-align: right;
  176. display: none;
  177. pointer-events: all; }
  178.  
  179. .js-map-btns:hover {
  180. display: block; }
  181.  
  182. .js-map-btns button {
  183. border-radius: 10px;
  184. font-size: 18px;
  185. padding: 0 5px;
  186. background: rgba(0, 0, 0, 0.4);
  187. border: 0;
  188. color: white;
  189. font-weight: bold;
  190. cursor: pointer; }
  191.  
  192. /* On hover of map, show opacity controls */
  193. .js-map:hover .js-map-btns {
  194. display: block; }
  195. /* Mirror styles of other merchant inputs */
  196. .uidom-merchant-input {
  197. margin: 4px 0;
  198. align-self: center; }
  199.  
  200. /* Add 225px column for new filters input */
  201. .uidom-merchant-with-filters .search {
  202. grid-template-columns: 120px auto 50px auto 50px 225px 1fr auto auto; }
  203. .js-chat-resize {
  204. resize: both;
  205. overflow: auto; }
  206. .js-map {
  207. /* This makes sure scroll bars don't appear when resizing the map */
  208. overflow: hidden; }
  209.  
  210. .js-map-resize:hover {
  211. resize: both;
  212. overflow: auto;
  213. direction: rtl; }
  214. /* Allows last clicked window to appear above all other windows */
  215. .js-is-top {
  216. z-index: 9998 !important; }
  217.  
  218. .panel.context:not(.commandlist) {
  219. z-index: 9999 !important; }
  220.  
  221. /* The item icon being dragged in the inventory */
  222. .container.svelte-120o2pb {
  223. z-index: 9999 !important; }
  224. .js-cooldown-num {
  225. position: absolute;
  226. bottom: 10px;
  227. left: 0;
  228. width: 40px;
  229. text-align: center;
  230. font-weight: bold;
  231. color: white;
  232. pointer-events: none; }
  233. .container.uimod-xpmeter-1 {
  234. z-index: 6; }
  235.  
  236. .window.uimod-xpmeter-2 {
  237. padding: 5px;
  238. height: 100%;
  239. display: grid;
  240. grid-template-rows: 30px 1fr;
  241. grid-gap: 4px;
  242. transform-origin: inherit;
  243. min-width: fit-content; }
  244.  
  245. .titleframe.uimod-xpmeter-2 {
  246. line-height: 1em;
  247. display: flex;
  248. align-items: center;
  249. position: relative;
  250. letter-spacing: 0.5px; }
  251.  
  252. .titleicon.uimod-xpmeter-2 {
  253. margin: 3px; }
  254.  
  255. .title.uimod-xpmeter-2 {
  256. width: 100%;
  257. padding-left: 4px;
  258. font-weight: bold; }
  259.  
  260. .slot.uimod-xpmeter-2 {
  261. min-height: 0; }
  262.  
  263. .wrapper.uimod-xpmeter-1 {
  264. width: 200px; }
  265.  
  266. .bar.uimod-xpmeter-3 {
  267. background-color: rgba(45, 66, 71, 0.7);
  268. border-radius: 1.5px;
  269. position: relative;
  270. color: #DAE8EA;
  271. overflow: hidden;
  272. text-shadow: 1px 1px 2px #10131d;
  273. white-space: nowrap;
  274. text-transform: capitalize;
  275. font-weight: bold; }
  276.  
  277. .buttons.uimod-xpmeter-1 {
  278. line-height: 1;
  279. font-size: 13px; }
  280.  
  281. .left.uimod-xpmeter-3 {
  282. padding-left: 4px;
  283. position: relative;
  284. z-index: 1; }
  285.  
  286. .right.uimod-xpmeter-3 {
  287. position: absolute;
  288. right: 7px;
  289. z-index: 1; }
  290. /* This file is for CSS mods that don't fit in any other individual mod folder */
  291. /* Transparent chat bg color */
  292. .frame.svelte-1vrlsr3 {
  293. background: rgba(0, 0, 0, 0.4); }
  294.  
  295. /* Our mod's chat message color */
  296. .textuimod {
  297. color: #00dd33; }
  298.  
  299. /* The browser resize icon */
  300. *::-webkit-resizer {
  301. background: linear-gradient(to right, rgba(51, 77, 80, 0), rgba(203, 202, 165, 0.5));
  302. border-radius: 8px;
  303. box-shadow: 0 1px 1px black; }
  304.  
  305. *::-moz-resizer {
  306. background: linear-gradient(to right, rgba(51, 77, 80, 0), rgba(203, 202, 165, 0.5));
  307. border-radius: 8px;
  308. box-shadow: 0 1px 1px black; }
  309.  
  310. /* Our custom window, closely mirrors main settings window */
  311. .uimod-custom-window {
  312. position: absolute;
  313. top: 100px;
  314. left: 50%;
  315. transform: translate(-50%, 0);
  316. min-width: 350px;
  317. max-width: 600px;
  318. width: 90%;
  319. height: 80%;
  320. min-height: 350px;
  321. max-height: 500px;
  322. z-index: 9;
  323. padding: 0px 10px 5px; }
  324. `);
  325.  
  326. (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){
  327. "use strict";
  328.  
  329. var _mods = _interopRequireDefault(require("./mods"));
  330.  
  331. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  332.  
  333. function initialize() {
  334. // If the Hordes.io tab isn't active for long enough, it reloads the entire page, clearing this mod
  335. // We check for that and reinitialize the mod if that happens
  336. const $layout = document.querySelector('.layout');
  337.  
  338. if ($layout.classList.contains('uimod-initd')) {
  339. return;
  340. }
  341.  
  342. $layout.classList.add('uimod-initd');
  343. const rerunning = {
  344. // MutationObserver running whenever .layout changes
  345. onDomChange: [],
  346. // Mutation observer running whenever #chat changes
  347. onChatChange: [],
  348. // `click` Event listener running on document.body
  349. onLeftClick: [],
  350. // `contextmenu` Event listener running on document.body
  351. onRightClick: []
  352. }; // Run all our mods
  353.  
  354. const registerOnDomChange = callback => rerunning.onDomChange.push(callback);
  355.  
  356. const registerOnChatChange = callback => rerunning.onChatChange.push(callback);
  357.  
  358. const registerOnLeftClick = callback => rerunning.onLeftClick.push(callback);
  359.  
  360. const registerOnRightClick = callback => rerunning.onRightClick.push(callback);
  361.  
  362. _mods.default.forEach(mod => {
  363. mod.run({
  364. registerOnDomChange,
  365. registerOnChatChange,
  366. registerOnLeftClick,
  367. registerOnRightClick
  368. });
  369. }); // Continuously re-run specific mods methods that need to be executed on UI change
  370.  
  371.  
  372. const rerunObserver = new MutationObserver(mutations => {
  373. // If new window appears, e.g. even if window is closed and reopened, we need to rewire it
  374. // Fun fact: Some windows always exist in the DOM, even when hidden, e.g. Inventory
  375. // But some windows only exist in the DOM when open, e.g. Interaction
  376. rerunning.onDomChange.forEach(callback => callback(mutations));
  377. });
  378. Array.from(document.querySelectorAll('.layout > .container, .actionbarcontainer, .partyframes, .targetframes')).forEach($container => {
  379. rerunObserver.observe($container, {
  380. attributes: false,
  381. childList: true
  382. });
  383. }); // Rerun only on chat messages changing
  384.  
  385. const chatRerunObserver = new MutationObserver(mutations => {
  386. rerunning.onChatChange.forEach(callback => callback(mutations));
  387. });
  388. chatRerunObserver.observe(document.querySelector('#chat'), {
  389. attributes: false,
  390. childList: true
  391. }); // Event listeners for document.body might be kept when the game reloads, so don't reinitialize them
  392.  
  393. if (!document.body.classList.contains('js-uimod-initd')) {
  394. document.body.classList.add('js-uimod-initd');
  395. rerunning.onLeftClick.forEach(callback => document.body.addEventListener('click', callback));
  396. rerunning.onRightClick.forEach(callback => document.body.addEventListener('contextmenu', callback));
  397. }
  398. } // Initialize mods once UI DOM has loaded
  399. // Rerunning updates on every call to initialize
  400.  
  401.  
  402. const pageObserver = new MutationObserver(() => {
  403. const isUiLoaded = !!document.querySelector('.layout');
  404.  
  405. if (isUiLoaded) {
  406. initialize();
  407. }
  408. });
  409. pageObserver.observe(document.body, {
  410. attributes: true,
  411. childList: true
  412. });
  413.  
  414. },{"./mods":17}],2:[function(require,module,exports){
  415. "use strict";
  416.  
  417. Object.defineProperty(exports, "__esModule", {
  418. value: true
  419. });
  420. exports.default = void 0;
  421.  
  422. var _state = require("../../utils/state");
  423.  
  424. // Note: For a split second after these event handlers are added,
  425. // They may not actually be listening.
  426. // e.g. Refresh page with inventory open, immediately control+right click item
  427. // to copy its stats. It won't work because `keydown` didn't register the keydown event yet
  428. // Doesn't look like there's anything we can do about it, just something to keep in mind.
  429. function keyPressTracker() {
  430. const tempState = (0, _state.getTempState)();
  431. window.addEventListener('keydown', keyEvent => {
  432. if (keyEvent.key === 'Control') {
  433. tempState.keyModifiers.control = true;
  434. } else if (keyEvent.key === 'Alt') {
  435. tempState.keyModifiers.alt = true;
  436. } else if (keyEvent.key === 'Shift') {
  437. // Shouldn't set keyModifiers.shift if we're programatically doing it while getting tooltip content
  438. // tempState.gettingTooltipContentShiftPress should only be `true` if user already isn't pressing shift
  439. // See game.js `getTooltipContent` for more details
  440. if (tempState.gettingTooltipContentShiftPress) {
  441. return;
  442. }
  443.  
  444. tempState.keyModifiers.shift = true;
  445. }
  446. });
  447. window.addEventListener('keyup', keyEvent => {
  448. if (keyEvent.key === 'Control') {
  449. tempState.keyModifiers.control = false;
  450. } else if (keyEvent.key === 'Alt') {
  451. tempState.keyModifiers.alt = false;
  452. } else if (keyEvent.key === 'Shift') {
  453. tempState.keyModifiers.shift = false;
  454. }
  455. }); // If page ever regains focus, e.g. tabbing back in after tabbing out, make sure we reset our modifiers.
  456. // This prevents things like holding control, leaving the tab without releasing it, then coming back in and
  457. // the game will think you are still holding it, even if you're not.
  458.  
  459. window.addEventListener('focus', () => {
  460. tempState.keyModifiers.control = false;
  461. tempState.keyModifiers.alt = false;
  462. tempState.keyModifiers.shift = false;
  463. });
  464. }
  465.  
  466. var _default = {
  467. name: '[REQUIRED] Key press tracker',
  468. description: 'Identifies when you are pressing Ctrl/etc key modifiers, which is used by some other mods',
  469. run: keyPressTracker
  470. };
  471. exports.default = _default;
  472.  
  473. },{"../../utils/state":37}],3:[function(require,module,exports){
  474. "use strict";
  475.  
  476. Object.defineProperty(exports, "__esModule", {
  477. value: true
  478. });
  479. exports.default = void 0;
  480.  
  481. var chat = _interopRequireWildcard(require("../../utils/chat"));
  482.  
  483. var _version = require("../../utils/version");
  484.  
  485. var _state = require("../../utils/state");
  486.  
  487. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  488.  
  489. 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; }
  490.  
  491. function modStart() {
  492. chat.addChatMessage(`Hordes UI Mod v${_version.VERSION} is now running.`);
  493. (0, _state.loadState)();
  494. }
  495.  
  496. var _default = {
  497. name: '[REQUIRED] UI Mod Startup',
  498. description: 'Do not remove this! This displays a welcome message, loads saved state, and includes misc styles.',
  499. run: modStart
  500. };
  501. exports.default = _default;
  502.  
  503. },{"../../utils/chat":33,"../../utils/state":37,"../../utils/version":39}],4:[function(require,module,exports){
  504. "use strict";
  505.  
  506. Object.defineProperty(exports, "__esModule", {
  507. value: true
  508. });
  509. exports.showChatContextMenu = showChatContextMenu;
  510.  
  511. var _state = require("../../utils/state");
  512.  
  513. // Makes chat context menu visible and appear under the mouse
  514. function showChatContextMenu(name, mousePos) {
  515. const state = (0, _state.getState)(); // Right before we show the context menu, we want to handle showing/hiding Friend/Unfriend
  516.  
  517. const $contextMenu = document.querySelector('.js-chat-context-menu');
  518. $contextMenu.querySelector('[name="friend"]').classList.toggle('js-hidden', !!state.friendsList[name]);
  519. $contextMenu.querySelector('[name="unfriend"]').classList.toggle('js-hidden', !state.friendsList[name]);
  520. $contextMenu.querySelector('.js-name').textContent = name;
  521. $contextMenu.setAttribute('style', `display: block; left: ${mousePos.x}px; top: ${mousePos.y}px;`);
  522. }
  523.  
  524. },{"../../utils/state":37}],5:[function(require,module,exports){
  525. "use strict";
  526.  
  527. Object.defineProperty(exports, "__esModule", {
  528. value: true
  529. });
  530. exports.default = void 0;
  531.  
  532. var _state = require("../../utils/state");
  533.  
  534. var _misc = require("../../utils/misc");
  535.  
  536. var helpers = _interopRequireWildcard(require("./helpers"));
  537.  
  538. var chat = _interopRequireWildcard(require("../../utils/chat"));
  539.  
  540. var player = _interopRequireWildcard(require("../../utils/player"));
  541.  
  542. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  543.  
  544. 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; }
  545.  
  546. // This creates the initial chat context menu DOM (which starts as hidden)
  547. function createChatContextMenu() {
  548. const tempState = (0, _state.getTempState)();
  549.  
  550. if (document.querySelector('.js-chat-context-menu')) {
  551. return;
  552. }
  553.  
  554. let contextMenuHTML = `
  555. <div class="js-name">...</div>
  556. <div class="choice" name="party">Party invite</div>
  557. <div class="choice" name="whisper">Whisper</div>
  558. <div class="choice" name="friend">Friend</div>
  559. <div class="choice" name="unfriend">Unfriend</div>
  560. <div class="choice" name="copy">Copy name</div>
  561. <div class="choice" name="block">Block</div>
  562. `;
  563. document.body.appendChild((0, _misc.makeElement)({
  564. element: 'div',
  565. class: 'panel context border grey js-chat-context-menu',
  566. content: contextMenuHTML
  567. }));
  568. const $chatContextMenu = document.querySelector('.js-chat-context-menu');
  569. $chatContextMenu.querySelector('[name="party"]').addEventListener('click', () => {
  570. chat.partyPlayer(tempState.chatName);
  571. });
  572. $chatContextMenu.querySelector('[name="whisper"]').addEventListener('click', () => {
  573. chat.whisperPlayer(tempState.chatName);
  574. });
  575. $chatContextMenu.querySelector('[name="friend"]').addEventListener('click', () => {
  576. player.friendPlayer(tempState.chatName);
  577. });
  578. $chatContextMenu.querySelector('[name="unfriend"]').addEventListener('click', () => {
  579. player.unfriendPlayer(tempState.chatName);
  580. });
  581. $chatContextMenu.querySelector('[name="copy"]').addEventListener('click', () => {
  582. navigator.clipboard.writeText(tempState.chatName);
  583. });
  584. $chatContextMenu.querySelector('[name="block"]').addEventListener('click', () => {
  585. player.blockPlayer(tempState.chatName);
  586. });
  587. } // This opens a context menu when you click a user's name in chat
  588.  
  589.  
  590. function chatContextMenu() {
  591. const tempState = (0, _state.getTempState)();
  592.  
  593. const addContextMenu = ($name, name) => {
  594. $name.classList.add('js-is-context-menu-initd'); // Add name to element so we can target it in CSS, e.g. when filtering chat for block list
  595.  
  596. $name.setAttribute('data-chat-name', name);
  597.  
  598. const showContextMenu = clickEvent => {
  599. // TODO: Is there a way to pass the name to showChatContextMenumethod, instead of storing in tempState?
  600. tempState.chatName = name;
  601. helpers.showChatContextMenu(name, {
  602. x: clickEvent.pageX,
  603. y: clickEvent.pageY
  604. });
  605. };
  606.  
  607. $name.addEventListener('click', showContextMenu); // Left click
  608.  
  609. $name.addEventListener('contextmenu', showContextMenu); // Right click works too
  610. };
  611.  
  612. Array.from(document.querySelectorAll('#chat .name:not(.js-is-context-menu-initd)')).forEach($name => {
  613. addContextMenu($name, $name.textContent);
  614. }); // `textf0` is the VG faction, `textf1` is the BL faction - we want to support both with our whisper context menu
  615.  
  616. Array.from(document.querySelectorAll('.textwhisper .textf1:not(.js-is-context-menu-initd), .textwhisper .textf0:not(.js-is-context-menu-initd)')).forEach($whisperName => {
  617. // $whisperName's textContent is "to [name]" or "from [name]", so we cut off the first word
  618. let name = $whisperName.textContent.split(' ');
  619. name.shift(); // Remove the first word
  620.  
  621. name = name.join(' ');
  622. addContextMenu($whisperName, name);
  623. });
  624. } // Close chat context menu if clicking outside of it
  625.  
  626.  
  627. function closeChatContextMenu(clickEvent) {
  628. const $target = clickEvent.target; // If clicking on name or directly on context menu, don't close it
  629. // Still closes if clicking on context menu item
  630.  
  631. if ($target.classList.contains('js-is-context-menu-initd') || $target.classList.contains('js-chat-context-menu')) {
  632. return;
  633. }
  634.  
  635. const $contextMenu = document.querySelector('.js-chat-context-menu');
  636. $contextMenu.style.display = 'none';
  637. }
  638.  
  639. var _default = {
  640. name: 'Chat Context Menu',
  641. description: 'Displays a menu when you click on a player, allowing you to whisper/party/friend/block them',
  642. run: ({
  643. registerOnLeftClick,
  644. registerOnChatChange
  645. }) => {
  646. createChatContextMenu();
  647. chatContextMenu(); // When we click anywhere on the page outside of our chat context menu, we want to close the menu
  648.  
  649. registerOnLeftClick(closeChatContextMenu); // Register event listeners for each name when a new chat message appears
  650.  
  651. registerOnChatChange(chatContextMenu);
  652. }
  653. };
  654. exports.default = _default;
  655.  
  656. },{"../../utils/chat":33,"../../utils/misc":35,"../../utils/player":36,"../../utils/state":37,"./helpers":4}],6:[function(require,module,exports){
  657. "use strict";
  658.  
  659. Object.defineProperty(exports, "__esModule", {
  660. value: true
  661. });
  662. exports.default = void 0;
  663.  
  664. var chat = _interopRequireWildcard(require("../../utils/chat"));
  665.  
  666. var _state = require("../../utils/state");
  667.  
  668. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  669.  
  670. 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; }
  671.  
  672. // Remove GM chat filter state for users of v1.2.5 and prior
  673. function removeGmChatFilter() {
  674. const state = (0, _state.getState)();
  675. let stateUpdated = false;
  676. state.chatTabs = state.chatTabs.map(chatTabState => {
  677. if (!chatTabState) return chatTabState;
  678.  
  679. if (chatTabState.filters && chatTabState.filters.hasOwnProperty('gm')) {
  680. delete chatTabState.filters.gm;
  681. stateUpdated = true;
  682. }
  683.  
  684. return chatTabState;
  685. });
  686.  
  687. if (state.chat) {
  688. delete state.chat;
  689. stateUpdated = true;
  690. }
  691.  
  692. if (stateUpdated) (0, _state.saveState)();
  693. }
  694.  
  695. var _default = {
  696. name: 'Chat filters',
  697. description: "Filters all chat, e.g. ensuring blocked users' messages are not visible in chat.",
  698. run: ({
  699. registerOnChatChange
  700. }) => {
  701. removeGmChatFilter(); // Whenever chat changes, we want to filter it
  702.  
  703. registerOnChatChange(chat.filterAllChat);
  704. }
  705. };
  706. exports.default = _default;
  707.  
  708. },{"../../utils/chat":33,"../../utils/state":37}],7:[function(require,module,exports){
  709. "use strict";
  710.  
  711. Object.defineProperty(exports, "__esModule", {
  712. value: true
  713. });
  714. exports.showChatTabConfigWindow = showChatTabConfigWindow;
  715. exports.addChatTab = addChatTab;
  716. exports.selectChatTab = selectChatTab;
  717. exports.getCurrentChatFilters = getCurrentChatFilters;
  718.  
  719. var _state = require("../../utils/state");
  720.  
  721. var _misc = require("../../utils/misc");
  722.  
  723. const DEFAULT_CHAT_TAB_NAME = 'Untitled'; // Gets current chat filters as represented in the UI
  724. // filter being true means it's invisible(filtered) in chat
  725. // filter being false means it's visible(unfiltered) in chat
  726.  
  727. function getCurrentChatFilters() {
  728. // Saved by the official game client
  729. const gameFilters = JSON.parse(localStorage.getItem('filteredChannels'));
  730. return {
  731. global: gameFilters.includes('global'),
  732. faction: gameFilters.includes('faction'),
  733. party: gameFilters.includes('party'),
  734. clan: gameFilters.includes('clan'),
  735. pvp: gameFilters.includes('pvp'),
  736. inv: gameFilters.includes('inv')
  737. };
  738. } // Shows the chat tab config window for a specific tab, displayed in a specific position
  739.  
  740.  
  741. function showChatTabConfigWindow(tabId, pos) {
  742. const state = (0, _state.getState)();
  743. const tempState = (0, _state.getTempState)();
  744. const $chatTabConfig = document.querySelector('.js-chat-tab-config');
  745. const chatTab = state.chatTabs.find(tab => tab.id === tabId); // Update position and name in chat tab config
  746.  
  747. $chatTabConfig.style.left = `${pos.x}px`;
  748. $chatTabConfig.style.top = `${pos.y}px`;
  749. $chatTabConfig.querySelector('.js-chat-tab-name').value = chatTab.name; // Store tabId in state, to be used by the Remove/Add buttons in config window
  750.  
  751. tempState.editedChatTabId = tabId; // Hide remove button if only one chat tab left - can't remove last one
  752. // Show it if more than one chat tab left
  753.  
  754. const chatTabCount = Object.keys(state.chatTabs).length;
  755. const $removeChatTabBtn = $chatTabConfig.querySelector('.js-remove-chat-tab');
  756. $removeChatTabBtn.style.display = chatTabCount < 2 ? 'none' : 'block'; // Show chat tab config
  757.  
  758. $chatTabConfig.style.display = 'block';
  759. } // Adds chat tab to DOM, sets it as selected
  760. // If argument chatTab is provided, will use that name+id
  761. // If no argument is provided, will create new tab name/id and add it to state
  762. // isInittingTab is optional boolean, if `true`, will _not_ set added tab as selected. Used when initializing all chat tabs on load
  763. // Returns newly added tabId
  764.  
  765.  
  766. function addChatTab(chatTab, isInittingTab) {
  767. const state = (0, _state.getState)();
  768. let tabName = DEFAULT_CHAT_TAB_NAME;
  769. let tabId = (0, _misc.uuid)();
  770.  
  771. if (chatTab) {
  772. tabName = chatTab.name;
  773. tabId = chatTab.id;
  774. } else {
  775. // If no chat tab was provided, create it in state
  776. state.chatTabs.push({
  777. name: tabName,
  778. id: tabId,
  779. filters: getCurrentChatFilters()
  780. });
  781. (0, _state.saveState)();
  782. }
  783.  
  784. const $tabs = document.querySelector('.js-chat-tabs');
  785. const $tab = (0, _misc.makeElement)({
  786. element: 'div',
  787. content: tabName
  788. });
  789. $tab.setAttribute('data-tab-id', tabId); // Add chat tab to DOM
  790.  
  791. $tabs.appendChild($tab); // Wire chat tab up to open config on right click
  792.  
  793. $tab.addEventListener('contextmenu', clickEvent => {
  794. const mousePos = {
  795. x: clickEvent.pageX,
  796. y: clickEvent.pageY
  797. };
  798. showChatTabConfigWindow(tabId, mousePos);
  799. }); // And select chat tab on left click
  800.  
  801. $tab.addEventListener('click', () => {
  802. selectChatTab(tabId);
  803. });
  804.  
  805. if (!isInittingTab) {
  806. // Select the newly added chat tab
  807. selectChatTab(tabId);
  808. } // Returning tabId to all adding new tab to pass tab ID to `showChatTabConfigWindow`
  809.  
  810.  
  811. return tabId;
  812. } // Selects chat tab [on click], updating client chat filters and custom chat filters
  813.  
  814.  
  815. function selectChatTab(tabId) {
  816. const state = (0, _state.getState)(); // Remove selected class from everything, then add selected class to clicked tab
  817.  
  818. Array.from(document.querySelectorAll('[data-tab-id]')).forEach($tab => {
  819. $tab.classList.remove('js-selected-tab');
  820. });
  821. const $tab = document.querySelector(`[data-tab-id="${tabId}"]`);
  822. $tab.classList.add('js-selected-tab');
  823. const tabFilters = state.chatTabs.find(tab => tab.id === tabId).filters; // Simulating clicks on the filters to turn them on/off
  824.  
  825. const $filterButtons = Array.from(document.querySelectorAll('.channelselect small'));
  826. Object.keys(tabFilters).forEach(filter => {
  827. const $filterButton = $filterButtons.find($btn => $btn.textContent === filter);
  828. const isCurrentlyFiltered = $filterButton.classList.contains('textgrey'); // If is currently filtered but filter for this tab is turned off, click it to turn filter off
  829.  
  830. if (isCurrentlyFiltered && !tabFilters[filter]) {
  831. $filterButton.click();
  832. } // If it is not currently filtered but filter for this tab is turned on, click it to turn filter on
  833.  
  834.  
  835. if (!isCurrentlyFiltered && tabFilters[filter]) {
  836. $filterButton.click();
  837. }
  838. }); // Update the selected tab in state
  839.  
  840. state.selectedChatTabId = tabId;
  841. (0, _state.saveState)();
  842. }
  843.  
  844. },{"../../utils/misc":35,"../../utils/state":37}],8:[function(require,module,exports){
  845. "use strict";
  846.  
  847. Object.defineProperty(exports, "__esModule", {
  848. value: true
  849. });
  850. exports.default = void 0;
  851.  
  852. var helpers = _interopRequireWildcard(require("./helpers"));
  853.  
  854. var _state = require("../../utils/state");
  855.  
  856. var _misc = require("../../utils/misc");
  857.  
  858. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  859.  
  860. 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; }
  861.  
  862. // Creates DOM elements and wires them up for custom chat tabs and chat tab config
  863. // Note: Should be done after creating new custom chat filters
  864. function customChatTabs() {
  865. const state = (0, _state.getState)();
  866. const tempState = (0, _state.getTempState)(); // Create the chat tab configuration DOM
  867.  
  868. const $chatTabConfigurator = (0, _misc.makeElement)({
  869. element: 'div',
  870. class: 'uimod-chat-tab-config js-chat-tab-config',
  871. content: `
  872. <h1>Chat Tab Config</h1>
  873. <div class="uimod-chat-tab-config-grid">
  874. <div>Name</div><input type="text" class="js-chat-tab-name" value="untitled"></input>
  875. <div class="btn orange js-remove-chat-tab">Remove</div><div class="btn blue js-save-chat-tab">Ok</div>
  876. </div>
  877. `
  878. });
  879. document.body.append($chatTabConfigurator); // Wire it up
  880.  
  881. document.querySelector('.js-remove-chat-tab').addEventListener('click', () => {
  882. // Remove the chat tab from state
  883. const editedChatTab = state.chatTabs.find(tab => tab.id === tempState.editedChatTabId);
  884. const editedChatTabIndex = state.chatTabs.indexOf(editedChatTab);
  885. state.chatTabs.splice(editedChatTabIndex, 1); // Remove the chat tab from DOM
  886.  
  887. const $chatTab = document.querySelector(`[data-tab-id="${tempState.editedChatTabId}"]`);
  888. $chatTab.parentNode.removeChild($chatTab); // If we just removed the currently selected chat tab
  889.  
  890. if (tempState.editedChatTabId === state.selectedChatTabId) {
  891. // Select the chat tab to the left of the removed one
  892. const nextChatTabIndex = editedChatTabIndex === 0 ? 0 : editedChatTabIndex - 1;
  893. helpers.selectChatTab(state.chatTabs[nextChatTabIndex].id);
  894. } // Close chat tab config
  895.  
  896.  
  897. document.querySelector('.js-chat-tab-config').style.display = 'none';
  898. });
  899. document.querySelector('.js-save-chat-tab').addEventListener('click', () => {
  900. // Set new chat tab name in DOM
  901. const $chatTab = document.querySelector(`[data-tab-id="${state.selectedChatTabId}"]`);
  902. const newName = document.querySelector('.js-chat-tab-name').value;
  903. $chatTab.textContent = newName; // Set new chat tab name in state
  904. // `selectedChatTab` is a reference on `state.chatTabs`, so updating it above still updates it in the state - we want to save that
  905.  
  906. const selectedChatTab = state.chatTabs.find(tab => tab.id === state.selectedChatTabId);
  907. selectedChatTab.name = newName;
  908. (0, _state.saveState)(); // Close chat tab config
  909.  
  910. document.querySelector('.js-chat-tab-config').style.display = 'none';
  911. }); // Create the initial chat tabs HTML
  912.  
  913. const $chat = document.querySelector('#chat');
  914. const $chatTabs = (0, _misc.makeElement)({
  915. element: 'div',
  916. class: 'uimod-chat-tabs js-chat-tabs',
  917. content: '<div class="js-chat-tab-add">+</div>'
  918. }); // Add them to the DOM
  919.  
  920. $chat.parentNode.insertBefore($chatTabs, $chat); // Add all our chat tabs from state
  921.  
  922. state.chatTabs.forEach(chatTab => {
  923. const isInittingTab = true;
  924. helpers.addChatTab(chatTab, isInittingTab);
  925. }); // Wire up the add chat tab button
  926.  
  927. document.querySelector('.js-chat-tab-add').addEventListener('click', clickEvent => {
  928. const chatTabId = helpers.addChatTab();
  929. const mousePos = {
  930. x: clickEvent.pageX,
  931. y: clickEvent.pageY
  932. };
  933. helpers.showChatTabConfigWindow(chatTabId, mousePos);
  934. }); // If initial chat tab doesn't exist, create it based off current filter settings
  935.  
  936. if (!Object.keys(state.chatTabs).length) {
  937. const tabId = (0, _misc.uuid)();
  938. const chatTab = {
  939. name: 'Main',
  940. id: tabId,
  941. filters: helpers.getCurrentChatFilters()
  942. };
  943. state.chatTabs.push(chatTab);
  944. (0, _state.saveState)();
  945. helpers.addChatTab(chatTab);
  946. } // Wire up click event handlers onto the filters to update the selected chat tab's filters in state
  947.  
  948.  
  949. document.querySelector('.channelselect').addEventListener('click', clickEvent => {
  950. const $elementMouseIsOver = document.elementFromPoint(clickEvent.clientX, clickEvent.clientY); // We only want to change the filters if the user manually clicks the filter button
  951. // If they clicked a chat tab and we programatically set filters, we don't want to update
  952. // the current tab's filter state
  953.  
  954. if (!$elementMouseIsOver.classList.contains('btn')) {
  955. return;
  956. }
  957.  
  958. const selectedChatTab = state.chatTabs.find(tab => tab.id === state.selectedChatTabId);
  959. selectedChatTab.filters = helpers.getCurrentChatFilters();
  960. (0, _state.saveState)();
  961. }); // Select the currently selected tab in state on mod initialization
  962.  
  963. if (state.selectedChatTabId) {
  964. helpers.selectChatTab(state.selectedChatTabId);
  965. }
  966. }
  967.  
  968. function cleanCustomChatTabState() {
  969. const state = (0, _state.getState)();
  970. let stateUpdated = true;
  971. state.chatTabs = state.chatTabs.filter(chatTab => {
  972. if (!chatTab) {
  973. stateUpdated = true;
  974. return false;
  975. }
  976.  
  977. return true;
  978. });
  979. if (stateUpdated) (0, _state.saveState)();
  980. }
  981.  
  982. var _default = {
  983. name: 'Chat tabs',
  984. description: 'Enables support for multiple chat tabs',
  985. run: () => {
  986. cleanCustomChatTabState();
  987. customChatTabs();
  988. }
  989. };
  990. exports.default = _default;
  991.  
  992. },{"../../utils/misc":35,"../../utils/state":37,"./helpers":7}],9:[function(require,module,exports){
  993. "use strict";
  994.  
  995. Object.defineProperty(exports, "__esModule", {
  996. value: true
  997. });
  998. exports.handleClanWindowChange = handleClanWindowChange;
  999.  
  1000. var _misc = require("../../utils/misc");
  1001.  
  1002. var _state = require("../../utils/state");
  1003.  
  1004. function _lastSeenFromTimestamp(ts) {
  1005. if (!ts) return 'Never';
  1006. const nowTs = Date.now();
  1007. const seconds = (nowTs - ts) / 1000; // Divide by 1000 because Date.now returns milliseconds
  1008.  
  1009. const minutes = seconds / 60;
  1010. const hours = minutes / 60;
  1011. const days = hours / 24;
  1012. const weeks = days / 7;
  1013. const months = weeks / 30;
  1014. const years = months / 12;
  1015.  
  1016. const getPluralizedText = (num, word) => {
  1017. num = Math.round(num);
  1018. return num === 1 ? `${num} ${word}` : `${num} ${word}s`;
  1019. };
  1020.  
  1021. if (seconds < 60) return `${getPluralizedText(seconds, 'second')} ago`;
  1022. if (minutes < 60) return `${getPluralizedText(minutes, 'minute')} ago`;
  1023. if (hours < 24) return `${getPluralizedText(hours, 'hour')} ago`;
  1024. if (days < 7) return `${getPluralizedText(days, 'day')} ago`;
  1025. if (days < 30) return `${getPluralizedText(weeks, 'week')} ago`;
  1026. if (months < 12) return `${getPluralizedText(months, 'month')} ago`;
  1027. return `${getPluralizedText(years, 'year')} ago`;
  1028. }
  1029.  
  1030. function _handleClanMemberTableChange() {
  1031. const state = (0, _state.getState)();
  1032. const $clanLastSeenTable = document.querySelector('.js-clan-lastseen-table');
  1033. const $clanMemberTable = document.querySelector('.js-clan-members-table-initd'); // Update+Save current online users last seen time
  1034.  
  1035. const currentTimestamp = Date.now();
  1036. const $memberNames = Array.from($clanMemberTable.querySelectorAll('tr .name'));
  1037. const latestMemberNames = [];
  1038. $memberNames.map($name => {
  1039. const isOnline = !$name.parentNode.parentNode.classList.contains('offline');
  1040. const name = $name.textContent.trim();
  1041.  
  1042. if (isOnline) {
  1043. // Update current timestamp of online members
  1044. state.clanLastActiveMembers[name] = currentTimestamp;
  1045. } else if (!state.clanLastActiveMembers.hasOwnProperty(name)) {
  1046. // If not existing in state, add them so that we can check update their last seen time when they type in chat (See `refreshLastSeenClanMember`)
  1047. state.clanLastActiveMembers[name] = null;
  1048. }
  1049.  
  1050. latestMemberNames.push(name);
  1051. }); // Remove clan members that've left the clan from state, so their last seen time is no longer tracked when they type in chat
  1052.  
  1053. const removedMembers = Object.keys(state.clanLastActiveMembers).filter(nameInState => !latestMemberNames.includes(nameInState));
  1054. removedMembers.forEach(removedName => delete state.clanLastActiveMembers[removedName]);
  1055. (0, _state.saveState)(); // Update changed last seen times in DOM
  1056.  
  1057. const $names = Array.from($clanMemberTable.querySelectorAll('tr .name'));
  1058. const $lastSeenRows = Array.from($clanLastSeenTable.querySelectorAll('.js-clan-lastseen-row')); // If necessary, update the quantity of rows in our custom table
  1059.  
  1060. const $tableBody = $clanLastSeenTable.querySelector('tbody');
  1061.  
  1062. if ($names.length !== $lastSeenRows.length) {
  1063. const $newRow = (0, _misc.makeElement)({
  1064. element: 'tr',
  1065. class: 'striped js-clan-lastseen-row',
  1066. content: '<td></td>'
  1067. });
  1068.  
  1069. if ($names.length > $lastSeenRows.length) {
  1070. // Add last seen rows to match names length
  1071. const rowsToAddCount = $names.length - $lastSeenRows.length;
  1072.  
  1073. for (var i = 0; i < rowsToAddCount; i++) {
  1074. $tableBody.appendChild($newRow.cloneNode(true));
  1075. }
  1076. } else {
  1077. // Remove last seen rows to match names length
  1078. const rowsToRemoveCount = $lastSeenRows.length - $names.length;
  1079.  
  1080. for (var i = 0; i < rowsToRemoveCount; i++) {
  1081. $tableBody.querySelector('tr').remove();
  1082. }
  1083. }
  1084. } // Update last seen rows with appropriate last seen time
  1085.  
  1086.  
  1087. const $tableRows = Array.from($tableBody.querySelectorAll('td'));
  1088. $names.forEach(($name, index) => {
  1089. const name = $name.textContent.trim();
  1090. const isOnline = state.clanLastActiveMembers[name] === currentTimestamp;
  1091. const lastSeenStr = isOnline ? 'Now' : _lastSeenFromTimestamp(state.clanLastActiveMembers[name]);
  1092. const $tableRow = $tableRows[index];
  1093. const rowLastSeenStr = $tableRow.textContent;
  1094. const isLastSeenChanged = rowLastSeenStr !== lastSeenStr;
  1095. if (isLastSeenChanged) $tableRow.textContent = lastSeenStr; // Mirroring the 50% opacity that the normal clan member table has on offline members
  1096.  
  1097. const lineClassList = $tableRow.parentNode.classList;
  1098. const displayingRowAsOffline = lineClassList.contains('js-offline-member');
  1099.  
  1100. if (!isOnline && !displayingRowAsOffline) {
  1101. lineClassList.add('js-offline-member');
  1102. } else if (isOnline && displayingRowAsOffline) {
  1103. lineClassList.remove('js-offline-member');
  1104. }
  1105. });
  1106. }
  1107.  
  1108. function handleClanWindowChange() {
  1109. const state = (0, _state.getState)();
  1110. const tempState = (0, _state.getTempState)();
  1111. const $clanWindow = document.querySelector('.window .clanView'); // Table takes a moment to be created after clanView window is opened
  1112.  
  1113. const $clanMemberTable = $clanWindow.querySelector('table:not(.js-clan-lastseen-initd)');
  1114. if (!$clanMemberTable) return; // If not in Members tab (e.g. Applications tab), don't initialize Last seen
  1115. // Check if we're in Members tab by seeing if there are 2 columns or not
  1116. // (This allows us to support multiple languages, as opposed to checking for "Applications")
  1117.  
  1118. const isMembersTab = Array.from($clanMemberTable.querySelectorAll('thead th')).length === 2;
  1119. const $lastSeenTable = $clanWindow.querySelector('.js-clan-lastseen-table');
  1120.  
  1121. if (!isMembersTab) {
  1122. // Hide last seen table if it's visible
  1123. if ($lastSeenTable) $lastSeenTable.style.display = 'none';
  1124. return;
  1125. } else if ($lastSeenTable) {
  1126. // Unhide it when we are on Members table
  1127. $lastSeenTable.setAttribute('style', '');
  1128. } // Initialize the table column if we haven't already
  1129. // The clan member table loses its class when the tab is changed, so we check
  1130.  
  1131.  
  1132. if (!$clanMemberTable.classList.contains('js-clan-members-table-initd')) {
  1133. $clanMemberTable.classList.add('js-clan-members-table-initd', 'uimod-clan-members-table'); // Last seen table may already exist if we're switching from Applications tab back to Members tab
  1134.  
  1135. if ($lastSeenTable) return; // If last seen table hasn't been created, create it.
  1136. // We add a new table next to the preexisting table.
  1137. // We don't just add a new column because Svelte changes the columns and rows around
  1138. // a lot, pretty randomly. This leads to our right-most column occasionally bugging out
  1139. // and ending up as the left-most column.
  1140. // Using our own table lets us control everything about it without Svelte interfering.
  1141.  
  1142. $clanMemberTable.parentNode.appendChild((0, _misc.makeElement)({
  1143. element: 'table',
  1144. class: 'marg-top panel-black js-clan-lastseen-table uimod-clan-lastseen-table',
  1145. content: `
  1146. <thead>
  1147. <tr class="textprimary">
  1148. <th>Last seen</th>
  1149. </tr>
  1150. </thead>
  1151. <tbody>
  1152. <tr class="striped js-clan-lastseen-row">
  1153. <td></td>
  1154. </tr>
  1155. </tbody>
  1156. `
  1157. })); // Reset last active members state if clan has changed
  1158.  
  1159. const clanName = $clanWindow.querySelector('.textcenter h1').textContent;
  1160.  
  1161. if (clanName !== state.currentClanName) {
  1162. state.currentClanName = clanName.trim();
  1163. state.clanLastActiveMembers = {};
  1164. (0, _state.saveState)();
  1165. }
  1166. }
  1167.  
  1168. if (!tempState.clanTableObserver) {
  1169. _handleClanMemberTableChange();
  1170.  
  1171. tempState.clanTableObserver = new MutationObserver(_handleClanMemberTableChange);
  1172. tempState.clanTableObserver.observe($clanMemberTable, {
  1173. attributes: true,
  1174. childList: true,
  1175. subtree: true
  1176. });
  1177. }
  1178. }
  1179.  
  1180. },{"../../utils/misc":35,"../../utils/state":37}],10:[function(require,module,exports){
  1181. "use strict";
  1182.  
  1183. Object.defineProperty(exports, "__esModule", {
  1184. value: true
  1185. });
  1186. exports.default = void 0;
  1187.  
  1188. var _ui = require("../../utils/ui");
  1189.  
  1190. var _state = require("../../utils/state");
  1191.  
  1192. var _helpers = require("./helpers");
  1193.  
  1194. // When clan window is open, initialize the mutation observer to add Last seen and track last seen in state
  1195. function clanActivityTracker() {
  1196. const tempState = (0, _state.getTempState)();
  1197. const $clanWindow = document.querySelector('.window .clanView'); // If the window is no longer visible, update the state to denote the window has closed and kill the observer
  1198.  
  1199. if (!$clanWindow) {
  1200. if ((0, _ui.isWindowOpen)(_ui.WindowNames.clan)) {
  1201. if (tempState.clanWindowObserver) {
  1202. tempState.clanWindowObserver.disconnect();
  1203. delete tempState.clanWindowObserver;
  1204. }
  1205.  
  1206. if (tempState.clanTableObserver) {
  1207. tempState.clanTableObserver.disconnect();
  1208. delete tempState.clanTableObserver;
  1209. }
  1210.  
  1211. (0, _ui.setWindowClosed)(_ui.WindowNames.clan);
  1212. }
  1213. } else if (!tempState.clanWindowObserver) {
  1214. (0, _ui.setWindowOpen)(_ui.WindowNames.clan);
  1215. (0, _helpers.handleClanWindowChange)();
  1216. tempState.clanWindowObserver = new MutationObserver(_helpers.handleClanWindowChange);
  1217. tempState.clanWindowObserver.observe($clanWindow, {
  1218. attributes: true,
  1219. childList: true
  1220. });
  1221. }
  1222. } // Update last seen for clan members when they type in chat
  1223.  
  1224.  
  1225. function refreshLastSeenClanMember(mutations) {
  1226. const state = (0, _state.getState)();
  1227. let updatedState = false;
  1228. const $newChatLines = mutations.map(mutation => Array.from(mutation.addedNodes)).flat();
  1229. $newChatLines.forEach($chatLine => {
  1230. const $name = $chatLine.querySelector('.name');
  1231. if (!$name) return;
  1232. const name = $name.textContent.trim(); // If not clan member, don't update state
  1233.  
  1234. if (!state.clanLastActiveMembers.hasOwnProperty(name)) return;
  1235. updatedState = true;
  1236. state.clanLastActiveMembers[name] = Date.now();
  1237. });
  1238. if (updatedState) (0, _state.saveState)();
  1239. }
  1240.  
  1241. var _default = {
  1242. name: 'Clan activity tracker',
  1243. description: 'Updates clan member table with a Last seen column',
  1244. run: ({
  1245. registerOnDomChange,
  1246. registerOnChatChange
  1247. }) => {
  1248. clanActivityTracker(); // Run it initially once in case clan is already open on mod load
  1249.  
  1250. registerOnDomChange(clanActivityTracker); // Run it on dom change for whenever the clan window is opened/closed
  1251.  
  1252. registerOnChatChange(refreshLastSeenClanMember); // Run it on chat change so whenever a clan member chats, their last seen is updated
  1253. }
  1254. };
  1255. exports.default = _default;
  1256.  
  1257. },{"../../utils/state":37,"../../utils/ui":38,"./helpers":9}],11:[function(require,module,exports){
  1258. "use strict";
  1259.  
  1260. Object.defineProperty(exports, "__esModule", {
  1261. value: true
  1262. });
  1263. exports.default = void 0;
  1264.  
  1265. var _misc = require("../../utils/misc");
  1266.  
  1267. var _ui = require("../../utils/ui");
  1268.  
  1269. function customSettings() {
  1270. const $settings = document.querySelector('.divide:not(.js-settings-initd)');
  1271.  
  1272. if (!$settings) {
  1273. return;
  1274. }
  1275.  
  1276. $settings.classList.add('js-settings-initd');
  1277. const $settingsChoiceList = $settings.querySelector('.choice').parentNode;
  1278. $settingsChoiceList.appendChild((0, _misc.makeElement)({
  1279. element: 'div',
  1280. class: 'choice js-blocked-players',
  1281. content: 'Blocked players'
  1282. }));
  1283. $settingsChoiceList.appendChild((0, _misc.makeElement)({
  1284. element: 'div',
  1285. class: 'choice js-reset-ui-pos',
  1286. content: 'Reset UI Positions'
  1287. })); // Upon click, we display our custom settings window UI
  1288.  
  1289. document.querySelector('.js-blocked-players').addEventListener('click', _ui.createBlockList); // Reset positions immediately upon click
  1290.  
  1291. document.querySelector('.js-reset-ui-pos').addEventListener('click', _ui.resetUiPositions); // If it was open when the game last closed keep it open
  1292.  
  1293. if ((0, _ui.isWindowOpen)(_ui.WindowNames.blockList)) {
  1294. (0, _ui.createBlockList)();
  1295. }
  1296. }
  1297.  
  1298. var _default = {
  1299. name: 'Custom settings',
  1300. description: 'Allows you to view and remove blocked players from the Settings window. Also adds Reset UI Position to settings',
  1301. run: ({
  1302. registerOnDomChange
  1303. }) => {
  1304. customSettings(); // If the settings window becomes visible/invisible, we want to update it
  1305.  
  1306. registerOnDomChange(customSettings);
  1307. }
  1308. };
  1309. exports.default = _default;
  1310.  
  1311. },{"../../utils/misc":35,"../../utils/ui":38}],12:[function(require,module,exports){
  1312. "use strict";
  1313.  
  1314. Object.defineProperty(exports, "__esModule", {
  1315. value: true
  1316. });
  1317. exports.deposit = deposit;
  1318.  
  1319. var _game = require("../../utils/game");
  1320.  
  1321. var _ui = require("../../utils/ui");
  1322.  
  1323. function deposit() {
  1324. const $stash = (0, _game.getWindow)(_ui.WindowNames.stash); // Select normal deposit button
  1325.  
  1326. $stash.querySelector('.slot .grey.gold:not(.js-deposit-all)').dispatchEvent(new Event('click'));
  1327. const $currencyInput = $stash.querySelector('input.formatted'); // Input some huge value they'll have less than
  1328.  
  1329. $currencyInput.value = 999999999999999;
  1330. $currencyInput.dispatchEvent(new Event('input'));
  1331. setTimeout(function () {
  1332. const $depositButton = $stash.querySelector('.btn.blue');
  1333.  
  1334. if (!$depositButton.classList.contains('disabled')) {
  1335. $depositButton.dispatchEvent(new Event('click'));
  1336. } // Clear input
  1337.  
  1338.  
  1339. $currencyInput.value = '';
  1340. $currencyInput.dispatchEvent(new Event('input'));
  1341. }, 0);
  1342. }
  1343.  
  1344. },{"../../utils/game":34,"../../utils/ui":38}],13:[function(require,module,exports){
  1345. "use strict";
  1346.  
  1347. Object.defineProperty(exports, "__esModule", {
  1348. value: true
  1349. });
  1350. exports.default = void 0;
  1351.  
  1352. var _misc = require("../../utils/misc");
  1353.  
  1354. var _ui = require("../../utils/ui");
  1355.  
  1356. var _game = require("../../utils/game");
  1357.  
  1358. var _helper = require("./helper");
  1359.  
  1360. function addDepositAllButton() {
  1361. const $stash = (0, _game.getWindow)(_ui.WindowNames.stash); // If stash is closed or deposit all button is already added, we dont need to do anything
  1362.  
  1363. if (!$stash || $stash.querySelector('.js-deposit-all')) {
  1364. return;
  1365. } // Create deposit all button and add it to stash
  1366.  
  1367.  
  1368. const $depositTargetBtn = $stash.querySelector('.slot .grey.gold');
  1369. const $depositAllBtn = $depositTargetBtn.cloneNode(true);
  1370. const $depositAllText = (0, _misc.makeElement)({
  1371. element: 'span',
  1372. content: ' ALL'
  1373. });
  1374. $depositAllBtn.append($depositAllText);
  1375. $depositAllBtn.classList.add('js-deposit-all');
  1376. $depositAllBtn.classList.remove('active');
  1377. $depositTargetBtn.parentElement.insertBefore($depositAllBtn, $depositTargetBtn);
  1378. $stash.querySelector('.js-deposit-all').addEventListener('click', _helper.deposit);
  1379. }
  1380.  
  1381. var _default = {
  1382. name: 'Desposit All Button',
  1383. description: 'Adds a button to your stash to quickly deposit all of your money',
  1384. run: ({
  1385. registerOnDomChange
  1386. }) => {
  1387. addDepositAllButton();
  1388. registerOnDomChange(addDepositAllButton);
  1389. }
  1390. };
  1391. exports.default = _default;
  1392.  
  1393. },{"../../utils/game":34,"../../utils/misc":35,"../../utils/ui":38,"./helper":12}],14:[function(require,module,exports){
  1394. "use strict";
  1395.  
  1396. Object.defineProperty(exports, "__esModule", {
  1397. value: true
  1398. });
  1399. exports.dragElement = dragElement;
  1400.  
  1401. // Influenced by: https://gist.github.com/remarkablemark/5002d27442600510d454a5aeba370579 & https://stackoverflow.com/a/45831670
  1402. // $draggedElement is the item that will be dragged.
  1403. // $dragTrigger is optional, if passed, this element that must be held down to drag $draggedElement
  1404. // If $dragTrigger is not passed, clicking anywhere on $draggedElement will drag it
  1405. // dragAfterTimeMs is an optional argument. If passed, user has to hold mouse down for that long before being able to drag
  1406. function dragElement($draggedElement, $dragTrigger, dragAfterTimeMs) {
  1407. let offset = [0, 0];
  1408. let mouseDownPos = [0, 0];
  1409. let elementPos = [0, 0];
  1410. let isDown = false;
  1411. let downTimeMs = 0; // Time when user last started holding mouse left click
  1412.  
  1413. const $trigger = $dragTrigger || $draggedElement;
  1414. $trigger.addEventListener('mousedown', e => {
  1415. isDown = true;
  1416. downTimeMs = Date.now(); // Offset is used when there is a separate $dragTrigger
  1417.  
  1418. offset = [$draggedElement.offsetLeft - e.clientX, $draggedElement.offsetTop - e.clientY]; // mouseDownPos and elementPos are used when $draggedElement is also the trigger
  1419.  
  1420. mouseDownPos = [e.clientX, e.clientY];
  1421. elementPos = [parseInt($draggedElement.style.left) || 0, parseInt($draggedElement.style.top) || 0];
  1422. }, true);
  1423. document.addEventListener('mouseup', () => {
  1424. downTimeMs = 0;
  1425. isDown = false;
  1426. }, true);
  1427. document.addEventListener('mousemove', e => {
  1428. e.preventDefault();
  1429.  
  1430. if (isDown) {
  1431. // If dragAfterTimeMs is set, then user must hold down mouse for specified time before being able to drag
  1432. if (dragAfterTimeMs && Date.now() - downTimeMs < dragAfterTimeMs) return;
  1433. const deltaX = $dragTrigger ? e.clientX + offset[0] : elementPos[0] + e.clientX - mouseDownPos[0];
  1434. const deltaY = $dragTrigger ? e.clientY + offset[1] : elementPos[1] + e.clientY - mouseDownPos[1];
  1435. $draggedElement.style.left = `${deltaX}px`;
  1436. $draggedElement.style.top = `${deltaY}px`;
  1437. }
  1438. }, true);
  1439. }
  1440.  
  1441. },{}],15:[function(require,module,exports){
  1442. "use strict";
  1443.  
  1444. Object.defineProperty(exports, "__esModule", {
  1445. value: true
  1446. });
  1447. exports.default = void 0;
  1448.  
  1449. var helpers = _interopRequireWildcard(require("./helpers"));
  1450.  
  1451. var _state = require("../../utils/state");
  1452.  
  1453. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  1454.  
  1455. 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; }
  1456.  
  1457. // Drag all windows by their header
  1458. function draggableUIWindows() {
  1459. Array.from(document.querySelectorAll('.window:not(.js-can-move)')).forEach($window => {
  1460. $window.classList.add('js-can-move');
  1461. helpers.dragElement($window, $window.querySelector('.titleframe'));
  1462. });
  1463. Array.from(document.querySelectorAll(`
  1464. .partyframes:not(.js-can-move),
  1465. #ufplayer:not(.js-can-move),
  1466. #uftarget:not(.js-can-move),
  1467. #skillbar:not(.js-can-move)
  1468. `)).forEach($frame => {
  1469. $frame.classList.add('js-can-move');
  1470. helpers.dragElement($frame, null, 500);
  1471. });
  1472. } // Save dragged UI windows position to state
  1473.  
  1474.  
  1475. function saveDraggedUIWindows() {
  1476. const state = (0, _state.getState)();
  1477. Array.from(document.querySelectorAll('.window:not(.js-ui-is-saving)')).forEach($window => {
  1478. $window.classList.add('js-ui-is-saving');
  1479. const $draggableTarget = $window.querySelector('.titleframe');
  1480. const windowName = $draggableTarget.querySelector('[name="title"]').textContent;
  1481. $draggableTarget.addEventListener('mouseup', () => {
  1482. state.windowsPos[windowName] = $window.getAttribute('style');
  1483. (0, _state.saveState)();
  1484. });
  1485. });
  1486.  
  1487. const saveFramePos = ($element, name) => {
  1488. if (!$element) return;
  1489. $element.classList.add('js-ui-is-saving');
  1490. $element.addEventListener('mouseup', () => {
  1491. state.windowsPos[name] = $element.getAttribute('style');
  1492. });
  1493. };
  1494.  
  1495. saveFramePos(document.querySelector('.partyframes:not(.js-ui-is-saving)'), 'partyFrame');
  1496. saveFramePos(document.querySelector('#ufplayer:not(.js-ui-is-saving)'), 'playerFrame');
  1497. saveFramePos(document.querySelector('#uftarget:not(.js-ui-is-saving)'), 'targetFrame');
  1498. } // Loads draggable UI windows position from state
  1499.  
  1500.  
  1501. function loadDraggedUIWindowsPositions() {
  1502. const state = (0, _state.getState)();
  1503. Array.from(document.querySelectorAll('.window:not(.js-has-loaded-pos)')).forEach($window => {
  1504. $window.classList.add('js-has-loaded-pos');
  1505. const windowName = $window.querySelector('[name="title"]').textContent;
  1506. const pos = state.windowsPos[windowName];
  1507.  
  1508. if (pos) {
  1509. $window.setAttribute('style', pos);
  1510. }
  1511. });
  1512.  
  1513. const loadFramePos = ($element, name) => {
  1514. if (!$element) return;
  1515. $element.classList.add('js-has-loaded-pos');
  1516. const pos = state.windowsPos[name];
  1517.  
  1518. if (pos) {
  1519. $element.setAttribute('style', pos);
  1520. }
  1521. };
  1522.  
  1523. loadFramePos(document.querySelector('.partyframes:not(.js-has-loaded-pos)'), 'partyFrame');
  1524. loadFramePos(document.querySelector('#ufplayer:not(.js-has-loaded-pos)'), 'playerFrame');
  1525. loadFramePos(document.querySelector('#uftarget:not(.js-has-loaded-pos)'), 'targetFrame');
  1526. }
  1527.  
  1528. var _default = {
  1529. name: 'Draggable Windows',
  1530. description: 'Allows you to drag windows in the UI',
  1531. run: ({
  1532. registerOnDomChange
  1533. }) => {
  1534. draggableUIWindows();
  1535. saveDraggedUIWindows();
  1536. loadDraggedUIWindowsPositions(); // As windows open, we want to make them draggable
  1537.  
  1538. registerOnDomChange(saveDraggedUIWindows);
  1539. registerOnDomChange(draggableUIWindows);
  1540. registerOnDomChange(loadDraggedUIWindowsPositions);
  1541. }
  1542. };
  1543. exports.default = _default;
  1544.  
  1545. },{"../../utils/state":37,"./helpers":14}],16:[function(require,module,exports){
  1546. "use strict";
  1547.  
  1548. Object.defineProperty(exports, "__esModule", {
  1549. value: true
  1550. });
  1551. exports.default = void 0;
  1552.  
  1553. var _misc = require("../../utils/misc");
  1554.  
  1555. var _ui = require("../../utils/ui");
  1556.  
  1557. // The F icon and the UI that appears when you click it
  1558. function customFriendsList() {
  1559. var friendsIconElement = (0, _misc.makeElement)({
  1560. element: 'div',
  1561. class: 'btn border black js-friends-list-icon',
  1562. content: 'F'
  1563. }); // Add the icon to the right of Elixir icon
  1564.  
  1565. const $elixirIcon = document.querySelector('#sysgem');
  1566. $elixirIcon.parentNode.insertBefore(friendsIconElement, $elixirIcon.nextSibling); // Create the friends list UI
  1567.  
  1568. document.querySelector('.js-friends-list-icon').addEventListener('click', _ui.toggleFriendsList); // If it was open when the game last closed keep it open
  1569.  
  1570. if ((0, _ui.isWindowOpen)(_ui.WindowNames.friendsList)) {
  1571. (0, _ui.createFriendsList)();
  1572. }
  1573. }
  1574.  
  1575. var _default = {
  1576. name: 'Friends list',
  1577. description: 'Allows access to your friends list from the top right F icon',
  1578. run: customFriendsList
  1579. };
  1580. exports.default = _default;
  1581.  
  1582. },{"../../utils/misc":35,"../../utils/ui":38}],17:[function(require,module,exports){
  1583. "use strict";
  1584.  
  1585. Object.defineProperty(exports, "__esModule", {
  1586. value: true
  1587. });
  1588. exports.default = void 0;
  1589.  
  1590. var _modStart = _interopRequireDefault(require("./_modStart"));
  1591.  
  1592. var _customSettings = _interopRequireDefault(require("./customSettings"));
  1593.  
  1594. var _chatContextMenu = _interopRequireDefault(require("./chatContextMenu"));
  1595.  
  1596. var _chatFilters = _interopRequireDefault(require("./chatFilters"));
  1597.  
  1598. var _chatTabs = _interopRequireDefault(require("./chatTabs"));
  1599.  
  1600. var _draggableUI = _interopRequireDefault(require("./draggableUI"));
  1601.  
  1602. var _friendsList = _interopRequireDefault(require("./friendsList"));
  1603.  
  1604. var _mapControls = _interopRequireDefault(require("./mapControls"));
  1605.  
  1606. var _resizableChat = _interopRequireDefault(require("./resizableChat"));
  1607.  
  1608. var _resizableMap = _interopRequireDefault(require("./resizableMap"));
  1609.  
  1610. var _selectedWindowIsTop = _interopRequireDefault(require("./selectedWindowIsTop"));
  1611.  
  1612. var _xpMeter = _interopRequireDefault(require("./xpMeter"));
  1613.  
  1614. var _merchantFilter = _interopRequireDefault(require("./merchantFilter"));
  1615.  
  1616. var _itemStatsCopy = _interopRequireDefault(require("./itemStatsCopy"));
  1617.  
  1618. var _keyPressTracker = _interopRequireDefault(require("./_keyPressTracker"));
  1619.  
  1620. var _clanActivityTracker = _interopRequireDefault(require("./clanActivityTracker"));
  1621.  
  1622. var _skillCooldownNumbers = _interopRequireDefault(require("./skillCooldownNumbers"));
  1623.  
  1624. var _depositAll = _interopRequireDefault(require("./depositAll"));
  1625.  
  1626. var _lockedItemSlots = _interopRequireDefault(require("./lockedItemSlots"));
  1627.  
  1628. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1629.  
  1630. // The array here dictates the order of which mods are executed, from top to bottom
  1631. var _default = [_modStart.default, _keyPressTracker.default, _resizableMap.default, _mapControls.default, _friendsList.default, _customSettings.default, _resizableChat.default, _chatContextMenu.default, _chatFilters.default, _chatTabs.default, _draggableUI.default, _selectedWindowIsTop.default, _xpMeter.default, _merchantFilter.default, _itemStatsCopy.default, _clanActivityTracker.default, _skillCooldownNumbers.default, _depositAll.default, _lockedItemSlots.default];
  1632. exports.default = _default;
  1633.  
  1634. },{"./_keyPressTracker":2,"./_modStart":3,"./chatContextMenu":5,"./chatFilters":6,"./chatTabs":8,"./clanActivityTracker":10,"./customSettings":11,"./depositAll":13,"./draggableUI":15,"./friendsList":16,"./itemStatsCopy":18,"./lockedItemSlots":20,"./mapControls":22,"./merchantFilter":24,"./resizableChat":25,"./resizableMap":27,"./selectedWindowIsTop":28,"./skillCooldownNumbers":30,"./xpMeter":32}],18:[function(require,module,exports){
  1635. "use strict";
  1636.  
  1637. Object.defineProperty(exports, "__esModule", {
  1638. value: true
  1639. });
  1640. exports.default = void 0;
  1641.  
  1642. var chat = _interopRequireWildcard(require("../../utils/chat"));
  1643.  
  1644. var _game = require("../../utils/game");
  1645.  
  1646. var _state = require("../../utils/state");
  1647.  
  1648. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  1649.  
  1650. 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; }
  1651.  
  1652. async function itemStatsCopy(clickEvent) {
  1653. const tempState = (0, _state.getTempState)(); // This mod only triggers if you alt+right click
  1654.  
  1655. if (!tempState.keyModifiers.alt) {
  1656. return;
  1657. }
  1658.  
  1659. 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
  1660.  
  1661. const $bagSlot = $elementMouseIsOver.parentNode; // No item in slot
  1662.  
  1663. if (!$bagSlot.querySelector('img')) {
  1664. return;
  1665. } // Once we confirm we want to copy to clipboard, hide context menu
  1666.  
  1667.  
  1668. const $itemContextMenuChoice = document.body.querySelector('.container > .panel > .choice');
  1669.  
  1670. if (!$itemContextMenuChoice) {
  1671. // If context menu isn't open, something is not right - stop what we're doing and exit
  1672. // Seen this happen very rarely when testing
  1673. return;
  1674. }
  1675.  
  1676. const $itemContextMenu = $itemContextMenuChoice.parentNode;
  1677.  
  1678. if ($itemContextMenu) {
  1679. $itemContextMenu.style.display = 'none';
  1680. } // Get the texts we want from the tooltip
  1681.  
  1682.  
  1683. const getDetailedTooltips = true;
  1684. const $tooltip = await (0, _game.getTooltipContent)($bagSlot, getDetailedTooltips);
  1685.  
  1686. if (!$tooltip) {
  1687. // This _shouldn't_ happen, but very occasionally there is a (likely timing-related) problem getting the tooltip
  1688. return;
  1689. } // We get the detailed tooltip, which may have a second comparison tooltip. Remove the comparison tooltip if we have it.
  1690.  
  1691.  
  1692. const $comparisonTooltip = $tooltip.querySelector('.slotdescription');
  1693. if ($comparisonTooltip) $comparisonTooltip.parentNode.removeChild($comparisonTooltip); // Collect item name/stats into strings
  1694.  
  1695. const itemName = $tooltip.querySelector('.slottitle').textContent;
  1696. const $itemQuality = $tooltip.querySelector('.type span');
  1697. const itemQuality = $itemQuality.textContent; // It's not a piece of equipment, just copy item name and exit
  1698.  
  1699. if (!itemQuality.includes('%')) {
  1700. let trimmedItemName = itemName; // If item name starts with T#, e.g. T1, T5, etc, then this was added onto the detailed tooltip
  1701. // It's usually unnecessary information, so we remove it
  1702. // (e.g. shows as "T94 Centrifugal Laceration Lv. 4" instead of "Centrifugal Laceration Lv. 4")
  1703.  
  1704. if (itemName.substr(0, 2).match(/T[0-9]/)) {
  1705. trimmedItemName = itemName.substr(itemName.indexOf(' ') + 1);
  1706. }
  1707.  
  1708. navigator.clipboard.writeText(trimmedItemName);
  1709. chat.addChatMessage(`Copied ${trimmedItemName} to clipboard.`);
  1710. return;
  1711. } // We only want the lvl number, so pop off the level number from the "Requires Lv. 17" line
  1712.  
  1713.  
  1714. const itemLvl = $tooltip.querySelector('.requirements').textContent.split(' ').pop(); // Grab the stats we care about, i.e. not part of the requirements or item type
  1715.  
  1716. const $stats = Array.from($tooltip.querySelectorAll(`
  1717. .container > .textpurp,
  1718. .container > .textblue,
  1719. .container > .textgreen:not(.slottitle):not(.requirements),
  1720. .container > .textwhite:not(.type)
  1721. `));
  1722. const statsText = $stats.map($stat => {
  1723. // Return quality percentage only if it exists, otherwise return normal stat
  1724. const $quality = $stat.querySelector('span');
  1725.  
  1726. if ($quality) {
  1727. const quality = $quality.textContent;
  1728. const statLineChunks = $stat.textContent.replace(/\+\s/g, '+').split(' ');
  1729. statLineChunks.pop(); // Remove quality at end
  1730.  
  1731. statLineChunks.shift(); // Remove specific +# at the beginning
  1732.  
  1733. const statName = statLineChunks.join(' ');
  1734. return `${statName} ${quality}`;
  1735. } else {
  1736. return $stat.textContent.trim();
  1737. }
  1738. }).join(', ');
  1739. navigator.clipboard.writeText(`${itemName} ${itemQuality} Lv.${itemLvl}: ${statsText}`);
  1740. chat.addChatMessage(`Copied ${itemName}'s stats to clipboard.`);
  1741. }
  1742.  
  1743. var _default = {
  1744. name: 'Items stats copy',
  1745. description: 'When ctrl+left clicking a piece of equipment in your inventory, its stats will be copied to your clipboard',
  1746. run: ({
  1747. registerOnRightClick
  1748. }) => {
  1749. registerOnRightClick(itemStatsCopy);
  1750. }
  1751. };
  1752. exports.default = _default;
  1753.  
  1754. },{"../../utils/chat":33,"../../utils/game":34,"../../utils/state":37}],19:[function(require,module,exports){
  1755. "use strict";
  1756.  
  1757. Object.defineProperty(exports, "__esModule", {
  1758. value: true
  1759. });
  1760. exports.lockSlot = lockSlot;
  1761. exports.initLockedSlots = initLockedSlots;
  1762.  
  1763. var _state = require("../../utils/state");
  1764.  
  1765. var _misc = require("../../utils/misc");
  1766.  
  1767. var _ui = require("../../utils/ui");
  1768.  
  1769. var _game = require("../../utils/game");
  1770.  
  1771. function _wireLockSlot($lockedSlot) {
  1772. const state = (0, _state.getState)();
  1773. const tempState = (0, _state.getTempState)();
  1774. const slotNumber = $lockedSlot.getAttribute('data-locked-slot-num');
  1775. const $bagSlot = document.querySelector(`#bag${slotNumber}`); // Left clicking works normally, proxy it through
  1776.  
  1777. $lockedSlot.addEventListener('click', () => {
  1778. $bagSlot.dispatchEvent(new Event('pointerup'));
  1779. }); // Hovering to see the tooltip works normally, proxy it through
  1780.  
  1781. $lockedSlot.addEventListener('pointerenter', () => {
  1782. $bagSlot.dispatchEvent(new Event('pointerenter'));
  1783. });
  1784. $lockedSlot.addEventListener('pointerleave', () => {
  1785. $bagSlot.dispatchEvent(new Event('pointerleave'));
  1786. }); // Right clicking removes Drop item from menu, otherwise works normally, proxy it through
  1787.  
  1788. $lockedSlot.addEventListener('contextmenu', event => {
  1789. // Block shift+right click
  1790. if (tempState.keyModifiers.shift) return; // Don't do anything if no item in this slot
  1791.  
  1792. if (!$bagSlot.querySelector('img')) return; // Emulate right click on the item to display its context menu
  1793.  
  1794. $bagSlot.dispatchEvent(new PointerEvent('pointerup', event));
  1795. setTimeout(() => {
  1796. const $contextMenuChoices = Array.from(document.querySelectorAll('.container > .panel.context .choice')); // Remove "Drop item" from context menu
  1797.  
  1798. $contextMenuChoices.forEach($choice => {
  1799. if ($choice.textContent.toLowerCase() === 'drop item') {
  1800. $choice.style.display = 'none';
  1801. }
  1802. }); // Add "Unlock slot" menu item
  1803.  
  1804. $contextMenuChoices[0].parentNode.appendChild((0, _misc.makeElement)({
  1805. element: 'div',
  1806. class: 'choice js-unlock-item',
  1807. content: 'Unlock slot'
  1808. })); // Wire up "Unlock slot" menu item
  1809.  
  1810. const $unlockItemChoice = document.querySelector('.js-unlock-item');
  1811. $unlockItemChoice.addEventListener('click', () => {
  1812. state.lockedItemSlots.splice(state.lockedItemSlots.indexOf(slotNumber), 1);
  1813. (0, _state.saveState)();
  1814. $lockedSlot.parentNode.removeChild($lockedSlot); // Hide context menu after clicking unlock (removing it breaks client that tries to remove it later)
  1815.  
  1816. const $contextMenu = $unlockItemChoice.parentNode;
  1817. $contextMenu.style.display = 'none';
  1818. });
  1819. }, 0);
  1820. });
  1821. }
  1822.  
  1823. function lockSlot(slotNumber) {
  1824. const $slot = document.querySelector(`#bag${slotNumber}`);
  1825. if (!$slot) return; // If slot has already been locked, don't lock it again
  1826.  
  1827. if (document.querySelector(`.js-locked-slot[data-locked-slot-num="${slotNumber}"]`)) return;
  1828. const $lockedSlot = (0, _misc.makeElement)({
  1829. element: 'div',
  1830. class: 'js-locked-slot uimod-locked-slot'
  1831. });
  1832. $lockedSlot.setAttribute('data-locked-slot-num', slotNumber);
  1833. $lockedSlot.setAttribute('style', `left: ${$slot.offsetLeft}px; top: ${$slot.offsetTop}px;`);
  1834. $slot.parentNode.insertBefore($lockedSlot, $slot);
  1835.  
  1836. _wireLockSlot($lockedSlot);
  1837. }
  1838.  
  1839. function initLockedSlots() {
  1840. const state = (0, _state.getState)();
  1841. const $inventory = (0, _game.getWindow)(_ui.WindowNames.inventory);
  1842. if (!$inventory || $inventory.classList.contains('js-locked-slots-initd')) return;
  1843. $inventory.classList.add('js-locked-slots-initd'); // Initialize locked slots UI
  1844.  
  1845. state.lockedItemSlots.forEach(lockSlot);
  1846. }
  1847.  
  1848. },{"../../utils/game":34,"../../utils/misc":35,"../../utils/state":37,"../../utils/ui":38}],20:[function(require,module,exports){
  1849. "use strict";
  1850.  
  1851. Object.defineProperty(exports, "__esModule", {
  1852. value: true
  1853. });
  1854. exports.default = void 0;
  1855.  
  1856. var _ui = require("../../utils/ui");
  1857.  
  1858. var _game = require("../../utils/game");
  1859.  
  1860. var _state = require("../../utils/state");
  1861.  
  1862. var _misc = require("../../utils/misc");
  1863.  
  1864. var _helpers = require("./helpers");
  1865.  
  1866. function addLockItemContextMenu() {
  1867. const state = (0, _state.getState)();
  1868. const $inventory = (0, _game.getWindow)(_ui.WindowNames.inventory);
  1869. const $contextMenu = document.querySelector('.container > .panel.context:not(.js-lock-menu-initd)');
  1870. if (!$inventory || !$contextMenu) return;
  1871. const $elementUnderContextMenu = document.elementFromPoint($contextMenu.offsetLeft, $contextMenu.offsetTop - 10 // Subtract 10px to get element right above context menu, rather than context menu itself
  1872. ); // If context menu top left is not inside inventory, then this is not the inventory context menu
  1873. // For example, Queue or Party was clicked while inventory was opened
  1874.  
  1875. if (!$inventory.contains($elementUnderContextMenu)) return; // Add Lock slot, only if unlock slot doesn't exist
  1876. // Use `setTimeout` to wait for `unlock slot` to be added
  1877.  
  1878. setTimeout(() => {
  1879. // If Lock slot already added, dont add it
  1880. if (document.querySelector('.js-lock-item')) return; // If Unlock slot exists, don't add Lock slot
  1881.  
  1882. const isLocked = Array.from($contextMenu.querySelectorAll('.choice')).some($choice => $choice.textContent.toLowerCase() === 'unlock slot');
  1883. if (isLocked) return;
  1884. $contextMenu.appendChild((0, _misc.makeElement)({
  1885. element: 'div',
  1886. class: 'choice js-lock-item',
  1887. content: 'Lock slot'
  1888. }));
  1889. document.querySelector('.js-lock-item').addEventListener('click', () => {
  1890. // Get bag slot element displayed above right click menu
  1891. // Overlay of the bag slot is selected by `elementFromPoint
  1892. const $bagSlotOverlay = document.elementFromPoint($contextMenu.offsetLeft, $contextMenu.offsetTop - 10); // Parent of overlay is the bag slot. Get its id (e.g. "bag4"), then get the slot number from the id
  1893.  
  1894. const bagSlotNum = parseInt($bagSlotOverlay.parentNode.id.substr(3));
  1895. state.lockedItemSlots.push(bagSlotNum);
  1896. (0, _state.saveState)(); // Hide context menu
  1897.  
  1898. $contextMenu.style.display = 'none'; // Add lock slot in UI
  1899.  
  1900. (0, _helpers.lockSlot)(bagSlotNum);
  1901. });
  1902. }, 0);
  1903. } // Pass `true` as argument to reinitialize even if initd
  1904.  
  1905.  
  1906. function renderLockedItemSlots() {
  1907. const $inventory = (0, _game.getWindow)(_ui.WindowNames.inventory, true);
  1908. const $inventoryContainer = $inventory.parentNode; // We listen specifically on the inventory's container to check for `style` changes
  1909. // so we know if the inventory has had its visibility toggled
  1910.  
  1911. const inventoryObserver = new MutationObserver(_helpers.initLockedSlots);
  1912. inventoryObserver.observe($inventoryContainer, {
  1913. attributes: true,
  1914. childList: false
  1915. });
  1916. (0, _helpers.initLockedSlots)();
  1917. } // Removes non-numbers and duplicates from state.lockedItemSlots, and ensures it is an array
  1918. // This is primarily necessary because the original release had a few bugs that allowed a slot
  1919. // to be in the state array multiple times, or allowed `null` to be in the array. This isn't expected and caused bugs.
  1920.  
  1921.  
  1922. function cleanLockedItemState() {
  1923. const state = (0, _state.getState)(); // If something really went wrong and lockedItemSlots isn't an array, set it to an empty array
  1924.  
  1925. if (!Array.isArray(state.lockedItemSlots)) {
  1926. state.lockedItemSlots = [];
  1927. (0, _state.saveState)();
  1928. return;
  1929. } // Remove duplicates and non-numbers
  1930.  
  1931.  
  1932. const cleanedLockItems = Array.from(new Set(state.lockedItemSlots)).filter(item => typeof item === 'number');
  1933. const itemsAreSame = cleanedLockItems.sort().join() === state.lockedItemSlots.sort().join();
  1934.  
  1935. if (!itemsAreSame) {
  1936. state.lockedItemSlots = cleanedLockItems;
  1937. (0, _state.saveState)();
  1938. }
  1939. }
  1940.  
  1941. var _default = {
  1942. name: 'Locked item slots',
  1943. description: 'Allows you to lock inventory slots so you can not drop those items or shift+right click them',
  1944. run: ({
  1945. registerOnDomChange
  1946. }) => {
  1947. cleanLockedItemState(); // Initialize locked item overlays
  1948.  
  1949. renderLockedItemSlots(); // Add Lock item choice to inventory context menu
  1950.  
  1951. addLockItemContextMenu();
  1952. registerOnDomChange(addLockItemContextMenu);
  1953. }
  1954. };
  1955. exports.default = _default;
  1956.  
  1957. },{"../../utils/game":34,"../../utils/misc":35,"../../utils/state":37,"../../utils/ui":38,"./helpers":19}],21:[function(require,module,exports){
  1958. "use strict";
  1959.  
  1960. Object.defineProperty(exports, "__esModule", {
  1961. value: true
  1962. });
  1963. exports.updateMapOpacity = updateMapOpacity;
  1964.  
  1965. var _state = require("../../utils/state");
  1966.  
  1967. // On load, update map opacity to match state
  1968. // We modify the opacity of the canvas and the background color alpha of the parent container
  1969. // We do this to allow our opacity buttons to be visible on hover with 100% opacity
  1970. // (A surprisingly difficult enough task to require this implementation)
  1971. function updateMapOpacity() {
  1972. const state = (0, _state.getState)();
  1973. const $map = document.querySelector('.container canvas');
  1974. const $mapContainer = document.querySelector('.js-map');
  1975. $map.style.opacity = String(state.mapOpacity / 100);
  1976. 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
  1977.  
  1978. let opacity = state.mapOpacity / 100; // This is a slightly lazy browser workaround to fix a bug.
  1979. // If the opacity is `1`, and it sets `rgba` to `1`, then the browser changes the
  1980. // rgba to rgb, dropping the alpha. We could account for that and add the `alpha` back in
  1981. // later, but setting the max opacity to very close to 1 makes sure the issue never crops up.
  1982. // Fun fact: 0.99 retains the alpha, but setting this to 0.999 still causes the browser to drop the alpha. Rude.
  1983.  
  1984. if (opacity === 1) {
  1985. opacity = 0.99;
  1986. }
  1987.  
  1988. const newBgColor = mapContainerBgColor.replace(/[\d\.]+\)$/g, `${opacity})`);
  1989. $mapContainer.style['background-color'] = newBgColor; // Update the button opacity
  1990.  
  1991. const $addBtn = document.querySelector('.js-map-opacity-add');
  1992. const $minusBtn = document.querySelector('.js-map-opacity-minus'); // Hide plus button if the opacity is max
  1993.  
  1994. if (state.mapOpacity === 100) {
  1995. $addBtn.style.visibility = 'hidden';
  1996. } else {
  1997. $addBtn.style.visibility = 'visible';
  1998. } // Hide minus button if the opacity is lowest
  1999.  
  2000.  
  2001. if (state.mapOpacity === 0) {
  2002. $minusBtn.style.visibility = 'hidden';
  2003. } else {
  2004. $minusBtn.style.visibility = 'visible';
  2005. }
  2006. }
  2007.  
  2008. },{"../../utils/state":37}],22:[function(require,module,exports){
  2009. "use strict";
  2010.  
  2011. Object.defineProperty(exports, "__esModule", {
  2012. value: true
  2013. });
  2014. exports.default = void 0;
  2015.  
  2016. var _state = require("../../utils/state");
  2017.  
  2018. var helpers = _interopRequireWildcard(require("./helpers"));
  2019.  
  2020. var _misc = require("../../utils/misc");
  2021.  
  2022. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  2023.  
  2024. 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; }
  2025.  
  2026. function mapControls() {
  2027. const state = (0, _state.getState)();
  2028. const $map = document.querySelector('.container canvas');
  2029.  
  2030. if (!$map.parentNode.classList.contains('js-map')) {
  2031. $map.parentNode.classList.add('js-map');
  2032. }
  2033.  
  2034. const $mapContainer = document.querySelector('.js-map'); // We only use the `js-map-move` button in the `draggableUI` mod
  2035.  
  2036. const $mapButtons = (0, _misc.makeElement)({
  2037. element: 'div',
  2038. class: 'js-map-btns',
  2039. content: `
  2040. <button class="js-map-opacity-add">+</button>
  2041. <button class="js-map-opacity-minus">-</button>
  2042. <button class="js-map-reset">r</button>
  2043. `
  2044. }); // Add it right before the map container div
  2045.  
  2046. $map.parentNode.insertBefore($mapButtons, $map);
  2047. helpers.updateMapOpacity();
  2048. const $addBtn = document.querySelector('.js-map-opacity-add');
  2049. const $minusBtn = document.querySelector('.js-map-opacity-minus');
  2050. const $resetBtn = document.querySelector('.js-map-reset'); // Hide the buttons if map opacity is maxed/minimum
  2051.  
  2052. if (state.mapOpacity === 100) {
  2053. $addBtn.style.visibility = 'hidden';
  2054. }
  2055.  
  2056. if (state.mapOpacity === 0) {
  2057. $minusBtn.style.visibility = 'hidden';
  2058. } // Wire it up
  2059.  
  2060.  
  2061. $addBtn.addEventListener('click', () => {
  2062. // Update opacity
  2063. state.mapOpacity += 10;
  2064. (0, _state.saveState)();
  2065. helpers.updateMapOpacity();
  2066. });
  2067. $minusBtn.addEventListener('click', () => {
  2068. // Update opacity
  2069. state.mapOpacity -= 10;
  2070. (0, _state.saveState)();
  2071. helpers.updateMapOpacity();
  2072. });
  2073. $resetBtn.addEventListener('click', () => {
  2074. state.mapOpacity = 70;
  2075. state.mapWidth = '174px';
  2076. state.mapHeight = '174px';
  2077. (0, _state.saveState)();
  2078. helpers.updateMapOpacity();
  2079. $mapContainer.style.width = state.mapWidth;
  2080. $mapContainer.style.height = state.mapHeight;
  2081. });
  2082. helpers.updateMapOpacity();
  2083. }
  2084.  
  2085. var _default = {
  2086. name: 'Map controls',
  2087. 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',
  2088. run: mapControls
  2089. };
  2090. exports.default = _default;
  2091.  
  2092. },{"../../utils/misc":35,"../../utils/state":37,"./helpers":21}],23:[function(require,module,exports){
  2093. "use strict";
  2094.  
  2095. Object.defineProperty(exports, "__esModule", {
  2096. value: true
  2097. });
  2098. exports.handleMerchantFilterInputChange = handleMerchantFilterInputChange;
  2099. exports.deleteMerchantObserver = deleteMerchantObserver;
  2100.  
  2101. var _game = require("../../utils/game");
  2102.  
  2103. var _state = require("../../utils/state");
  2104.  
  2105. function handleMerchantFilterInputChange() {
  2106. const $filterInput = document.querySelector('.js-merchant-filter-input');
  2107.  
  2108. if (!$filterInput) {
  2109. return;
  2110. }
  2111.  
  2112. const value = $filterInput.value;
  2113.  
  2114. if (value) {
  2115. _refreshMerchantFilter(); // When we're filtering, start refreshing merchant filter if we haven't already
  2116.  
  2117. } // If no filters, include single empty string, to make every item visible
  2118.  
  2119.  
  2120. const filters = value.split(',').map(v => v.trim()) || [''];
  2121. const $items = Array.from(document.querySelectorAll('.js-merchant-initd .items .slot'));
  2122. $items.forEach($item => {
  2123. const tooltipContentPromise = (0, _game.getTooltipContent)($item);
  2124. tooltipContentPromise.then(tooltipContent => {
  2125. if (!tooltipContent) {
  2126. // Something weird happened, probably related to lag from looking at tooltips in bulk
  2127. // In this case where we unexpectedly don't have the tooltip, just show the item rather than error out
  2128. $item.parentNode.style.display = 'grid';
  2129. return;
  2130. }
  2131.  
  2132. let filterMatchCount = 0;
  2133. filters.forEach(filter => {
  2134. const matchesFilter = tooltipContent.textContent.toLowerCase().includes(filter.toLowerCase());
  2135.  
  2136. if (matchesFilter) {
  2137. filterMatchCount++;
  2138. }
  2139. });
  2140. const matchesAllFilters = filterMatchCount === filters.length;
  2141.  
  2142. if (matchesAllFilters) {
  2143. $item.parentNode.style.display = 'grid';
  2144. } else {
  2145. $item.parentNode.style.display = 'none';
  2146. }
  2147. });
  2148. });
  2149. }
  2150.  
  2151. function _refreshMerchantFilter() {
  2152. const tempState = (0, _state.getTempState)(); // If we're already observing, we don't need to observe again
  2153.  
  2154. if (tempState.merchantLoadingObserver) return;
  2155. tempState.merchantLoadingObserver = new MutationObserver(mutation => {
  2156. // If spinner is visible, we are loading. Once spinner is not visible, we are no longer loading
  2157. if (mutation[0] && mutation[0].addedNodes[0] && mutation[0].addedNodes[0].classList.contains('spinner')) {
  2158. tempState.merchantLoading = true;
  2159. } else {
  2160. // If we were loading and now we aren't, we want to refresh the filters
  2161. if (tempState.merchantLoading) {
  2162. handleMerchantFilterInputChange();
  2163. }
  2164.  
  2165. tempState.merchantLoading = false;
  2166. }
  2167. });
  2168. tempState.merchantLoadingObserver.observe(document.querySelector('.js-merchant-initd .buy'), {
  2169. attributes: false,
  2170. childList: true,
  2171. subtree: true
  2172. });
  2173. }
  2174.  
  2175. function deleteMerchantObserver() {
  2176. const tempState = (0, _state.getTempState)();
  2177.  
  2178. if (tempState.merchantLoadingObserver) {
  2179. tempState.merchantLoading = false;
  2180. tempState.merchantLoadingObserver.disconnect();
  2181. delete tempState.merchantLoadingObserver;
  2182. }
  2183. }
  2184.  
  2185. },{"../../utils/game":34,"../../utils/state":37}],24:[function(require,module,exports){
  2186. "use strict";
  2187.  
  2188. Object.defineProperty(exports, "__esModule", {
  2189. value: true
  2190. });
  2191. exports.default = void 0;
  2192.  
  2193. var _game = require("../../utils/game");
  2194.  
  2195. var _misc = require("../../utils/misc");
  2196.  
  2197. var _ui = require("../../utils/ui");
  2198.  
  2199. var _helpers = require("./helpers");
  2200.  
  2201. function addMerchantFilter() {
  2202. const $merchant = (0, _game.getWindow)('Merchant'); // If merchant is closed or merchant filter input is already added, we dont need to do anything
  2203.  
  2204. if (!$merchant || $merchant.querySelector('.js-merchant-filter-input')) {
  2205. return;
  2206. }
  2207.  
  2208. $merchant.classList.add('js-merchant-initd');
  2209. $merchant.classList.add('uidom-merchant-with-filters');
  2210. (0, _ui.setWindowOpen)(_ui.WindowNames.merchant);
  2211. const $lvMaximumField = $merchant.querySelectorAll('input[type="number"]')[1];
  2212. const $customSearchField = (0, _misc.makeElement)({
  2213. element: 'input',
  2214. class: 'js-merchant-filter-input uidom-merchant-input',
  2215. type: 'search',
  2216. placeholder: 'Filters (comma separated)'
  2217. });
  2218. $lvMaximumField.parentNode.insertBefore($customSearchField, $lvMaximumField.nextSibling);
  2219. $merchant.querySelector('.js-merchant-filter-input').addEventListener('keyup', (0, _misc.debounce)(_helpers.handleMerchantFilterInputChange, 250));
  2220. }
  2221.  
  2222. function cleanupMerchantObserver() {
  2223. if ((0, _ui.isWindowOpen)(_ui.WindowNames.merchant)) {
  2224. const $merchant = document.querySelector('.js-merchant-initd');
  2225. if ($merchant) return;
  2226. } // Window was set to open but is actually closed, let's clean up...
  2227.  
  2228.  
  2229. (0, _ui.setWindowClosed)(_ui.WindowNames.merchant);
  2230. (0, _helpers.deleteMerchantObserver)();
  2231. }
  2232.  
  2233. var _default = {
  2234. name: 'Merchant filter',
  2235. description: 'Allows you to specify filters, or search text, for items displayed in the merchant',
  2236. run: ({
  2237. registerOnDomChange
  2238. }) => {
  2239. addMerchantFilter();
  2240. registerOnDomChange(addMerchantFilter);
  2241. registerOnDomChange(() => {
  2242. cleanupMerchantObserver();
  2243. });
  2244. }
  2245. };
  2246. exports.default = _default;
  2247.  
  2248. },{"../../utils/game":34,"../../utils/misc":35,"../../utils/ui":38,"./helpers":23}],25:[function(require,module,exports){
  2249. "use strict";
  2250.  
  2251. Object.defineProperty(exports, "__esModule", {
  2252. value: true
  2253. });
  2254. exports.default = void 0;
  2255.  
  2256. var _state = require("../../utils/state");
  2257.  
  2258. function resizableChat() {
  2259. const state = (0, _state.getState)(); // Add the appropriate classes
  2260.  
  2261. const $chatContainer = document.querySelector('#chat').parentNode;
  2262. $chatContainer.classList.add('js-chat-resize'); // Load initial chat and map size
  2263.  
  2264. if (state.chatWidth && state.chatHeight) {
  2265. $chatContainer.style.width = state.chatWidth;
  2266. $chatContainer.style.height = state.chatHeight;
  2267. } // Save chat size on resize
  2268.  
  2269.  
  2270. const resizeObserverChat = new ResizeObserver(() => {
  2271. const chatWidthStr = window.getComputedStyle($chatContainer, null).getPropertyValue('width');
  2272. const chatHeightStr = window.getComputedStyle($chatContainer, null).getPropertyValue('height');
  2273. const hasWidthChanged = state.chatWidth !== chatWidthStr;
  2274. const hasHeightChanged = state.chatHeight !== chatHeightStr;
  2275. if (hasWidthChanged) state.chatWidth = chatWidthStr;
  2276. if (hasHeightChanged) state.chatHeight = chatHeightStr;
  2277. if (hasWidthChanged || hasHeightChanged) (0, _state.saveState)();
  2278. });
  2279. resizeObserverChat.observe($chatContainer);
  2280. }
  2281.  
  2282. var _default = {
  2283. name: 'Resizable chat',
  2284. description: 'Allows you to resize chat by clicking and dragging from the bottom right of chat',
  2285. run: resizableChat
  2286. };
  2287. exports.default = _default;
  2288.  
  2289. },{"../../utils/state":37}],26:[function(require,module,exports){
  2290. "use strict";
  2291.  
  2292. Object.defineProperty(exports, "__esModule", {
  2293. value: true
  2294. });
  2295. exports.mapResizeHandler = mapResizeHandler;
  2296. exports.triggerMapResize = triggerMapResize;
  2297.  
  2298. var _state = require("../../utils/state");
  2299.  
  2300. // When the map container resizes, we want to update the canvas width/height and the state
  2301. function mapResizeHandler() {
  2302. if (!document.querySelector('.layout')) {
  2303. return;
  2304. }
  2305.  
  2306. const state = (0, _state.getState)();
  2307. const tempState = (0, _state.getTempState)();
  2308. const $map = document.querySelector('.container canvas').parentNode;
  2309. const $canvas = $map.querySelector('canvas'); // Get real values of map height/width, excluding padding/margin/etc
  2310. // We round the values in this file to prevent unnecessary decimal points in our map or canvas sizes
  2311. // For some people these decimal points cause the map to constantly resize, making it pretty unusable.
  2312. // Rounding the numbers fixes this.
  2313.  
  2314. const mapWidthStr = window.getComputedStyle($map, null).getPropertyValue('width');
  2315. const mapHeightStr = window.getComputedStyle($map, null).getPropertyValue('height');
  2316. const mapWidth = Math.round(Number(mapWidthStr.slice(0, -2)));
  2317. const mapHeight = Math.round(Number(mapHeightStr.slice(0, -2))); // If height/width are 0 or unset, don't resize canvas
  2318.  
  2319. if (!mapWidth || !mapHeight) {
  2320. return;
  2321. }
  2322.  
  2323. if ($canvas.width !== mapWidth) {
  2324. $canvas.width = mapWidth;
  2325. }
  2326.  
  2327. if ($canvas.height !== mapHeight) {
  2328. $canvas.height = mapHeight;
  2329. } // If we're clicking map, i.e. manually resizing, then save state
  2330. // Don't save state when minimizing/maximizing map via [M]
  2331.  
  2332.  
  2333. if (tempState.clickingMap) {
  2334. state.mapWidth = mapWidthStr;
  2335. state.mapHeight = mapHeightStr;
  2336. (0, _state.saveState)();
  2337. } else {
  2338. const isMaximized = mapWidth > tempState.lastMapWidth && mapHeight > tempState.lastMapHeight;
  2339.  
  2340. if (!isMaximized) {
  2341. $map.style.width = state.mapWidth;
  2342. $map.style.height = state.mapHeight;
  2343. }
  2344. } // Store last map width/height in temp state, so we know if we've minimized or maximized
  2345.  
  2346.  
  2347. tempState.lastMapWidth = mapWidth;
  2348. tempState.lastMapHeight = mapHeight;
  2349. } // We need to observe canvas resizes to tell when the user presses M to open the big map
  2350. // At that point, we resize the map to match the canvas
  2351.  
  2352.  
  2353. function triggerMapResize() {
  2354. if (!document.querySelector('.layout')) {
  2355. return;
  2356. }
  2357.  
  2358. const $map = document.querySelector('.container canvas').parentNode;
  2359. const $canvas = $map.querySelector('canvas'); // Get real values of map height/width, excluding padding/margin/etc
  2360.  
  2361. const mapWidthStr = window.getComputedStyle($map, null).getPropertyValue('width');
  2362. const mapHeightStr = window.getComputedStyle($map, null).getPropertyValue('height');
  2363. const mapWidth = Math.round(Number(mapWidthStr.slice(0, -2)));
  2364. const mapHeight = Math.round(Number(mapHeightStr.slice(0, -2)));
  2365. const canvasWidth = Math.round($canvas.width);
  2366. const canvasHeight = Math.round($canvas.height); // If height/width are 0 or unset, we don't care about resizing yet
  2367.  
  2368. if (!mapWidth || !mapHeight) {
  2369. return;
  2370. }
  2371.  
  2372. if (canvasWidth !== mapWidth) {
  2373. $map.style.width = `${canvasWidth}px`;
  2374. }
  2375.  
  2376. if (canvasHeight !== mapHeight) {
  2377. $map.style.height = `${canvasHeight}px`;
  2378. }
  2379. }
  2380.  
  2381. },{"../../utils/state":37}],27:[function(require,module,exports){
  2382. "use strict";
  2383.  
  2384. Object.defineProperty(exports, "__esModule", {
  2385. value: true
  2386. });
  2387. exports.default = void 0;
  2388.  
  2389. var _state = require("../../utils/state");
  2390.  
  2391. var helpers = _interopRequireWildcard(require("./helpers"));
  2392.  
  2393. var _misc = require("../../utils/misc");
  2394.  
  2395. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  2396.  
  2397. 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; }
  2398.  
  2399. function resizableMap() {
  2400. const state = (0, _state.getState)();
  2401. const tempState = (0, _state.getTempState)();
  2402. const $map = document.querySelector('.container canvas').parentNode;
  2403. const $canvas = $map.querySelector('canvas');
  2404. $map.classList.add('js-map-resize'); // Track whether we're clicking (resizing) map or not
  2405. // Used to detect if resize changes are manually done, or from minimizing/maximizing map (with [M])
  2406.  
  2407. $map.addEventListener('mousedown', () => {
  2408. tempState.clickingMap = true;
  2409. }); // Sometimes the mouseup event may be registered outside of the map - we account for this
  2410.  
  2411. document.body.addEventListener('mouseup', () => {
  2412. tempState.clickingMap = false;
  2413. });
  2414.  
  2415. if (state.mapWidth && state.mapHeight) {
  2416. $map.style.width = state.mapWidth;
  2417. $map.style.height = state.mapHeight;
  2418. helpers.mapResizeHandler(); // Update canvas size on initial load of saved map size
  2419. } // On resize of map, resize canvas to match
  2420. // Debouncing allows map to be visible while resizing
  2421.  
  2422.  
  2423. const debouncedMapResize = (0, _misc.debounce)(helpers.mapResizeHandler, 1);
  2424. const resizeObserverMap = new ResizeObserver(debouncedMapResize);
  2425. helpers.mapResizeHandler();
  2426. resizeObserverMap.observe($map); // We debounce the canvas resize, so it doesn't resize every single
  2427. // pixel you move when resizing the DOM. If this were to happen,
  2428. // resizing would constantly be interrupted. You'd have to resize a tiny bit,
  2429. // lift left click, left click again to resize a tiny bit more, etc.
  2430. // Resizing is smooth when we debounce this canvas.
  2431.  
  2432. const debouncedTriggerResize = (0, _misc.debounce)(helpers.triggerMapResize, 50);
  2433. const resizeObserverCanvas = new ResizeObserver(debouncedTriggerResize);
  2434. resizeObserverCanvas.observe($canvas);
  2435. }
  2436.  
  2437. var _default = {
  2438. name: 'Resizable map',
  2439. description: 'Allows you to resize the map by clicking and dragging from the bottom left',
  2440. run: resizableMap
  2441. };
  2442. exports.default = _default;
  2443.  
  2444. },{"../../utils/misc":35,"../../utils/state":37,"./helpers":26}],28:[function(require,module,exports){
  2445. "use strict";
  2446.  
  2447. Object.defineProperty(exports, "__esModule", {
  2448. value: true
  2449. });
  2450. exports.default = void 0;
  2451.  
  2452. // The last clicked UI window displays above all other UI windows
  2453. // This is useful when, for example, your inventory is near the market window,
  2454. // and you want the window and the tooltips to display above the market window.
  2455. function selectedWindowIsTop() {
  2456. Array.from(document.querySelectorAll('.window:not(.js-is-top-initd)')).forEach($window => {
  2457. $window.classList.add('js-is-top-initd');
  2458. $window.addEventListener('mousedown', () => {
  2459. // First, make the other is-top window not is-top
  2460. const $otherWindowContainer = document.querySelector('.js-is-top');
  2461.  
  2462. if ($otherWindowContainer) {
  2463. $otherWindowContainer.classList.remove('js-is-top');
  2464. } // Then, make our window's container (the z-index container) is-top
  2465.  
  2466.  
  2467. $window.parentNode.classList.add('js-is-top');
  2468. });
  2469. });
  2470. }
  2471.  
  2472. var _default = {
  2473. name: 'Make Selected Window Top',
  2474. description: 'The UI window you click will always be displayed over other UI windows',
  2475. run: ({
  2476. registerOnDomChange
  2477. }) => {
  2478. selectedWindowIsTop(); // As windows are opened, we want to enable them to become the top window when they're clicked
  2479.  
  2480. registerOnDomChange(selectedWindowIsTop);
  2481. }
  2482. };
  2483. exports.default = _default;
  2484.  
  2485. },{}],29:[function(require,module,exports){
  2486. "use strict";
  2487.  
  2488. Object.defineProperty(exports, "__esModule", {
  2489. value: true
  2490. });
  2491. exports.addSkillCooldownNumbers = addSkillCooldownNumbers;
  2492.  
  2493. var _state = require("../../utils/state");
  2494.  
  2495. var _misc = require("../../utils/misc");
  2496.  
  2497. function _getCooldownText(cd) {
  2498. const timeBetweenCooldownChecks = cd.latestCooldownTimestamp - cd.initialCooldownTimestamp;
  2499. const percentCompletedWithinTime = cd.initialCooldownPcntLeft - cd.latestCooldownPcntLeft;
  2500. const secondsForOnePercent = timeBetweenCooldownChecks / percentCompletedWithinTime / 1000;
  2501. return Math.floor(secondsForOnePercent * cd.latestCooldownPcntLeft);
  2502. }
  2503.  
  2504. function _handleCooldownUpdate(mutations) {
  2505. const tempState = (0, _state.getTempState)();
  2506. mutations.forEach(mutation => {
  2507. if (!mutation.target.classList.contains('cd')) return;
  2508. const $cooldownOverlay = mutation.target;
  2509. const skillId = $cooldownOverlay.parentNode.id;
  2510. const cooldownPercentageLeft = parseInt($cooldownOverlay.style.height);
  2511. let cdState = tempState.cooldownNums[skillId]; // If cooldown percentage left is greater than the current initial cooldown pcnt left,
  2512. // that means the skill cooldown counter is still tracking an old cooldown.
  2513. // This can happen rarely if the user casts the ability the instant it comes off cooldown.
  2514. // In this scenario, we want to reset the cooldown state.
  2515. // If we don't reset the cooldown state, the cooldown number will be wrong because
  2516. // `initialCooldownTime` will be from the previous cast, not the current cast.
  2517.  
  2518. if (cdState.initialCooldownPcntLeft && cooldownPercentageLeft >= cdState.initialCooldownPcntLeft) {
  2519. cdState.initialCooldownTimestamp = null;
  2520. cdState.initialCooldownPcntLeft = null;
  2521. cdState.latestCooldownTimestamp = null;
  2522. cdState.latestCooldownPcntLeft = null;
  2523. cdState.calculationCount = 0;
  2524. }
  2525.  
  2526. if (!cdState.initialCooldownTimestamp) {
  2527. cdState.initialCooldownTimestamp = Date.now();
  2528. cdState.initialCooldownPcntLeft = cooldownPercentageLeft;
  2529. }
  2530.  
  2531. cdState.latestCooldownTimestamp = Date.now();
  2532. cdState.latestCooldownPcntLeft = cooldownPercentageLeft;
  2533. cdState.calculationCount++; // Minimum number of numbers to figure out an accurate enough real cooldown number = 3
  2534. // Set the cooldown number in the UI
  2535.  
  2536. if (cdState.calculationCount > 2) {
  2537. const $cooldownNum = $cooldownOverlay.querySelector('.js-cooldown-num');
  2538. $cooldownNum.innerText = _getCooldownText(cdState);
  2539. }
  2540. });
  2541. }
  2542.  
  2543. function addSkillCooldownNumbers() {
  2544. const tempState = (0, _state.getTempState)(); // Add/update cooldowns
  2545.  
  2546. const $skillCooldowns = Array.from(document.querySelectorAll('#skillbar .cd:not(.js-cooldown-num-initd'));
  2547. $skillCooldowns.forEach($cooldownOverlay => {
  2548. $cooldownOverlay.classList.add('js-cooldown-num-initd'); // Add cooldown element to overlay
  2549.  
  2550. $cooldownOverlay.appendChild((0, _misc.makeElement)({
  2551. element: 'div',
  2552. class: 'js-cooldown-num'
  2553. }));
  2554. const cooldownObserver = new MutationObserver(_handleCooldownUpdate); // Add cooldown number and mutator to state
  2555.  
  2556. const skillId = $cooldownOverlay.parentNode.id;
  2557. tempState.cooldownNums[skillId] = {
  2558. initialCooldownTimestamp: null,
  2559. initialCooldownPcntLeft: null,
  2560. latestCooldownTimestamp: null,
  2561. latestCooldownPcntLeft: null,
  2562. calculationCount: 0
  2563. }; // Clear preexisting observer if it exists, then set new one to state
  2564.  
  2565. if (tempState.cooldownObservers[skillId]) {
  2566. tempState.cooldownObservers[skillId].disconnect();
  2567. delete tempState.cooldownObservers[skillId];
  2568. }
  2569.  
  2570. tempState.cooldownObservers[skillId] = cooldownObserver;
  2571. cooldownObserver.observe($cooldownOverlay, {
  2572. attributes: true
  2573. });
  2574. });
  2575. }
  2576.  
  2577. },{"../../utils/misc":35,"../../utils/state":37}],30:[function(require,module,exports){
  2578. "use strict";
  2579.  
  2580. Object.defineProperty(exports, "__esModule", {
  2581. value: true
  2582. });
  2583. exports.default = void 0;
  2584.  
  2585. var _state = require("../../utils/state");
  2586.  
  2587. var _helpers = require("./helpers");
  2588.  
  2589. function skillCooldownNumbers() {
  2590. const tempState = (0, _state.getTempState)(); // If not initialized, initialize with initial observer
  2591.  
  2592. const $skillBar = document.querySelector('#skillbar:not(.js-cooldowns-skillbar-initd');
  2593. if (!$skillBar) return;
  2594. $skillBar.classList.add('js-cooldowns-skillbar-initd');
  2595.  
  2596. if (tempState.skillBarObserver) {
  2597. tempState.skillBarObserver.disconnect();
  2598. delete tempState.skillBarObserver;
  2599. }
  2600.  
  2601. tempState.skillBarObserver = new MutationObserver(_helpers.addSkillCooldownNumbers);
  2602. tempState.skillBarObserver.observe($skillBar, {
  2603. subtree: true,
  2604. childList: true,
  2605. attributes: true
  2606. });
  2607. }
  2608.  
  2609. var _default = {
  2610. name: 'Skill cooldown numbers',
  2611. description: 'Overlays time left on cooldown over skill icons',
  2612. run: () => {
  2613. skillCooldownNumbers();
  2614. }
  2615. };
  2616. exports.default = _default;
  2617.  
  2618. },{"../../utils/state":37,"./helpers":29}],31:[function(require,module,exports){
  2619. "use strict";
  2620.  
  2621. Object.defineProperty(exports, "__esModule", {
  2622. value: true
  2623. });
  2624. exports.getCurrentCharacterLvl = getCurrentCharacterLvl;
  2625. exports.getCurrentXp = getCurrentXp;
  2626. exports.getNextLevelXp = getNextLevelXp;
  2627. exports.resetXpMeterState = resetXpMeterState;
  2628. exports.msToString = msToString;
  2629.  
  2630. var _state = require("../../utils/state");
  2631.  
  2632. function getCurrentCharacterLvl() {
  2633. return Number(document.querySelector('#ufplayer .bgmana > .left').textContent.split('Lv. ')[1]);
  2634. }
  2635.  
  2636. function getCurrentXp() {
  2637. return Number(document.querySelector('#expbar .progressBar > .left').textContent.split('/')[0].replace(/,/g, '').trim());
  2638. }
  2639.  
  2640. function getNextLevelXp() {
  2641. return Number(document.querySelector('#expbar .progressBar > .left').textContent.split('/')[1].replace(/,/g, '').replace('EXP', '').trim());
  2642. } // user invoked reset of xp meter stats
  2643.  
  2644.  
  2645. function resetXpMeterState() {
  2646. const state = (0, _state.getState)();
  2647. state.xpMeterState.xpGains = []; // array of xp deltas every second
  2648.  
  2649. state.xpMeterState.averageXp = 0;
  2650. state.xpMeterState.gainedXp = 0;
  2651. (0, _state.saveState)();
  2652. document.querySelector('.js-xp-time').textContent = '-:-:-';
  2653. }
  2654.  
  2655. function msToString(ms) {
  2656. const pad = value => value < 10 ? `0${value}` : value;
  2657.  
  2658. const hours = pad(Math.floor(ms / (1000 * 60 * 60) % 60));
  2659. const minutes = pad(Math.floor(ms / (1000 * 60) % 60));
  2660. const seconds = pad(Math.floor(ms / 1000 % 60));
  2661. return `${hours}:${minutes}:${seconds}`;
  2662. }
  2663.  
  2664. },{"../../utils/state":37}],32:[function(require,module,exports){
  2665. "use strict";
  2666.  
  2667. Object.defineProperty(exports, "__esModule", {
  2668. value: true
  2669. });
  2670. exports.default = void 0;
  2671.  
  2672. var _state = require("../../utils/state");
  2673.  
  2674. var helpers = _interopRequireWildcard(require("./helpers"));
  2675.  
  2676. var _ui = require("../../utils/ui");
  2677.  
  2678. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  2679.  
  2680. 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; }
  2681.  
  2682. // TODO: Consider adding start button to start interval, and stop after X minutes of no EXP
  2683. // Or maybe watch XP bar and start it once XP bar first moves?
  2684. // Adds XP Meter DOM icon and window, starts continuous interval to get current xp over time
  2685. function xpMeter() {
  2686. const state = (0, _state.getState)();
  2687. const tempState = (0, _state.getTempState)();
  2688. (0, _ui.createXpMeter)(); // If it was open when the game last closed keep it open
  2689.  
  2690. if ((0, _ui.isWindowOpen)(_ui.WindowNames.xpMeter)) {
  2691. (0, _ui.toggleXpMeterVisibility)();
  2692. } // Wire up icon and xpmeter window
  2693.  
  2694.  
  2695. document.querySelector('.js-sysxp').addEventListener('click', _ui.toggleXpMeterVisibility);
  2696. document.querySelector('.js-xpmeter-close-icon').addEventListener('click', _ui.toggleXpMeterVisibility);
  2697. document.querySelector('.js-xpmeter-reset-button').addEventListener('click', helpers.resetXpMeterState);
  2698. const currentXp = helpers.getCurrentXp();
  2699. const currentCharLvl = helpers.getCurrentCharacterLvl();
  2700. if (currentXp !== state.xpMeterState.currentXp) state.xpMeterState.currentXp = currentXp;
  2701. if (currentCharLvl !== state.xpMeterState.currentLvl) state.xpMeterState.currentLvl = currentCharLvl;
  2702. (0, _state.saveState)();
  2703. if (tempState.xpMeterInterval) clearInterval(tempState.xpMeterInterval); // every second we run the operations for xp meter, update xps, calc delta, etc
  2704. // TODO Cleanup: This interval may not be cleaned up if the UI mod reinitializes,
  2705. // e.g. user is away from tab for a while then comes back
  2706. // Should confirm if this is an issue, and try to fix it if possible.
  2707.  
  2708. tempState.xpMeterInterval = setInterval(() => {
  2709. if (!document.querySelector('#expbar')) {
  2710. return;
  2711. } // This _shouldn't_ happen, but in case it does, reset xp meter state instead of throwing error
  2712.  
  2713.  
  2714. if (!Array.isArray(state.xpMeterState.xpGains)) {
  2715. helpers.resetXpMeterState();
  2716. }
  2717.  
  2718. const currentXp = helpers.getCurrentXp();
  2719. const nextLvlXp = helpers.getNextLevelXp();
  2720. const currentLvl = helpers.getCurrentCharacterLvl(); // Only update and save state if it has changed
  2721.  
  2722. const gainedXp = currentXp - state.xpMeterState.currentXp;
  2723. const xpGains = currentXp - state.xpMeterState.currentXp;
  2724. 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
  2725.  
  2726. state.xpMeterState.xpGains.push(xpGains); // array of xp deltas every second
  2727.  
  2728. if (gainedXp !== 0) state.xpMeterState.gainedXp += gainedXp;
  2729. if (currentXp !== state.xpMeterState.currentXp) state.xpMeterState.currentXp = currentXp;
  2730. if (averageXp !== state.xpMeterState.averageXp) state.xpMeterState.averageXp = averageXp;
  2731. (0, _state.saveState)();
  2732.  
  2733. if (document.querySelector('.js-xpmeter')) {
  2734. document.querySelector('.js-xpm').textContent = parseInt((state.xpMeterState.averageXp * 60).toFixed(0)).toLocaleString();
  2735. document.querySelector('.js-xph').textContent = parseInt((state.xpMeterState.averageXp * 60 * 60).toFixed(0)).toLocaleString();
  2736. document.querySelector('.js-xpg').textContent = state.xpMeterState.gainedXp.toLocaleString();
  2737. document.querySelector('.js-xpl').textContent = (nextLvlXp - currentXp).toLocaleString();
  2738. document.querySelector('.js-xp-s-time').textContent = helpers.msToString(state.xpMeterState.xpGains.length * 1000); // need a positive integer for averageXp to calc time left
  2739.  
  2740. if (state.xpMeterState.averageXp > 0) document.querySelector('.js-xp-time').textContent = helpers.msToString((nextLvlXp - currentXp) / state.xpMeterState.averageXp * 1000);
  2741. }
  2742.  
  2743. if (state.xpMeterState.currentLvl < currentLvl) {
  2744. helpers.resetXpMeterState();
  2745. state.xpMeterState.currentLvl = currentLvl;
  2746. (0, _state.saveState)();
  2747. }
  2748. }, 1000);
  2749. }
  2750.  
  2751. var _default = {
  2752. name: 'XP Meter',
  2753. description: "Tracks your XP/minute and displays how much XP you're getting and lets you know how long until you level up",
  2754. run: xpMeter
  2755. };
  2756. exports.default = _default;
  2757.  
  2758. },{"../../utils/state":37,"../../utils/ui":38,"./helpers":31}],33:[function(require,module,exports){
  2759. "use strict";
  2760.  
  2761. Object.defineProperty(exports, "__esModule", {
  2762. value: true
  2763. });
  2764. exports.filterAllChat = filterAllChat;
  2765. exports.whisperPlayer = whisperPlayer;
  2766. exports.partyPlayer = partyPlayer;
  2767. exports.addChatMessage = addChatMessage;
  2768.  
  2769. var _state = require("./state");
  2770.  
  2771. var _misc = require("./misc");
  2772.  
  2773. // Filters all chat based on custom filters
  2774. function filterAllChat() {
  2775. const state = (0, _state.getState)(); // Blocked user filter
  2776.  
  2777. Object.keys(state.blockList).forEach(blockedName => {
  2778. // Get the `.name` elements from the blocked user, if we haven't already hidden their messages
  2779. const $blockedChatNames = Array.from(document.querySelectorAll(`[data-chat-name="${blockedName}"]:not(.js-line-blocked)`)); // Hide each of their messages
  2780.  
  2781. $blockedChatNames.forEach($name => {
  2782. // Add the class name to $name so we can track whether it's been hidden in our CSS selector $blockedChatNames
  2783. $name.classList.add('js-line-blocked');
  2784. const $line = $name.parentNode.parentNode.parentNode; // Add the class name to $line so we can visibly hide the entire chat line
  2785.  
  2786. $line.classList.add('js-line-blocked');
  2787. });
  2788. });
  2789. }
  2790.  
  2791. function enterTextIntoChat(text) {
  2792. // Open chat input
  2793. const enterEvent = new KeyboardEvent('keydown', {
  2794. bubbles: true,
  2795. cancelable: true,
  2796. keyCode: 13
  2797. });
  2798. document.body.dispatchEvent(enterEvent); // Place text into chat
  2799.  
  2800. const $input = document.querySelector('#chatinput input');
  2801. $input.value = text; // Get chat input to recognize slash commands and change the channel
  2802. // by triggering the `input` event.
  2803. // (Did some debugging to figure out the channel only changes when the
  2804. // svelte `input` event listener exists.)
  2805.  
  2806. const inputEvent = new KeyboardEvent('input', {
  2807. bubbles: true,
  2808. cancelable: true
  2809. });
  2810. $input.dispatchEvent(inputEvent);
  2811. }
  2812.  
  2813. function submitChat() {
  2814. const $input = document.querySelector('#chatinput input');
  2815. const kbEvent = new KeyboardEvent('keydown', {
  2816. bubbles: true,
  2817. cancelable: true,
  2818. keyCode: 13
  2819. });
  2820. $input.dispatchEvent(kbEvent);
  2821. } // Automated chat command helpers
  2822. // (We've been OK'd to do these by the dev - all automation like this should receive approval from the dev)
  2823.  
  2824.  
  2825. function whisperPlayer(playerName) {
  2826. enterTextIntoChat(`/${playerName} `);
  2827. }
  2828.  
  2829. function partyPlayer(playerName) {
  2830. enterTextIntoChat(`/partyinvite ${playerName}`);
  2831. submitChat();
  2832. } // Pushes message to chat
  2833. // TODO: The margins for the message are off slightly compared to other messages - why?
  2834.  
  2835.  
  2836. function addChatMessage(text) {
  2837. const newMessageHTML = `
  2838. <div class="linewrap svelte-1vrlsr3">
  2839. <span class="time svelte-1vrlsr3">00.00</span>
  2840. <span class="textuimod content svelte-1vrlsr3">
  2841. <span class="capitalize channel svelte-1vrlsr3">UIMod</span>
  2842. </span>
  2843. <span class="svelte-1vrlsr3">${text}</span>
  2844. </div>
  2845. `;
  2846. const element = (0, _misc.makeElement)({
  2847. element: 'article',
  2848. class: 'line svelte-1vrlsr3',
  2849. content: newMessageHTML
  2850. });
  2851. const $chat = document.querySelector('#chat');
  2852. $chat.appendChild(element); // Scroll to bottom of chat
  2853.  
  2854. $chat.scrollTop = $chat.scrollHeight;
  2855. }
  2856.  
  2857. },{"./misc":35,"./state":37}],34:[function(require,module,exports){
  2858. "use strict";
  2859.  
  2860. Object.defineProperty(exports, "__esModule", {
  2861. value: true
  2862. });
  2863. exports.getTooltipContent = getTooltipContent;
  2864. exports.getWindow = getWindow;
  2865.  
  2866. var _state = require("./state");
  2867.  
  2868. // Gets the node of a tooltip for any element, emulates shift keypress to get tooltip with quality details
  2869. // Must be `await`'d to use, e.g. `await getTooltipContent($element)`
  2870. // Optionally pass `getDetailedTooltips` as `true` if you want detailed tooltips by holding shift
  2871. // ^ is laggier, do not use when looking at more than one item
  2872. async function getTooltipContent($elementToHoverOver, getDetailedTooltips) {
  2873. const tempState = (0, _state.getTempState)(); // Emulate holding down shift when getting tooltip
  2874. // Don't need to emulate if user is already holding it down
  2875.  
  2876. if (getDetailedTooltips && !tempState.keyModifiers.shift) {
  2877. // Set this so the keymodifiers mod knows our shift press shouldn't be tracked in tempState
  2878. tempState.gettingTooltipContentShiftPress = true;
  2879. document.body.dispatchEvent(new KeyboardEvent('keydown', {
  2880. bubbles: true,
  2881. cancelable: true,
  2882. key: 'Shift'
  2883. }));
  2884. }
  2885.  
  2886. $elementToHoverOver.dispatchEvent(new Event('pointerenter'));
  2887. const closeTooltipPromise = new Promise(resolve => setTimeout(() => {
  2888. const resolveWithTooltip = () => {
  2889. // If there is no slotdescription at this point, the item element passed very likely has no tooltip
  2890. const $tooltip = document.querySelector('.slotdescription');
  2891.  
  2892. if (!$tooltip || !$tooltip.cloneNode) {
  2893. resolve(false);
  2894. } else {
  2895. resolve($tooltip.cloneNode(true));
  2896. }
  2897.  
  2898. if (tempState.gettingTooltipContentShiftPress) {
  2899. // Release our emulated shift press
  2900. document.body.dispatchEvent(new KeyboardEvent('keyup', {
  2901. bubbles: true,
  2902. cancelable: true,
  2903. key: 'Shift'
  2904. }));
  2905. tempState.gettingTooltipContentShiftPress = false;
  2906. }
  2907.  
  2908. $elementToHoverOver.dispatchEvent(new Event('pointerleave'));
  2909. }; // Very occasionally the 0ms wait time on our timeout doesn't show the tooltip,
  2910. // so we set a second timeout to account for this. Not the most perfect user experience,
  2911. // but it rarely hapens, and it's better than getting an error.
  2912.  
  2913.  
  2914. if (getDetailedTooltips && !document.querySelector('.slotdescription')) {
  2915. setTimeout(resolveWithTooltip, 1);
  2916. } else {
  2917. resolveWithTooltip();
  2918. }
  2919. }, 0));
  2920. const $tooltip = await closeTooltipPromise;
  2921. return $tooltip;
  2922. } // Use this to get a specific window, rather than using the svelte class, which is not preferable
  2923. // Only returns window if it is visible. Some windows are kept in DOM at all times, but are not visible until opened, e.g. Inventory.
  2924. // To get window even if it isn't visible (but is still in DOM), pass `true` to second argument
  2925.  
  2926.  
  2927. function getWindow(windowTitle, getInvisibleWindow) {
  2928. const $specificWindowTitle = Array.from(document.querySelectorAll('.window [name="title"]')).find($windowTitle => $windowTitle.textContent.toLowerCase() === windowTitle.toLowerCase());
  2929. const $window = $specificWindowTitle ? $specificWindowTitle.parentNode.parentNode.parentNode : $specificWindowTitle; // If window is invisible, don't return it unless we are overriding with `getInvisibleWindow`
  2930.  
  2931. if (!$window || !$window.offsetParent && !getInvisibleWindow) {
  2932. return;
  2933. } else {
  2934. return $specificWindowTitle ? $specificWindowTitle.parentNode.parentNode.parentNode : $specificWindowTitle;
  2935. }
  2936. }
  2937.  
  2938. },{"./state":37}],35:[function(require,module,exports){
  2939. "use strict";
  2940.  
  2941. Object.defineProperty(exports, "__esModule", {
  2942. value: true
  2943. });
  2944. exports.makeElement = makeElement;
  2945. exports.debounce = debounce;
  2946. exports.uuid = uuid;
  2947. exports.deepClone = deepClone;
  2948.  
  2949. // Nicer impl to create elements in one method call
  2950. function makeElement(args) {
  2951. const $node = document.createElement(args.element);
  2952. if (args.class) $node.className = args.class;
  2953. if (args.content) $node.innerHTML = args.content;
  2954. if (args.src) $node.src = args.src;
  2955. if (args.type) $node.type = args.type;
  2956. if (args.placeholder) $node.placeholder = args.placeholder;
  2957. return $node;
  2958. } // Credit: David Walsh
  2959.  
  2960.  
  2961. function debounce(func, wait, immediate) {
  2962. var timeout;
  2963. return function () {
  2964. var context = this,
  2965. args = arguments;
  2966.  
  2967. var later = function () {
  2968. timeout = null;
  2969. if (!immediate) func.apply(context, args);
  2970. };
  2971.  
  2972. var callNow = immediate && !timeout;
  2973. clearTimeout(timeout);
  2974. timeout = setTimeout(later, wait);
  2975. if (callNow) func.apply(context, args);
  2976. };
  2977. } // Credit: https://gist.github.com/jcxplorer/823878
  2978. // Generate random UUID string
  2979.  
  2980.  
  2981. function uuid() {
  2982. var uuid = '',
  2983. i,
  2984. random;
  2985.  
  2986. for (i = 0; i < 32; i++) {
  2987. random = Math.random() * 16 | 0;
  2988.  
  2989. if (i == 8 || i == 12 || i == 16 || i == 20) {
  2990. uuid += '-';
  2991. }
  2992.  
  2993. uuid += (i == 12 ? 4 : i == 16 ? random & 3 | 8 : random).toString(16);
  2994. }
  2995.  
  2996. return uuid;
  2997. } // Credit: http://voidcanvas.com/clone-an-object-in-vanilla-js-in-depth/
  2998.  
  2999.  
  3000. function deepClone(obj) {
  3001. //in case of premitives
  3002. if (obj === null || typeof obj !== 'object') {
  3003. return obj;
  3004. } //date objects should be
  3005.  
  3006.  
  3007. if (obj instanceof Date) {
  3008. return new Date(obj.getTime());
  3009. } //handle Array
  3010.  
  3011.  
  3012. if (Array.isArray(obj)) {
  3013. var clonedArr = [];
  3014. obj.forEach(function (element) {
  3015. clonedArr.push(deepClone(element));
  3016. });
  3017. return clonedArr;
  3018. } //lastly, handle objects
  3019.  
  3020.  
  3021. let clonedObj = new obj.constructor();
  3022.  
  3023. for (var prop in obj) {
  3024. if (obj.hasOwnProperty(prop)) {
  3025. clonedObj[prop] = deepClone(obj[prop]);
  3026. }
  3027. }
  3028.  
  3029. return clonedObj;
  3030. }
  3031.  
  3032. },{}],36:[function(require,module,exports){
  3033. "use strict";
  3034.  
  3035. Object.defineProperty(exports, "__esModule", {
  3036. value: true
  3037. });
  3038. exports.friendPlayer = friendPlayer;
  3039. exports.unfriendPlayer = unfriendPlayer;
  3040. exports.blockPlayer = blockPlayer;
  3041. exports.unblockPlayer = unblockPlayer;
  3042.  
  3043. var _state = require("./state");
  3044.  
  3045. var chat = _interopRequireWildcard(require("./chat"));
  3046.  
  3047. var ui = _interopRequireWildcard(require("./ui"));
  3048.  
  3049. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  3050.  
  3051. 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; }
  3052.  
  3053. function friendPlayer(playerName) {
  3054. const state = (0, _state.getState)();
  3055.  
  3056. if (state.friendsList[playerName]) {
  3057. return;
  3058. }
  3059.  
  3060. state.friendsList[playerName] = true;
  3061. chat.addChatMessage(`${playerName} has been added to your friends list.`);
  3062. (0, _state.saveState)(); // If UI is open remake it with new changes
  3063.  
  3064. if (ui.isWindowOpen(ui.WindowNames.friendsList)) {
  3065. ui.removeFriendsList();
  3066. ui.createFriendsList();
  3067. }
  3068. }
  3069.  
  3070. function unfriendPlayer(playerName) {
  3071. const state = (0, _state.getState)();
  3072.  
  3073. if (!state.friendsList[playerName]) {
  3074. return;
  3075. }
  3076.  
  3077. delete state.friendsList[playerName];
  3078. delete state.friendNotes[playerName];
  3079. chat.addChatMessage(`${playerName} is no longer on your friends list.`);
  3080. (0, _state.saveState)(); // If UI is open remake it with new changes
  3081.  
  3082. if (ui.isWindowOpen(ui.WindowNames.friendsList)) {
  3083. ui.removeFriendsList();
  3084. ui.createFriendsList();
  3085. }
  3086. } // Adds player to block list, to be filtered out of chat
  3087.  
  3088.  
  3089. function blockPlayer(playerName) {
  3090. const state = (0, _state.getState)();
  3091.  
  3092. if (state.blockList[playerName]) {
  3093. return;
  3094. }
  3095.  
  3096. state.blockList[playerName] = true;
  3097. chat.filterAllChat();
  3098. chat.addChatMessage(`${playerName} has been blocked.`);
  3099. (0, _state.saveState)(); // If UI is open remake it with new changes
  3100.  
  3101. if (ui.isWindowOpen(ui.WindowNames.blockList)) {
  3102. ui.removeBlockList();
  3103. ui.createBlockList();
  3104. }
  3105. } // Removes player from block list and makes their messages visible again
  3106.  
  3107.  
  3108. function unblockPlayer(playerName) {
  3109. const state = (0, _state.getState)();
  3110. delete state.blockList[playerName];
  3111. chat.addChatMessage(`${playerName} has been unblocked.`);
  3112. (0, _state.saveState)(); // Make messages visible again
  3113.  
  3114. const $chatNames = Array.from(document.querySelectorAll(`.js-line-blocked[data-chat-name="${playerName}"]`));
  3115. $chatNames.forEach($name => {
  3116. $name.classList.remove('js-line-blocked');
  3117. const $line = $name.parentNode.parentNode.parentNode;
  3118. $line.classList.remove('js-line-blocked');
  3119. });
  3120. }
  3121.  
  3122. },{"./chat":33,"./state":37,"./ui":38}],37:[function(require,module,exports){
  3123. "use strict";
  3124.  
  3125. Object.defineProperty(exports, "__esModule", {
  3126. value: true
  3127. });
  3128. exports.getState = getState;
  3129. exports.getTempState = getTempState;
  3130. exports.saveState = saveState;
  3131. exports.loadState = loadState;
  3132.  
  3133. var _version = require("./version");
  3134.  
  3135. const STORAGE_STATE_KEY = 'hordesio-uimodsakaiyo-state';
  3136. let state = {
  3137. breakingVersion: _version.BREAKING_VERSION,
  3138. windowsPos: {},
  3139. blockList: {},
  3140. friendsList: {},
  3141. mapOpacity: 70,
  3142. // e.g. 70 = opacity: 0.7
  3143. friendNotes: {},
  3144. chatTabs: [],
  3145. xpMeterState: {
  3146. currentXp: 0,
  3147. xpGains: [],
  3148. // array of xp deltas every second
  3149. averageXp: 0,
  3150. gainedXp: 0,
  3151. currentLvl: 0
  3152. },
  3153. openWindows: {
  3154. friendsList: false,
  3155. blockList: false,
  3156. xpMeter: false,
  3157. merchant: false
  3158. },
  3159. clanLastActiveMembers: {},
  3160. lockedItemSlots: []
  3161. }; // tempState is saved only between page refreshes.
  3162.  
  3163. const tempState = {
  3164. // The last name clicked in chat
  3165. chatName: null,
  3166. lastMapWidth: 0,
  3167. lastMapHeight: 0,
  3168. xpMeterInterval: null,
  3169. // tracks the interval for fetching xp data
  3170. keyModifiers: {
  3171. shift: false,
  3172. control: false,
  3173. alt: false
  3174. },
  3175. // set by _keyModifiers mod
  3176. cooldownNums: {},
  3177. cooldownObservers: {}
  3178. };
  3179.  
  3180. function getState() {
  3181. return state;
  3182. }
  3183.  
  3184. function getTempState() {
  3185. return tempState;
  3186. }
  3187.  
  3188. function saveState() {
  3189. localStorage.setItem(STORAGE_STATE_KEY, JSON.stringify(state));
  3190. }
  3191.  
  3192. function loadState() {
  3193. const storedStateJson = localStorage.getItem(STORAGE_STATE_KEY);
  3194.  
  3195. if (storedStateJson) {
  3196. const storedState = JSON.parse(storedStateJson);
  3197.  
  3198. if (storedState.breakingVersion !== _version.BREAKING_VERSION) {
  3199. localStorage.setItem(STORAGE_STATE_KEY, JSON.stringify(state));
  3200. return;
  3201. }
  3202.  
  3203. for (let [key, value] of Object.entries(storedState)) {
  3204. state[key] = value;
  3205. }
  3206. }
  3207. }
  3208.  
  3209. },{"./version":39}],38:[function(require,module,exports){
  3210. "use strict";
  3211.  
  3212. Object.defineProperty(exports, "__esModule", {
  3213. value: true
  3214. });
  3215. exports.createBlockList = createBlockList;
  3216. exports.removeBlockList = removeBlockList;
  3217. exports.createFriendsList = createFriendsList;
  3218. exports.removeFriendsList = removeFriendsList;
  3219. exports.toggleFriendsList = toggleFriendsList;
  3220. exports.toggleXpMeterVisibility = toggleXpMeterVisibility;
  3221. exports.createXpMeter = createXpMeter;
  3222. exports.resetUiPositions = resetUiPositions;
  3223. exports.setWindowOpen = setWindowOpen;
  3224. exports.setWindowClosed = setWindowClosed;
  3225. exports.isWindowOpen = isWindowOpen;
  3226. exports.WindowNames = void 0;
  3227.  
  3228. var _state = require("./state");
  3229.  
  3230. var _misc = require("./misc");
  3231.  
  3232. var chat = _interopRequireWildcard(require("./chat"));
  3233.  
  3234. var player = _interopRequireWildcard(require("./player"));
  3235.  
  3236. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  3237.  
  3238. 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; }
  3239.  
  3240. const WindowNames = {
  3241. friendsList: 'friendsList',
  3242. blockList: 'blockList',
  3243. xpMeter: 'xpMeter',
  3244. merchant: 'merchant',
  3245. clan: 'clan',
  3246. stash: 'stash',
  3247. inventory: 'inventory'
  3248. };
  3249. exports.WindowNames = WindowNames;
  3250.  
  3251. function createBlockList() {
  3252. const state = (0, _state.getState)();
  3253. let blockedPlayersHTML = '';
  3254. Object.keys(state.blockList).sort().forEach(blockedName => {
  3255. blockedPlayersHTML += `
  3256. <div data-player-name="${blockedName}">${blockedName}</div>
  3257. <div class="btn orange js-unblock-player" data-player-name="${blockedName}">Unblock player</div>
  3258. `;
  3259. });
  3260. const customSettingsHTML = `
  3261. <h3 class="textprimary">Blocked players</h3>
  3262. <div class="settings uimod-settings">${blockedPlayersHTML}</div>
  3263. <p></p>
  3264. <div class="btn purp js-close-custom-settings">Close</div>
  3265. `;
  3266. const $customSettings = (0, _misc.makeElement)({
  3267. element: 'div',
  3268. class: 'menu panel-black uimod-custom-window js-blocked-list',
  3269. content: customSettingsHTML
  3270. });
  3271. document.body.appendChild($customSettings);
  3272. setWindowOpen(WindowNames.blockList); // Wire up all the unblock buttons
  3273.  
  3274. Array.from(document.querySelectorAll('.js-unblock-player')).forEach($button => {
  3275. $button.addEventListener('click', clickEvent => {
  3276. const name = clickEvent.target.getAttribute('data-player-name');
  3277. player.unblockPlayer(name); // Remove the blocked player from the list
  3278.  
  3279. Array.from(document.querySelectorAll(`.js-blocked-list [data-player-name="${name}"]`)).forEach($element => {
  3280. $element.parentNode.removeChild($element);
  3281. });
  3282. });
  3283. }); // And the close button for our custom UI
  3284.  
  3285. document.querySelector('.js-close-custom-settings').addEventListener('click', removeBlockList);
  3286. }
  3287.  
  3288. function removeBlockList() {
  3289. const $customSettingsWindow = document.querySelector('.js-blocked-list');
  3290. $customSettingsWindow.parentNode.removeChild($customSettingsWindow);
  3291. setWindowClosed(WindowNames.blockList);
  3292. }
  3293.  
  3294. function createFriendsList() {
  3295. const state = (0, _state.getState)();
  3296.  
  3297. if (document.querySelector('.js-friends-list')) {
  3298. // Don't open the friends list twice.
  3299. return;
  3300. }
  3301.  
  3302. let friendsListHTML = '';
  3303. Object.keys(state.friendsList).sort().forEach(friendName => {
  3304. friendsListHTML += `
  3305. <div data-player-name="${friendName}">${friendName}</div>
  3306. <div class="btn blue js-whisper-player" data-player-name="${friendName}">Whisper</div>
  3307. <div class="btn blue js-party-player" data-player-name="${friendName}">Party invite</div>
  3308. <div class="btn orange js-unfriend-player" data-player-name="${friendName}">X</div>
  3309. <input type="text" class="js-friend-note" data-player-name="${friendName}" value="${state.friendNotes[friendName] || ''}"></input>
  3310. `;
  3311. });
  3312. const customFriendsWindowHTML = `
  3313. <div class="titleframe uimod-friends-list-helper">
  3314. <div class="textprimary title uimod-friends-list-helper">
  3315. <div name="title">Friends list</div>
  3316. </div>
  3317. <img src="/assets/ui/icons/cross.svg?v=3282286" class="js-close-custom-friends-list btn black svgicon">
  3318. </div>
  3319. <div class="uimod-friends-intro">To add someone as a friend, click their name in chat and then click Friend :)</div>
  3320. <div class="uimod-friends">${friendsListHTML}</div>
  3321. `;
  3322. const $customFriendsList = (0, _misc.makeElement)({
  3323. element: 'div',
  3324. class: 'menu window panel-black js-friends-list uimod-custom-window',
  3325. content: customFriendsWindowHTML
  3326. });
  3327. document.body.appendChild($customFriendsList);
  3328. setWindowOpen(WindowNames.friendsList); // Wire up the buttons
  3329.  
  3330. Array.from(document.querySelectorAll('.js-whisper-player')).forEach($button => {
  3331. $button.addEventListener('click', clickEvent => {
  3332. const name = clickEvent.target.getAttribute('data-player-name');
  3333. player.whisperPlayer(name);
  3334. });
  3335. });
  3336. Array.from(document.querySelectorAll('.js-party-player')).forEach($button => {
  3337. $button.addEventListener('click', clickEvent => {
  3338. const name = clickEvent.target.getAttribute('data-player-name');
  3339. player.partyPlayer(name);
  3340. });
  3341. });
  3342. Array.from(document.querySelectorAll('.js-unfriend-player')).forEach($button => {
  3343. $button.addEventListener('click', clickEvent => {
  3344. const name = clickEvent.target.getAttribute('data-player-name');
  3345. player.unfriendPlayer(name); // Remove the blocked player from the list
  3346.  
  3347. Array.from(document.querySelectorAll(`.js-friends-list [data-player-name="${name}"]`)).forEach($element => {
  3348. $element.parentNode.removeChild($element);
  3349. });
  3350. });
  3351. });
  3352. Array.from(document.querySelectorAll('.js-friend-note')).forEach($element => {
  3353. $element.addEventListener('change', clickEvent => {
  3354. const name = clickEvent.target.getAttribute('data-player-name');
  3355. state.friendNotes[name] = clickEvent.target.value;
  3356. });
  3357. }); // The close button for our custom UI
  3358.  
  3359. document.querySelector('.js-close-custom-friends-list').addEventListener('click', removeFriendsList);
  3360. }
  3361.  
  3362. function removeFriendsList() {
  3363. const $friendsListWindow = document.querySelector('.js-friends-list');
  3364. $friendsListWindow.parentNode.removeChild($friendsListWindow);
  3365. setWindowClosed(WindowNames.friendsList);
  3366. }
  3367.  
  3368. function toggleFriendsList() {
  3369. if (isWindowOpen(WindowNames.friendsList)) {
  3370. removeFriendsList();
  3371. } else {
  3372. createFriendsList();
  3373. }
  3374. }
  3375.  
  3376. function toggleXpMeterVisibility() {
  3377. const xpMeterContainer = document.querySelector('.js-xpmeter'); // Make it if it doesn't exist for some reason
  3378.  
  3379. if (!xpMeterContainer) {
  3380. createXpMeter();
  3381. }
  3382.  
  3383. xpMeterContainer.style.display = xpMeterContainer.style.display === 'none' ? 'block' : 'none'; // Save whether xpMeter is currently open or closed in the state
  3384.  
  3385. if (xpMeterContainer.style.display === 'none') {
  3386. setWindowClosed(WindowNames.xpMeter);
  3387. } else {
  3388. setWindowOpen(WindowNames.xpMeter);
  3389. }
  3390. }
  3391.  
  3392. function createXpMeter() {
  3393. const $layoutContainer = document.querySelector('body > div.layout > div.container:nth-child(1)');
  3394. const $dpsMeterToggleElement = document.querySelector('#systrophy');
  3395. const $xpMeterToggleElement = (0, _misc.makeElement)({
  3396. element: 'div',
  3397. class: 'js-sysxp js-xpmeter-icon btn border black',
  3398. content: 'XP'
  3399. });
  3400. const xpMeterHTMLString = `
  3401. <div class="l-corner-lr container uimod-xpmeter-1 js-xpmeter" style="display: none">
  3402. <div class="window panel-black uimod-xpmeter-2">
  3403. <div class="titleframe uimod-xpmeter-2">
  3404. <img src="/assets/ui/icons/trophy.svg?v=3282286" class="titleicon svgicon uimod-xpmeter-2">
  3405. <div class="textprimary title uimod-xpmeter-2">
  3406. <div name="title">Experience / XP</div>
  3407. </div>
  3408. <img src="/assets/ui/icons/cross.svg?v=3282286" class="js-xpmeter-close-icon btn black svgicon">
  3409. </div>
  3410. <div class="slot uimod-xpmeter-2" style="">
  3411. <div class="wrapper uimod-xpmeter-1">
  3412. <div class="bar uimod-xpmeter-3" style="z-index: 0;">
  3413. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  3414. <span class="left uimod-xpmeter-3">XP per minute:</span>
  3415. <span class="right uimod-xpmeter-3 js-xpm">-</span>
  3416. </div>
  3417. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  3418. <span class="left uimod-xpmeter-3">XP per hour:</span>
  3419. <span class="right uimod-xpmeter-3 js-xph">-</span>
  3420. </div>
  3421. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  3422. <span class="left uimod-xpmeter-3">XP Gained:</span>
  3423. <span class="right uimod-xpmeter-3 js-xpg">-</span>
  3424. </div>
  3425. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  3426. <span class="left uimod-xpmeter-3">XP Left:</span>
  3427. <span class="right uimod-xpmeter-3 js-xpl">-</span>
  3428. </div>
  3429. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  3430. <span class="left uimod-xpmeter-3">Session Time: </span>
  3431. <span class="right uimod-xpmeter-3 js-xp-s-time">-</span>
  3432. </div>
  3433. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  3434. <span class="left uimod-xpmeter-3">Time to lvl: </span>
  3435. <span class="right uimod-xpmeter-3 js-xp-time">-</span>
  3436. </div>
  3437. </div>
  3438. </div>
  3439. <div class="grid buttons marg-top uimod-xpmeter-1 js-xpmeter-reset-button">
  3440. <div class="btn grey">Reset</div>
  3441. </div>
  3442. </div>
  3443. </div>
  3444. </div>
  3445. `;
  3446. $dpsMeterToggleElement.parentNode.insertBefore($xpMeterToggleElement, $dpsMeterToggleElement.nextSibling);
  3447. const $xpMeterElement = (0, _misc.makeElement)({
  3448. element: 'div',
  3449. content: xpMeterHTMLString.trim()
  3450. });
  3451. $layoutContainer.appendChild($xpMeterElement.firstChild);
  3452. }
  3453.  
  3454. function resetUiPositions() {
  3455. const state = (0, _state.getState)();
  3456. state.windowsPos = {};
  3457. (0, _state.saveState)();
  3458. chat.addChatMessage('Please refresh the page for the reset frame & window positions to take effect.');
  3459. } // state.openWindows should always only be managed by this file
  3460. // Sometimes we want to track when a UI window we don't control is opened/closed
  3461. // We use these methods to help facilitate that
  3462. // To use these methods correctly, you need to track when the window opens _and_ when it closes
  3463. // If you don't _need_ to do both those things, then don't do that, and don't use these methods
  3464.  
  3465.  
  3466. function setWindowOpen(windowName) {
  3467. const state = (0, _state.getState)();
  3468. state.openWindows[windowName] = true;
  3469. (0, _state.saveState)();
  3470. }
  3471.  
  3472. function setWindowClosed(windowName) {
  3473. const state = (0, _state.getState)();
  3474. state.openWindows[windowName] = false;
  3475. (0, _state.saveState)();
  3476. }
  3477.  
  3478. function isWindowOpen(windowName) {
  3479. const state = (0, _state.getState)();
  3480. return state.openWindows[windowName];
  3481. }
  3482.  
  3483. },{"./chat":33,"./misc":35,"./player":36,"./state":37}],39:[function(require,module,exports){
  3484. "use strict";
  3485.  
  3486. Object.defineProperty(exports, "__esModule", {
  3487. value: true
  3488. });
  3489. exports.VERSION = exports.BREAKING_VERSION = void 0;
  3490. // If this version is different from the user's stored state,
  3491. // e.g. they have upgraded the version of this script and there are breaking changes,
  3492. // then their stored state will be deleted.
  3493. const BREAKING_VERSION = 1; // Used for initialization message in chat, and userscript version
  3494.  
  3495. exports.BREAKING_VERSION = BREAKING_VERSION;
  3496. const VERSION = '1.2.6.1';
  3497. exports.VERSION = VERSION;
  3498.  
  3499. },{}]},{},[1]);