Hordes UI Mod - Merchant List Filter ONLY

Various UI mods for Hordes.io.

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