Hordes UI Mod

Various UI mods for Hordes.io.

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

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