Hordes UI Mod

Various UI mods for Hordes.io.

目前为 2019-12-30 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Hordes UI Mod
  3. // @version 1.0.2
  4. // @description Various UI mods for Hordes.io.
  5. // @author Sakaiyo & Chandog#6373 & Cullen
  6. // @match https://hordes.io/play
  7. // @grant GM_addStyle
  8. // @namespace https://greasyfork.org/users/160017
  9. // ==/UserScript==
  10.  
  11. GM_addStyle(`/* Custom css for settings page, duplicates preexisting settings pane grid */
  12. .uimod-settings {
  13. display: grid;
  14. grid-template-columns: 2fr 3fr;
  15. grid-gap: 8px;
  16. align-items: center;
  17. max-height: 390px;
  18. margin: 0 20px;
  19. overflow-y: auto; }
  20. /* Custom chat context menu, invisible by default */
  21. .js-chat-context-menu {
  22. display: none; }
  23.  
  24. .js-chat-context-menu .name {
  25. color: white;
  26. padding: 2px 4px; }
  27.  
  28. /* Allow names in chat to be clicked (textf1 = BL, textf0 = VG) */
  29. #chat .name,
  30. .textwhisper .textf1,
  31. .textwhisper .textf0 {
  32. pointer-events: all !important; }
  33. /* Custom chat filter colors */
  34. .js-chat-gm {
  35. color: #a6dcd5; }
  36.  
  37. /* Class that hides chat lines */
  38. .js-line-hidden,
  39. .js-line-blocked {
  40. display: none; }
  41. /* Custom chat tabs */
  42. .uimod-chat-tabs {
  43. position: fixed;
  44. margin-top: -22px;
  45. left: 5px;
  46. pointer-events: all;
  47. color: #5b858e;
  48. font-size: 12px;
  49. font-weight: bold; }
  50.  
  51. .uimod-chat-tabs > div {
  52. cursor: pointer;
  53. background-color: rgba(0, 0, 0, 0.4);
  54. border-top-right-radius: 4px;
  55. border-top-left-radius: 4px;
  56. display: inline-block;
  57. border: 1px black solid;
  58. border-bottom: 0;
  59. margin-right: 2px;
  60. padding: 3px 5px; }
  61.  
  62. .uimod-chat-tabs > div:not(.js-selected-tab):hover {
  63. border-color: #aaa; }
  64.  
  65. .uimod-chat-tabs > .js-selected-tab {
  66. color: #fff; }
  67.  
  68. /* Chat tab custom config */
  69. .uimod-chat-tab-config {
  70. position: absolute;
  71. z-index: 9999999;
  72. background-color: rgba(0, 0, 0, 0.6);
  73. color: white;
  74. border-radius: 3px;
  75. text-align: center;
  76. padding: 8px 12px 8px 6px;
  77. width: 175px;
  78. font-size: 14px;
  79. border: 1px solid black;
  80. display: none; }
  81.  
  82. .uimod-chat-tab-config-grid {
  83. grid-template-columns: 35% 65%;
  84. display: grid;
  85. grid-gap: 6px;
  86. align-items: center; }
  87.  
  88. .uimod-chat-tab-config h1 {
  89. font-size: 16px;
  90. margin-top: 0; }
  91.  
  92. .uimod-chat-tab-config .btn,
  93. .uimod-chat-tab-config input {
  94. font-size: 12px; }
  95. /* Allows windows to be moved */
  96. .window {
  97. position: relative; }
  98.  
  99. /* All purpose hidden class */
  100. .js-hidden {
  101. display: none; }
  102. /* Friends list CSS, similar to settings but supports 4 columns */
  103. .uimod-friends {
  104. display: grid;
  105. grid-template-columns: 2fr 1.1fr 1.5fr 0.33fr 3fr;
  106. grid-gap: 8px;
  107. align-items: center;
  108. max-height: 390px;
  109. margin: 0 20px;
  110. overflow-y: auto; }
  111. .js-map-btns {
  112. position: absolute;
  113. top: 46px;
  114. right: 12px;
  115. z-index: 999;
  116. width: 100px;
  117. height: 100px;
  118. text-align: right;
  119. display: none;
  120. pointer-events: all; }
  121.  
  122. .js-map-btns:hover {
  123. display: block; }
  124.  
  125. .js-map-btns button {
  126. border-radius: 10px;
  127. font-size: 18px;
  128. padding: 0 5px;
  129. background: rgba(0, 0, 0, 0.4);
  130. border: 0;
  131. color: white;
  132. font-weight: bold;
  133. cursor: pointer; }
  134.  
  135. /* On hover of map, show opacity controls */
  136. .js-map:hover .js-map-btns {
  137. display: block; }
  138. .js-chat-resize {
  139. resize: both;
  140. overflow: auto; }
  141. .js-map {
  142. /* This makes sure scroll bars don't appear when resizing the map */
  143. overflow: hidden; }
  144.  
  145. .js-map-resize:hover {
  146. resize: both;
  147. overflow: auto;
  148. direction: rtl; }
  149. /* Allows last clicked window to appear above all other windows */
  150. .js-is-top {
  151. z-index: 9998 !important; }
  152.  
  153. .panel.context:not(.commandlist) {
  154. z-index: 9999 !important; }
  155.  
  156. /* The item icon being dragged in the inventory */
  157. .container.svelte-120o2pb {
  158. z-index: 9999 !important; }
  159. .container.uimod-xpmeter-1 {
  160. z-index: 6; }
  161.  
  162. .window.uimod-xpmeter-2 {
  163. padding: 5px;
  164. height: 100%;
  165. display: grid;
  166. grid-template-rows: 30px 1fr;
  167. grid-gap: 4px;
  168. transform-origin: inherit;
  169. min-width: fit-content; }
  170.  
  171. .titleframe.uimod-xpmeter-2 {
  172. line-height: 1em;
  173. display: flex;
  174. align-items: center;
  175. position: relative;
  176. letter-spacing: 0.5px; }
  177.  
  178. .titleicon.uimod-xpmeter-2 {
  179. margin: 3px; }
  180.  
  181. .title.uimod-xpmeter-2 {
  182. width: 100%;
  183. padding-left: 4px;
  184. font-weight: bold; }
  185.  
  186. .slot.uimod-xpmeter-2 {
  187. min-height: 0; }
  188.  
  189. .wrapper.uimod-xpmeter-1 {
  190. width: 200px; }
  191.  
  192. .bar.uimod-xpmeter-3 {
  193. background-color: rgba(45, 66, 71, 0.7);
  194. border-radius: 1.5px;
  195. position: relative;
  196. color: #DAE8EA;
  197. overflow: hidden;
  198. text-shadow: 1px 1px 2px #10131d;
  199. white-space: nowrap;
  200. text-transform: capitalize;
  201. font-weight: bold; }
  202.  
  203. .buttons.uimod-xpmeter-1 {
  204. line-height: 1;
  205. font-size: 13px; }
  206.  
  207. .left.uimod-xpmeter-3 {
  208. padding-left: 4px;
  209. position: relative;
  210. z-index: 1; }
  211.  
  212. .right.uimod-xpmeter-3 {
  213. position: absolute;
  214. right: 7px;
  215. z-index: 1; }
  216. /* This file is for CSS mods that don't fit in any other individual mod folder */
  217. /* Transparent chat bg color */
  218. .frame.svelte-1vrlsr3 {
  219. background: rgba(0, 0, 0, 0.4); }
  220.  
  221. /* Our mod's chat message color */
  222. .textuimod {
  223. color: #00dd33; }
  224.  
  225. /* The browser resize icon */
  226. *::-webkit-resizer {
  227. background: linear-gradient(to right, rgba(51, 77, 80, 0), rgba(203, 202, 165, 0.5));
  228. border-radius: 8px;
  229. box-shadow: 0 1px 1px black; }
  230.  
  231. *::-moz-resizer {
  232. background: linear-gradient(to right, rgba(51, 77, 80, 0), rgba(203, 202, 165, 0.5));
  233. border-radius: 8px;
  234. box-shadow: 0 1px 1px black; }
  235.  
  236. /* Our custom window, closely mirrors main settings window */
  237. .uimod-custom-window {
  238. position: absolute;
  239. top: 100px;
  240. left: 50%;
  241. transform: translate(-50%, 0);
  242. min-width: 350px;
  243. max-width: 600px;
  244. width: 90%;
  245. height: 80%;
  246. min-height: 350px;
  247. max-height: 500px;
  248. z-index: 9;
  249. padding: 0px 10px 5px; }
  250. `);
  251.  
  252. (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){
  253. "use strict";
  254.  
  255. var _mods = _interopRequireDefault(require("./mods"));
  256.  
  257. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  258.  
  259. // Add new DOM, load our stored state, wire it up, then continuously rerun specific methods whenever UI changes
  260. function initialize() {
  261. // If the Hordes.io tab isn't active for long enough, it reloads the entire page, clearing this mod
  262. // We check for that and reinitialize the mod if that happens
  263. const $layout = document.querySelector('.layout');
  264.  
  265. if ($layout.classList.contains('uimod-initd')) {
  266. return;
  267. }
  268.  
  269. $layout.classList.add('uimod-initd');
  270. const rerunning = {
  271. // MutationObserver running whenever .layout changes
  272. onDomChange: [],
  273. // Mutation observer running whenever #chat changes
  274. onChatChange: [],
  275. // `click` Event listener running on document.body
  276. onPageClick: []
  277. }; // Run all our mods
  278.  
  279. const registerOnDomChange = callback => rerunning.onDomChange.push(callback);
  280.  
  281. const registerOnChatChange = callback => rerunning.onChatChange.push(callback);
  282.  
  283. const registerOnPageClick = callback => rerunning.onPageClick.push(callback);
  284.  
  285. _mods.default.forEach(mod => {
  286. mod.run({
  287. registerOnDomChange,
  288. registerOnChatChange,
  289. registerOnPageClick
  290. });
  291. }); // Continuously re-run specific mods methods that need to be executed on UI change
  292.  
  293.  
  294. const rerunObserver = new MutationObserver(() => {
  295. // If new window appears, e.g. even if window is closed and reopened, we need to rewire it
  296. // Fun fact: Some windows always exist in the DOM, even when hidden, e.g. Inventory
  297. // But some windows only exist in the DOM when open, e.g. Interaction
  298. rerunning.onDomChange.forEach(callback => callback());
  299. });
  300. rerunObserver.observe(document.querySelector('.layout > .container'), {
  301. attributes: false,
  302. childList: true
  303. }); // Rerun only on chat messages changing
  304.  
  305. const chatRerunObserver = new MutationObserver(() => {
  306. rerunning.onChatChange.forEach(callback => callback());
  307. });
  308. chatRerunObserver.observe(document.querySelector('#chat'), {
  309. attributes: false,
  310. childList: true
  311. }); // Event listeners for document.body might be kept when the game reloads, so don't reinitialize them
  312.  
  313. if (!document.body.classList.contains('js-uimod-initd')) {
  314. document.body.classList.add('js-uimod-initd');
  315. rerunning.onPageClick.forEach(callback => document.body.addEventListener('click', callback));
  316. }
  317. } // Initialize mods once UI DOM has loaded
  318.  
  319.  
  320. const pageObserver = new MutationObserver(() => {
  321. const isUiLoaded = !!document.querySelector('.layout');
  322.  
  323. if (isUiLoaded) {
  324. initialize();
  325. }
  326. });
  327. pageObserver.observe(document.body, {
  328. attributes: true,
  329. childList: true
  330. });
  331.  
  332. },{"./mods":12}],2:[function(require,module,exports){
  333. "use strict";
  334.  
  335. Object.defineProperty(exports, "__esModule", {
  336. value: true
  337. });
  338. exports.default = void 0;
  339.  
  340. var chat = _interopRequireWildcard(require("../../utils/chat"));
  341.  
  342. var _version = require("../../utils/version");
  343.  
  344. var _state = require("../../utils/state");
  345.  
  346. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  347.  
  348. 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; }
  349.  
  350. function modStart() {
  351. chat.addChatMessage(`Hordes UI Mod v${_version.VERSION} is now running.`);
  352. (0, _state.loadState)();
  353. }
  354.  
  355. var _default = {
  356. name: '[REQUIRED] UI Mod Startup',
  357. description: 'Do not remove this! This handles some initial mod loading, including loading saved state.',
  358. run: modStart
  359. };
  360. exports.default = _default;
  361.  
  362. },{"../../utils/chat":21,"../../utils/state":24,"../../utils/version":25}],3:[function(require,module,exports){
  363. "use strict";
  364.  
  365. Object.defineProperty(exports, "__esModule", {
  366. value: true
  367. });
  368. exports.default = void 0;
  369.  
  370. var _state = require("../../utils/state");
  371.  
  372. var _misc = require("../../utils/misc");
  373.  
  374. var player = _interopRequireWildcard(require("../../utils/player"));
  375.  
  376. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  377.  
  378. 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; }
  379.  
  380. function blockedPlayerSettings() {
  381. const state = (0, _state.getState)();
  382. const $settings = document.querySelector('.divide:not(.js-settings-initd)');
  383.  
  384. if (!$settings) {
  385. return;
  386. }
  387.  
  388. $settings.classList.add('js-settings-initd');
  389. const $settingsChoiceList = $settings.querySelector('.choice').parentNode;
  390. $settingsChoiceList.appendChild((0, _misc.makeElement)({
  391. element: 'div',
  392. class: 'choice js-blocked-players',
  393. content: 'Blocked players'
  394. })); // Upon click, we display our custom settings window UI
  395.  
  396. document.querySelector('.js-blocked-players').addEventListener('click', () => {
  397. let blockedPlayersHTML = '';
  398. Object.keys(state.blockList).sort().forEach(blockedName => {
  399. blockedPlayersHTML += `
  400. <div data-player-name="${blockedName}">${blockedName}</div>
  401. <div class="btn orange js-unblock-player" data-player-name="${blockedName}">Unblock player</div>
  402. `;
  403. });
  404. const customSettingsHTML = `
  405. <h3 class="textprimary">Blocked players</h3>
  406. <div class="settings uimod-settings">${blockedPlayersHTML}</div>
  407. <p></p>
  408. <div class="btn purp js-close-custom-settings">Close</div>
  409. `;
  410. const $customSettings = (0, _misc.makeElement)({
  411. element: 'div',
  412. class: 'menu panel-black js-custom-settings uimod-custom-window',
  413. content: customSettingsHTML
  414. });
  415. document.body.appendChild($customSettings); // Wire up all the unblock buttons
  416.  
  417. Array.from(document.querySelectorAll('.js-unblock-player')).forEach($button => {
  418. $button.addEventListener('click', clickEvent => {
  419. const name = clickEvent.target.getAttribute('data-player-name');
  420. player.unblockPlayer(name); // Remove the blocked player from the list
  421.  
  422. Array.from(document.querySelectorAll(`.js-custom-settings [data-player-name="${name}"]`)).forEach($element => {
  423. $element.parentNode.removeChild($element);
  424. });
  425. });
  426. }); // And the close button for our custom UI
  427.  
  428. document.querySelector('.js-close-custom-settings').addEventListener('click', () => {
  429. const $customSettingsWindow = document.querySelector('.js-custom-settings');
  430. $customSettingsWindow.parentNode.removeChild($customSettingsWindow);
  431. });
  432. });
  433. }
  434.  
  435. var _default = {
  436. name: 'Blocked Players List',
  437. description: 'Allows you to view and remove blocked players from the Settings window',
  438. run: ({
  439. registerOnDomChange
  440. }) => {
  441. blockedPlayerSettings(); // If the settings window becomes visible/invisible, we want to update it
  442.  
  443. registerOnDomChange(blockedPlayerSettings);
  444. }
  445. };
  446. exports.default = _default;
  447.  
  448. },{"../../utils/misc":22,"../../utils/player":23,"../../utils/state":24}],4:[function(require,module,exports){
  449. "use strict";
  450.  
  451. Object.defineProperty(exports, "__esModule", {
  452. value: true
  453. });
  454. exports.showChatContextMenu = showChatContextMenu;
  455.  
  456. var _state = require("../../utils/state");
  457.  
  458. // Makes chat context menu visible and appear under the mouse
  459. function showChatContextMenu(name, mousePos) {
  460. const state = (0, _state.getState)(); // Right before we show the context menu, we want to handle showing/hiding Friend/Unfriend
  461.  
  462. const $contextMenu = document.querySelector('.js-chat-context-menu');
  463. $contextMenu.querySelector('[name="friend"]').classList.toggle('js-hidden', !!state.friendsList[name]);
  464. $contextMenu.querySelector('[name="unfriend"]').classList.toggle('js-hidden', !state.friendsList[name]);
  465. $contextMenu.querySelector('.js-name').textContent = name;
  466. $contextMenu.setAttribute('style', `display: block; left: ${mousePos.x}px; top: ${mousePos.y}px;`);
  467. }
  468.  
  469. },{"../../utils/state":24}],5:[function(require,module,exports){
  470. "use strict";
  471.  
  472. Object.defineProperty(exports, "__esModule", {
  473. value: true
  474. });
  475. exports.default = void 0;
  476.  
  477. var _state = require("../../utils/state");
  478.  
  479. var _misc = require("../../utils/misc");
  480.  
  481. var helpers = _interopRequireWildcard(require("./helpers"));
  482.  
  483. var chat = _interopRequireWildcard(require("../../utils/chat"));
  484.  
  485. var player = _interopRequireWildcard(require("../../utils/player"));
  486.  
  487. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  488.  
  489. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  490.  
  491. // This creates the initial chat context menu DOM (which starts as hidden)
  492. function createChatContextMenu() {
  493. const tempState = (0, _state.getTempState)();
  494.  
  495. if (document.querySelector('.js-chat-context-menu')) {
  496. return;
  497. }
  498.  
  499. let contextMenuHTML = `
  500. <div class="js-name">...</div>
  501. <div class="choice" name="party">Party invite</div>
  502. <div class="choice" name="whisper">Whisper</div>
  503. <div class="choice" name="friend">Friend</div>
  504. <div class="choice" name="unfriend">Unfriend</div>
  505. <div class="choice" name="copy">Copy name</div>
  506. <div class="choice" name="block">Block</div>
  507. `;
  508. document.body.appendChild((0, _misc.makeElement)({
  509. element: 'div',
  510. class: 'panel context border grey js-chat-context-menu',
  511. content: contextMenuHTML
  512. }));
  513. const $chatContextMenu = document.querySelector('.js-chat-context-menu');
  514. $chatContextMenu.querySelector('[name="party"]').addEventListener('click', () => {
  515. chat.partyPlayer(tempState.chatName);
  516. });
  517. $chatContextMenu.querySelector('[name="whisper"]').addEventListener('click', () => {
  518. chat.whisperPlayer(tempState.chatName);
  519. });
  520. $chatContextMenu.querySelector('[name="friend"]').addEventListener('click', () => {
  521. player.friendPlayer(tempState.chatName);
  522. });
  523. $chatContextMenu.querySelector('[name="unfriend"]').addEventListener('click', () => {
  524. player.unfriendPlayer(tempState.chatName);
  525. });
  526. $chatContextMenu.querySelector('[name="copy"]').addEventListener('click', () => {
  527. navigator.clipboard.writeText(tempState.chatName);
  528. });
  529. $chatContextMenu.querySelector('[name="block"]').addEventListener('click', () => {
  530. player.blockPlayer(tempState.chatName);
  531. });
  532. } // This opens a context menu when you click a user's name in chat
  533.  
  534.  
  535. function chatContextMenu() {
  536. const tempState = (0, _state.getTempState)();
  537.  
  538. const addContextMenu = ($name, name) => {
  539. $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
  540.  
  541. $name.setAttribute('data-chat-name', name);
  542.  
  543. const showContextMenu = clickEvent => {
  544. // TODO: Is there a way to pass the name to showChatContextMenumethod, instead of storing in tempState?
  545. tempState.chatName = name;
  546. helpers.showChatContextMenu(name, {
  547. x: clickEvent.pageX,
  548. y: clickEvent.pageY
  549. });
  550. };
  551.  
  552. $name.addEventListener('click', showContextMenu); // Left click
  553.  
  554. $name.addEventListener('contextmenu', showContextMenu); // Right click works too
  555. };
  556.  
  557. Array.from(document.querySelectorAll('#chat .name:not(.js-is-context-menu-initd)')).forEach($name => {
  558. addContextMenu($name, $name.textContent);
  559. }); // `textf0` is the VG faction, `textf1` is the BL faction - we want to support both with our whisper context menu
  560.  
  561. Array.from(document.querySelectorAll('.textwhisper .textf1:not(.js-is-context-menu-initd), .textwhisper .textf0:not(.js-is-context-menu-initd)')).forEach($whisperName => {
  562. // $whisperName's textContent is "to [name]" or "from [name]", so we cut off the first word
  563. let name = $whisperName.textContent.split(' ');
  564. name.shift(); // Remove the first word
  565.  
  566. name = name.join(' ');
  567. addContextMenu($whisperName, name);
  568. });
  569. } // Close chat context menu if clicking outside of it
  570.  
  571.  
  572. function closeChatContextMenu(clickEvent) {
  573. const $target = clickEvent.target; // If clicking on name or directly on context menu, don't close it
  574. // Still closes if clicking on context menu item
  575.  
  576. if ($target.classList.contains('js-is-context-menu-initd') || $target.classList.contains('js-chat-context-menu')) {
  577. return;
  578. }
  579.  
  580. const $contextMenu = document.querySelector('.js-chat-context-menu');
  581. $contextMenu.style.display = 'none';
  582. }
  583.  
  584. var _default = {
  585. name: 'Chat Context Menu',
  586. description: 'Displays a menu when you click on a player, allowing you to whisper/party/friend/block them',
  587. run: ({
  588. registerOnPageClick,
  589. registerOnChatChange
  590. }) => {
  591. createChatContextMenu();
  592. chatContextMenu(); // When we click anywhere on the page outside of our chat context menu, we want to close the menu
  593.  
  594. registerOnPageClick(closeChatContextMenu); // Register event listeners for each name when a new chat message appears
  595.  
  596. registerOnChatChange(chatContextMenu);
  597. }
  598. };
  599. exports.default = _default;
  600.  
  601. },{"../../utils/chat":21,"../../utils/misc":22,"../../utils/player":23,"../../utils/state":24,"./helpers":4}],6:[function(require,module,exports){
  602. "use strict";
  603.  
  604. Object.defineProperty(exports, "__esModule", {
  605. value: true
  606. });
  607. exports.default = void 0;
  608.  
  609. var chat = _interopRequireWildcard(require("../../utils/chat"));
  610.  
  611. var _state = require("../../utils/state");
  612.  
  613. var _misc = require("../../utils/misc");
  614.  
  615. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  616.  
  617. 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; }
  618.  
  619. // Creates DOM elements for custom chat filters
  620. function newChatFilters() {
  621. const state = (0, _state.getState)();
  622. const $channelselect = document.querySelector('.channelselect');
  623.  
  624. if (!document.querySelector(`.js-chat-gm`)) {
  625. const $gm = (0, _misc.makeElement)({
  626. element: 'small',
  627. class: `btn border black js-chat-gm ${state.chat.GM ? '' : 'textgrey'}`,
  628. content: 'GM'
  629. });
  630. $channelselect.appendChild($gm);
  631. }
  632. } // Wire up new chat buttons to toggle in state+ui
  633.  
  634.  
  635. function newChatFilterButtons() {
  636. const state = (0, _state.getState)();
  637. const $chatGM = document.querySelector(`.js-chat-gm`);
  638. $chatGM.addEventListener('click', () => {
  639. chat.setGMChatVisibility(!state.chat.GM);
  640. });
  641. }
  642.  
  643. var _default = {
  644. name: 'Chat filters',
  645. description: 'Enables custom chat filters: GM chat',
  646. run: ({
  647. registerOnChatChange
  648. }) => {
  649. newChatFilters();
  650. newChatFilterButtons(); // Whenever chat changes, we want to filter it
  651.  
  652. registerOnChatChange(chat.filterAllChat);
  653. }
  654. };
  655. exports.default = _default;
  656.  
  657. },{"../../utils/chat":21,"../../utils/misc":22,"../../utils/state":24}],7:[function(require,module,exports){
  658. "use strict";
  659.  
  660. Object.defineProperty(exports, "__esModule", {
  661. value: true
  662. });
  663. exports.showChatTabConfigWindow = showChatTabConfigWindow;
  664. exports.addChatTab = addChatTab;
  665. exports.selectChatTab = selectChatTab;
  666. exports.getCurrentChatFilters = getCurrentChatFilters;
  667.  
  668. var chat = _interopRequireWildcard(require("../../utils/chat"));
  669.  
  670. var _state = require("../../utils/state");
  671.  
  672. var _misc = require("../../utils/misc");
  673.  
  674. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  675.  
  676. 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; }
  677.  
  678. const DEFAULT_CHAT_TAB_NAME = 'Untitled'; // Gets current chat filters as represented in the UI
  679. // filter being true means it's invisible(filtered) in chat
  680. // filter being false means it's visible(unfiltered) in chat
  681.  
  682. function getCurrentChatFilters() {
  683. const state = (0, _state.getState)(); // Saved by the official game client
  684.  
  685. const gameFilters = JSON.parse(localStorage.getItem('filteredChannels'));
  686. return {
  687. global: gameFilters.includes('global'),
  688. faction: gameFilters.includes('faction'),
  689. party: gameFilters.includes('party'),
  690. clan: gameFilters.includes('clan'),
  691. pvp: gameFilters.includes('pvp'),
  692. inv: gameFilters.includes('inv'),
  693. 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
  694.  
  695. };
  696. } // Shows the chat tab config window for a specific tab, displayed in a specific position
  697.  
  698.  
  699. function showChatTabConfigWindow(tabId, pos) {
  700. const state = (0, _state.getState)();
  701. const tempState = getTempState();
  702. const $chatTabConfig = document.querySelector('.js-chat-tab-config');
  703. const chatTab = state.chatTabs.find(tab => tab.id === tabId); // Update position and name in chat tab config
  704.  
  705. $chatTabConfig.style.left = `${pos.x}px`;
  706. $chatTabConfig.style.top = `${pos.y}px`;
  707. $chatTabConfig.querySelector('.js-chat-tab-name').value = chatTab.name; // Store tabId in state, to be used by the Remove/Add buttons in config window
  708.  
  709. tempState.editedChatTabId = tabId; // Hide remove button if only one chat tab left - can't remove last one
  710. // Show it if more than one chat tab left
  711.  
  712. const chatTabCount = Object.keys(state.chatTabs).length;
  713. const $removeChatTabBtn = $chatTabConfig.querySelector('.js-remove-chat-tab');
  714. $removeChatTabBtn.style.display = chatTabCount < 2 ? 'none' : 'block'; // Show chat tab config
  715.  
  716. $chatTabConfig.style.display = 'block';
  717. } // Adds chat tab to DOM, sets it as selected
  718. // If argument chatTab is provided, will use that name+id
  719. // If no argument is provided, will create new tab name/id and add it to state
  720. // isInittingTab is optional boolean, if `true`, will _not_ set added tab as selected. Used when initializing all chat tabs on load
  721. // Returns newly added tabId
  722.  
  723.  
  724. function addChatTab(chatTab, isInittingTab) {
  725. const state = (0, _state.getState)();
  726. let tabName = DEFAULT_CHAT_TAB_NAME;
  727. let tabId = (0, _misc.uuid)();
  728.  
  729. if (chatTab) {
  730. tabName = chatTab.name;
  731. tabId = chatTab.id;
  732. } else {
  733. // If no chat tab was provided, create it in state
  734. state.chatTabs.push({
  735. name: tabName,
  736. id: tabId,
  737. filters: getCurrentChatFilters()
  738. });
  739. (0, _state.saveState)();
  740. }
  741.  
  742. const $tabs = document.querySelector('.js-chat-tabs');
  743. const $tab = (0, _misc.makeElement)({
  744. element: 'div',
  745. content: tabName
  746. });
  747. $tab.setAttribute('data-tab-id', tabId); // Add chat tab to DOM
  748.  
  749. $tabs.appendChild($tab); // Wire chat tab up to open config on right click
  750.  
  751. $tab.addEventListener('contextmenu', clickEvent => {
  752. const mousePos = {
  753. x: clickEvent.pageX,
  754. y: clickEvent.pageY
  755. };
  756. showChatTabConfigWindow(tabId, mousePos);
  757. }); // And select chat tab on left click
  758.  
  759. $tab.addEventListener('click', () => {
  760. selectChatTab(tabId);
  761. });
  762.  
  763. if (!isInittingTab) {
  764. // Select the newly added chat tab
  765. selectChatTab(tabId);
  766. } // Returning tabId to all adding new tab to pass tab ID to `showChatTabConfigWindow`
  767.  
  768.  
  769. return tabId;
  770. } // Selects chat tab [on click], updating client chat filters and custom chat filters
  771.  
  772.  
  773. function selectChatTab(tabId) {
  774. const state = (0, _state.getState)(); // Remove selected class from everything, then add selected class to clicked tab
  775.  
  776. Array.from(document.querySelectorAll('[data-tab-id]')).forEach($tab => {
  777. $tab.classList.remove('js-selected-tab');
  778. });
  779. const $tab = document.querySelector(`[data-tab-id="${tabId}"]`);
  780. $tab.classList.add('js-selected-tab');
  781. const tabFilters = state.chatTabs.find(tab => tab.id === tabId).filters; // Simulating clicks on the filters to turn them on/off
  782.  
  783. const $filterButtons = Array.from(document.querySelectorAll('.channelselect small'));
  784. Object.keys(tabFilters).forEach(filter => {
  785. const $filterButton = $filterButtons.find($btn => $btn.textContent === filter);
  786. const isCurrentlyFiltered = $filterButton.classList.contains('textgrey'); // If is currently filtered but filter for this tab is turned off, click it to turn filter off
  787.  
  788. if (isCurrentlyFiltered && !tabFilters[filter]) {
  789. $filterButton.click();
  790. } // If it is not currently filtered but filter for this tab is turned on, click it to turn filter on
  791.  
  792.  
  793. if (!isCurrentlyFiltered && tabFilters[filter]) {
  794. $filterButton.click();
  795. }
  796. }); // Update state for our custom chat filters to match the tab's configuration, then filter chat for it
  797.  
  798. const isGMChatVisible = !tabFilters.GM;
  799. chat.setGMChatVisibility(isGMChatVisible); // Update the selected tab in state
  800.  
  801. state.selectedChatTabId = tabId;
  802. (0, _state.saveState)();
  803. }
  804.  
  805. },{"../../utils/chat":21,"../../utils/misc":22,"../../utils/state":24}],8:[function(require,module,exports){
  806. "use strict";
  807.  
  808. Object.defineProperty(exports, "__esModule", {
  809. value: true
  810. });
  811. exports.default = void 0;
  812.  
  813. var helpers = _interopRequireWildcard(require("./helpers"));
  814.  
  815. var _state = require("../../utils/state");
  816.  
  817. var _misc = require("../../utils/misc");
  818.  
  819. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  820.  
  821. 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; }
  822.  
  823. // Creates DOM elements and wires them up for custom chat tabs and chat tab config
  824. // Note: Should be done after creating new custom chat filters
  825. function customChatTabs() {
  826. const state = (0, _state.getState)();
  827. const tempState = (0, _state.getTempState)(); // Create the chat tab configuration DOM
  828.  
  829. const $chatTabConfigurator = (0, _misc.makeElement)({
  830. element: 'div',
  831. class: 'uimod-chat-tab-config js-chat-tab-config',
  832. content: `
  833. <h1>Chat Tab Config</h1>
  834. <div class="uimod-chat-tab-config-grid">
  835. <div>Name</div><input type="text" class="js-chat-tab-name" value="untitled"></input>
  836. <div class="btn orange js-remove-chat-tab">Remove</div><div class="btn blue js-save-chat-tab">Ok</div>
  837. </div>
  838. `
  839. });
  840. document.body.append($chatTabConfigurator); // Wire it up
  841.  
  842. document.querySelector('.js-remove-chat-tab').addEventListener('click', () => {
  843. // Remove the chat tab from state
  844. const editedChatTab = state.chatTabs.find(tab => tab.id === tempState.editedChatTabId);
  845. const editedChatTabIndex = state.chatTabs.indexOf(editedChatTab);
  846. state.chatTabs.splice(editedChatTabIndex, 1); // Remove the chat tab from DOM
  847.  
  848. const $chatTab = document.querySelector(`[data-tab-id="${tempState.editedChatTabId}"]`);
  849. $chatTab.parentNode.removeChild($chatTab); // If we just removed the currently selected chat tab
  850.  
  851. if (tempState.editedChatTabId === state.selectedChatTabId) {
  852. // Select the chat tab to the left of the removed one
  853. const nextChatTabIndex = editedChatTabIndex === 0 ? 0 : editedChatTabIndex - 1;
  854. helpers.selectChatTab(state.chatTabs[nextChatTabIndex].id);
  855. } // Close chat tab config
  856.  
  857.  
  858. document.querySelector('.js-chat-tab-config').style.display = 'none';
  859. });
  860. document.querySelector('.js-save-chat-tab').addEventListener('click', () => {
  861. // Set new chat tab name in DOM
  862. const $chatTab = document.querySelector(`[data-tab-id="${state.selectedChatTabId}"]`);
  863. const newName = document.querySelector('.js-chat-tab-name').value;
  864. $chatTab.textContent = newName; // Set new chat tab name in state
  865. // `selectedChatTab` is a reference on `state.chatTabs`, so updating it above still updates it in the state - we want to save that
  866.  
  867. const selectedChatTab = state.chatTabs.find(tab => tab.id === state.selectedChatTabId);
  868. selectedChatTab.name = newName;
  869. (0, _state.saveState)(); // Close chat tab config
  870.  
  871. document.querySelector('.js-chat-tab-config').style.display = 'none';
  872. }); // Create the initial chat tabs HTML
  873.  
  874. const $chat = document.querySelector('#chat');
  875. const $chatTabs = (0, _misc.makeElement)({
  876. element: 'div',
  877. class: 'uimod-chat-tabs js-chat-tabs',
  878. content: '<div class="js-chat-tab-add">+</div>'
  879. }); // Add them to the DOM
  880.  
  881. $chat.parentNode.insertBefore($chatTabs, $chat); // Add all our chat tabs from state
  882.  
  883. state.chatTabs.forEach(chatTab => {
  884. const isInittingTab = true;
  885. helpers.addChatTab(chatTab, isInittingTab);
  886. }); // Wire up the add chat tab button
  887.  
  888. document.querySelector('.js-chat-tab-add').addEventListener('click', clickEvent => {
  889. const chatTabId = helpers.addChatTab();
  890. const mousePos = {
  891. x: clickEvent.pageX,
  892. y: clickEvent.pageY
  893. };
  894. helpers.showChatTabConfigWindow(chatTabId, mousePos);
  895. }); // If initial chat tab doesn't exist, create it based off current filter settings
  896.  
  897. if (!Object.keys(state.chatTabs).length) {
  898. const tabId = (0, _misc.uuid)();
  899. const chatTab = {
  900. name: 'Main',
  901. id: tabId,
  902. filters: helpers.getCurrentChatFilters()
  903. };
  904. state.chatTabs.push(chatTab);
  905. (0, _state.saveState)();
  906. helpers.addChatTab(chatTab);
  907. } // Wire up click event handlers onto the filters to update the selected chat tab's filters in state
  908.  
  909.  
  910. document.querySelector('.channelselect').addEventListener('click', clickEvent => {
  911. const $elementMouseIsOver = document.elementFromPoint(clickEvent.clientX, clickEvent.clientY); // We only want to change the filters if the user manually clicks the filter button
  912. // If they clicked a chat tab and we programatically set filters, we don't want to update
  913. // the current tab's filter state
  914.  
  915. if (!$elementMouseIsOver.classList.contains('btn')) {
  916. return;
  917. }
  918.  
  919. const selectedChatTab = state.chatTabs.find(tab => tab.id === state.selectedChatTabId);
  920. selectedChatTab.filters = helpers.getCurrentChatFilters();
  921. (0, _state.saveState)();
  922. }); // Select the currently selected tab in state on mod initialization
  923.  
  924. if (state.selectedChatTabId) {
  925. helpers.selectChatTab(state.selectedChatTabId);
  926. }
  927. }
  928.  
  929. var _default = {
  930. name: 'Chat tabs',
  931. description: 'Enables support for multiple chat tabs',
  932. run: customChatTabs
  933. };
  934. exports.default = _default;
  935.  
  936. },{"../../utils/misc":22,"../../utils/state":24,"./helpers":7}],9:[function(require,module,exports){
  937. "use strict";
  938.  
  939. Object.defineProperty(exports, "__esModule", {
  940. value: true
  941. });
  942. exports.dragElement = dragElement;
  943.  
  944. // Credit: https://stackoverflow.com/a/14234618 (Has been slightly modified)
  945. // $draggedElement is the item that will be dragged.
  946. // $dragTrigger is the element that must be held down to drag $draggedElement
  947. function dragElement($draggedElement, $dragTrigger) {
  948. let offset = [0, 0];
  949. let isDown = false;
  950. $dragTrigger.addEventListener('mousedown', function (e) {
  951. isDown = true;
  952. offset = [$draggedElement.offsetLeft - e.clientX, $draggedElement.offsetTop - e.clientY];
  953. }, true);
  954. document.addEventListener('mouseup', function () {
  955. isDown = false;
  956. }, true);
  957. document.addEventListener('mousemove', function (e) {
  958. event.preventDefault();
  959.  
  960. if (isDown) {
  961. $draggedElement.style.left = e.clientX + offset[0] + 'px';
  962. $draggedElement.style.top = e.clientY + offset[1] + 'px';
  963. }
  964. }, true);
  965. }
  966.  
  967. },{}],10:[function(require,module,exports){
  968. "use strict";
  969.  
  970. Object.defineProperty(exports, "__esModule", {
  971. value: true
  972. });
  973. exports.default = void 0;
  974.  
  975. var helpers = _interopRequireWildcard(require("./helpers"));
  976.  
  977. var _state = require("../../utils/state");
  978.  
  979. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  980.  
  981. 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; }
  982.  
  983. // Drag all windows by their header
  984. function draggableUIWindows() {
  985. Array.from(document.querySelectorAll('.window:not(.js-can-move)')).forEach($window => {
  986. $window.classList.add('js-can-move');
  987. helpers.dragElement($window, $window.querySelector('.titleframe'));
  988. });
  989. } // Save dragged UI windows position to state
  990.  
  991.  
  992. function saveDraggedUIWindows() {
  993. const state = (0, _state.getState)();
  994. Array.from(document.querySelectorAll('.window:not(.js-window-is-saving)')).forEach($window => {
  995. $window.classList.add('js-window-is-saving');
  996. const $draggableTarget = $window.querySelector('.titleframe');
  997. const windowName = $draggableTarget.querySelector('[name="title"]').textContent;
  998. $draggableTarget.addEventListener('mouseup', () => {
  999. state.windowsPos[windowName] = $window.getAttribute('style');
  1000. (0, _state.saveState)();
  1001. });
  1002. });
  1003. } // Loads draggable UI windows position from state
  1004.  
  1005.  
  1006. function loadDraggedUIWindowsPositions() {
  1007. const state = (0, _state.getState)();
  1008. Array.from(document.querySelectorAll('.window:not(.js-has-loaded-pos)')).forEach($window => {
  1009. $window.classList.add('js-has-loaded-pos');
  1010. const windowName = $window.querySelector('[name="title"]').textContent;
  1011. const pos = state.windowsPos[windowName];
  1012.  
  1013. if (pos) {
  1014. $window.setAttribute('style', pos);
  1015. }
  1016. });
  1017. }
  1018.  
  1019. var _default = {
  1020. name: 'Draggable Windows',
  1021. description: 'Allows you to drag windows in the UI',
  1022. run: ({
  1023. registerOnDomChange
  1024. }) => {
  1025. draggableUIWindows();
  1026. saveDraggedUIWindows();
  1027. loadDraggedUIWindowsPositions(); // As windows open, we want to make them draggable
  1028.  
  1029. registerOnDomChange(saveDraggedUIWindows);
  1030. registerOnDomChange(draggableUIWindows);
  1031. registerOnDomChange(loadDraggedUIWindowsPositions);
  1032. }
  1033. };
  1034. exports.default = _default;
  1035.  
  1036. },{"../../utils/state":24,"./helpers":9}],11:[function(require,module,exports){
  1037. "use strict";
  1038.  
  1039. Object.defineProperty(exports, "__esModule", {
  1040. value: true
  1041. });
  1042. exports.default = void 0;
  1043.  
  1044. var _state = require("../../utils/state");
  1045.  
  1046. var player = _interopRequireWildcard(require("../../utils/player"));
  1047.  
  1048. var _misc = require("../../utils/misc");
  1049.  
  1050. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  1051.  
  1052. 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; }
  1053.  
  1054. // The F icon and the UI that appears when you click it
  1055. function customFriendsList() {
  1056. const state = (0, _state.getState)();
  1057. var friendsIconElement = (0, _misc.makeElement)({
  1058. element: 'div',
  1059. class: 'btn border black js-friends-list-icon',
  1060. content: 'F'
  1061. }); // Add the icon to the right of Elixir icon
  1062.  
  1063. const $elixirIcon = document.querySelector('#sysgem');
  1064. $elixirIcon.parentNode.insertBefore(friendsIconElement, $elixirIcon.nextSibling); // Create the friends list UI
  1065.  
  1066. document.querySelector('.js-friends-list-icon').addEventListener('click', () => {
  1067. if (document.querySelector('.js-friends-list')) {
  1068. // Don't open the friends list twice.
  1069. return;
  1070. }
  1071.  
  1072. let friendsListHTML = '';
  1073. Object.keys(state.friendsList).sort().forEach(friendName => {
  1074. friendsListHTML += `
  1075. <div data-player-name="${friendName}">${friendName}</div>
  1076. <div class="btn blue js-whisper-player" data-player-name="${friendName}">Whisper</div>
  1077. <div class="btn blue js-party-player" data-player-name="${friendName}">Party invite</div>
  1078. <div class="btn orange js-unfriend-player" data-player-name="${friendName}">X</div>
  1079. <input type="text" class="js-friend-note" data-player-name="${friendName}" value="${state.friendNotes[friendName] || ''}"></input>
  1080. `;
  1081. });
  1082. const customFriendsWindowHTML = `
  1083. <h3 class="textprimary">Friends list</h3>
  1084. <div class="uimod-friends">${friendsListHTML}</div>
  1085. <p></p>
  1086. <div class="btn purp js-close-custom-friends-list">Close</div>
  1087. `;
  1088. const $customFriendsList = (0, _misc.makeElement)({
  1089. element: 'div',
  1090. class: 'menu panel-black js-friends-list uimod-custom-window',
  1091. content: customFriendsWindowHTML
  1092. });
  1093. document.body.appendChild($customFriendsList); // Wire up the buttons
  1094.  
  1095. Array.from(document.querySelectorAll('.js-whisper-player')).forEach($button => {
  1096. $button.addEventListener('click', clickEvent => {
  1097. const name = clickEvent.target.getAttribute('data-player-name');
  1098. player.whisperPlayer(name);
  1099. });
  1100. });
  1101. Array.from(document.querySelectorAll('.js-party-player')).forEach($button => {
  1102. $button.addEventListener('click', clickEvent => {
  1103. const name = clickEvent.target.getAttribute('data-player-name');
  1104. player.partyPlayer(name);
  1105. });
  1106. });
  1107. Array.from(document.querySelectorAll('.js-unfriend-player')).forEach($button => {
  1108. $button.addEventListener('click', clickEvent => {
  1109. const name = clickEvent.target.getAttribute('data-player-name');
  1110. player.unfriendPlayer(name); // Remove the blocked player from the list
  1111.  
  1112. Array.from(document.querySelectorAll(`.js-friends-list [data-player-name="${name}"]`)).forEach($element => {
  1113. $element.parentNode.removeChild($element);
  1114. });
  1115. });
  1116. });
  1117. Array.from(document.querySelectorAll('.js-friend-note')).forEach($element => {
  1118. $element.addEventListener('change', clickEvent => {
  1119. const name = clickEvent.target.getAttribute('data-player-name');
  1120. state.friendNotes[name] = clickEvent.target.value;
  1121. });
  1122. }); // The close button for our custom UI
  1123.  
  1124. document.querySelector('.js-close-custom-friends-list').addEventListener('click', () => {
  1125. const $friendsListWindow = document.querySelector('.js-friends-list');
  1126. $friendsListWindow.parentNode.removeChild($friendsListWindow);
  1127. });
  1128. });
  1129. }
  1130.  
  1131. var _default = {
  1132. name: 'Friends list',
  1133. description: 'Allows access to your friends list from the top right F icon',
  1134. run: customFriendsList
  1135. };
  1136. exports.default = _default;
  1137.  
  1138. },{"../../utils/misc":22,"../../utils/player":23,"../../utils/state":24}],12:[function(require,module,exports){
  1139. "use strict";
  1140.  
  1141. Object.defineProperty(exports, "__esModule", {
  1142. value: true
  1143. });
  1144. exports.default = void 0;
  1145.  
  1146. var _modStart = _interopRequireDefault(require("./_modStart"));
  1147.  
  1148. var _blockedPlayerSettings = _interopRequireDefault(require("./blockedPlayerSettings"));
  1149.  
  1150. var _chatContextMenu = _interopRequireDefault(require("./chatContextMenu"));
  1151.  
  1152. var _chatFilters = _interopRequireDefault(require("./chatFilters"));
  1153.  
  1154. var _chatTabs = _interopRequireDefault(require("./chatTabs"));
  1155.  
  1156. var _draggableUI = _interopRequireDefault(require("./draggableUI"));
  1157.  
  1158. var _friendsList = _interopRequireDefault(require("./friendsList"));
  1159.  
  1160. var _mapControls = _interopRequireDefault(require("./mapControls"));
  1161.  
  1162. var _resizableChat = _interopRequireDefault(require("./resizableChat"));
  1163.  
  1164. var _resizableMap = _interopRequireDefault(require("./resizableMap"));
  1165.  
  1166. var _selectedWindowIsTop = _interopRequireDefault(require("./selectedWindowIsTop"));
  1167.  
  1168. var _xpMeter = _interopRequireDefault(require("./xpMeter"));
  1169.  
  1170. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1171.  
  1172. // TODO: Get /cssMods/styles.scss somehow, maybe create index.js with imported css file? Maybe separate default styles.scss outside of mods?
  1173. // The array here dictates the order of which mods are executed, from top to bottom
  1174. var _default = [_modStart.default, _resizableMap.default, _mapControls.default, _friendsList.default, _blockedPlayerSettings.default, _resizableChat.default, _chatFilters.default, _chatContextMenu.default, _chatTabs.default, _draggableUI.default, _selectedWindowIsTop.default, _xpMeter.default];
  1175. exports.default = _default;
  1176.  
  1177. },{"./_modStart":2,"./blockedPlayerSettings":3,"./chatContextMenu":5,"./chatFilters":6,"./chatTabs":8,"./draggableUI":10,"./friendsList":11,"./mapControls":14,"./resizableChat":15,"./resizableMap":17,"./selectedWindowIsTop":18,"./xpMeter":20}],13:[function(require,module,exports){
  1178. "use strict";
  1179.  
  1180. Object.defineProperty(exports, "__esModule", {
  1181. value: true
  1182. });
  1183. exports.updateMapOpacity = updateMapOpacity;
  1184.  
  1185. var _state = require("../../utils/state");
  1186.  
  1187. // On load, update map opacity to match state
  1188. // We modify the opacity of the canvas and the background color alpha of the parent container
  1189. // We do this to allow our opacity buttons to be visible on hover with 100% opacity
  1190. // (A surprisingly difficult enough task to require this implementation)
  1191. function updateMapOpacity() {
  1192. const state = (0, _state.getState)();
  1193. const $map = document.querySelector('.container canvas');
  1194. const $mapContainer = document.querySelector('.js-map');
  1195. $map.style.opacity = String(state.mapOpacity / 100);
  1196. 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
  1197.  
  1198. let opacity = state.mapOpacity / 100; // This is a slightly lazy browser workaround to fix a bug.
  1199. // If the opacity is `1`, and it sets `rgba` to `1`, then the browser changes the
  1200. // rgba to rgb, dropping the alpha. We could account for that and add the `alpha` back in
  1201. // later, but setting the max opacity to very close to 1 makes sure the issue never crops up.
  1202. // Fun fact: 0.99 retains the alpha, but setting this to 0.999 still causes the browser to drop the alpha. Rude.
  1203.  
  1204. if (opacity === 1) {
  1205. opacity = 0.99;
  1206. }
  1207.  
  1208. const newBgColor = mapContainerBgColor.replace(/[\d\.]+\)$/g, `${opacity})`);
  1209. $mapContainer.style['background-color'] = newBgColor; // Update the button opacity
  1210.  
  1211. const $addBtn = document.querySelector('.js-map-opacity-add');
  1212. const $minusBtn = document.querySelector('.js-map-opacity-minus'); // Hide plus button if the opacity is max
  1213.  
  1214. if (state.mapOpacity === 100) {
  1215. $addBtn.style.visibility = 'hidden';
  1216. } else {
  1217. $addBtn.style.visibility = 'visible';
  1218. } // Hide minus button if the opacity is lowest
  1219.  
  1220.  
  1221. if (state.mapOpacity === 0) {
  1222. $minusBtn.style.visibility = 'hidden';
  1223. } else {
  1224. $minusBtn.style.visibility = 'visible';
  1225. }
  1226. }
  1227.  
  1228. },{"../../utils/state":24}],14:[function(require,module,exports){
  1229. "use strict";
  1230.  
  1231. Object.defineProperty(exports, "__esModule", {
  1232. value: true
  1233. });
  1234. exports.default = void 0;
  1235.  
  1236. var _state = require("../../utils/state");
  1237.  
  1238. var helpers = _interopRequireWildcard(require("./helpers"));
  1239.  
  1240. var _misc = require("../../utils/misc");
  1241.  
  1242. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  1243.  
  1244. 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; }
  1245.  
  1246. function mapControls() {
  1247. const state = (0, _state.getState)();
  1248. const $map = document.querySelector('.container canvas');
  1249.  
  1250. if (!$map.parentNode.classList.contains('js-map')) {
  1251. $map.parentNode.classList.add('js-map');
  1252. }
  1253.  
  1254. const $mapContainer = document.querySelector('.js-map');
  1255. const $mapButtons = (0, _misc.makeElement)({
  1256. element: 'div',
  1257. class: 'js-map-btns',
  1258. content: `
  1259. <button class="js-map-opacity-add">+</button>
  1260. <button class="js-map-opacity-minus">-</button>
  1261. <button class="js-map-reset">r</button>
  1262. `
  1263. }); // Add it right before the map container div
  1264.  
  1265. $map.parentNode.insertBefore($mapButtons, $map);
  1266. helpers.updateMapOpacity();
  1267. const $addBtn = document.querySelector('.js-map-opacity-add');
  1268. const $minusBtn = document.querySelector('.js-map-opacity-minus');
  1269. const $resetBtn = document.querySelector('.js-map-reset'); // Hide the buttons if map opacity is maxed/minimum
  1270.  
  1271. if (state.mapOpacity === 100) {
  1272. $addBtn.style.visibility = 'hidden';
  1273. }
  1274.  
  1275. if (state.mapOpacity === 0) {
  1276. $minusBtn.style.visibility = 'hidden';
  1277. } // Wire it up
  1278.  
  1279.  
  1280. $addBtn.addEventListener('click', clickEvent => {
  1281. // Update opacity
  1282. state.mapOpacity += 10;
  1283. (0, _state.saveState)();
  1284. helpers.updateMapOpacity();
  1285. });
  1286. $minusBtn.addEventListener('click', clickEvent => {
  1287. // Update opacity
  1288. state.mapOpacity -= 10;
  1289. (0, _state.saveState)();
  1290. helpers.updateMapOpacity();
  1291. });
  1292. $resetBtn.addEventListener('click', clickEvent => {
  1293. state.mapOpacity = 70;
  1294. state.mapWidth = '174px';
  1295. state.mapHeight = '174px';
  1296. (0, _state.saveState)();
  1297. helpers.updateMapOpacity();
  1298. $mapContainer.style.width = state.mapWidth;
  1299. $mapContainer.style.height = state.mapHeight;
  1300. });
  1301. helpers.updateMapOpacity();
  1302. }
  1303.  
  1304. var _default = {
  1305. name: 'Map controls',
  1306. 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',
  1307. run: mapControls
  1308. };
  1309. exports.default = _default;
  1310.  
  1311. },{"../../utils/misc":22,"../../utils/state":24,"./helpers":13}],15:[function(require,module,exports){
  1312. "use strict";
  1313.  
  1314. Object.defineProperty(exports, "__esModule", {
  1315. value: true
  1316. });
  1317. exports.default = void 0;
  1318.  
  1319. var _state = require("../../utils/state");
  1320.  
  1321. function resizableChat() {
  1322. const state = (0, _state.getState)(); // Add the appropriate classes
  1323.  
  1324. const $chatContainer = document.querySelector('#chat').parentNode;
  1325. $chatContainer.classList.add('js-chat-resize'); // Load initial chat and map size
  1326.  
  1327. if (state.chatWidth && state.chatHeight) {
  1328. $chatContainer.style.width = state.chatWidth;
  1329. $chatContainer.style.height = state.chatHeight;
  1330. } // Save chat size on resize
  1331.  
  1332.  
  1333. const resizeObserverChat = new ResizeObserver(() => {
  1334. const chatWidthStr = window.getComputedStyle($chatContainer, null).getPropertyValue('width');
  1335. const chatHeightStr = window.getComputedStyle($chatContainer, null).getPropertyValue('height');
  1336. state.chatWidth = chatWidthStr;
  1337. state.chatHeight = chatHeightStr;
  1338. (0, _state.saveState)();
  1339. });
  1340. resizeObserverChat.observe($chatContainer);
  1341. }
  1342.  
  1343. var _default = {
  1344. name: 'Resizable chat',
  1345. description: 'Allows you to resize chat by clicking and dragging from the bottom right of chat',
  1346. run: resizableChat
  1347. };
  1348. exports.default = _default;
  1349.  
  1350. },{"../../utils/state":24}],16:[function(require,module,exports){
  1351. "use strict";
  1352.  
  1353. Object.defineProperty(exports, "__esModule", {
  1354. value: true
  1355. });
  1356. exports.onMapResize = onMapResize;
  1357. exports.triggerMapResize = triggerMapResize;
  1358.  
  1359. var _state = require("../../utils/state");
  1360.  
  1361. // When the map container resizes, we want to update the canvas width/height and the state
  1362. function onMapResize(e) {
  1363. if (!document.querySelector('.layout')) {
  1364. return;
  1365. }
  1366.  
  1367. const state = (0, _state.getState)();
  1368. const tempState = (0, _state.getTempState)();
  1369. const $map = document.querySelector('.container canvas').parentNode;
  1370. const $canvas = $map.querySelector('canvas'); // Get real values of map height/width, excluding padding/margin/etc
  1371.  
  1372. const mapWidthStr = window.getComputedStyle($map, null).getPropertyValue('width');
  1373. const mapHeightStr = window.getComputedStyle($map, null).getPropertyValue('height');
  1374. const mapWidth = Number(mapWidthStr.slice(0, -2));
  1375. const mapHeight = Number(mapHeightStr.slice(0, -2)); // If height/width are 0 or unset, don't resize canvas
  1376.  
  1377. if (!mapWidth || !mapHeight) {
  1378. return;
  1379. }
  1380.  
  1381. if ($canvas.width !== mapWidth) {
  1382. $canvas.width = mapWidth;
  1383. }
  1384.  
  1385. if ($canvas.height !== mapHeight) {
  1386. $canvas.height = mapHeight;
  1387. } // If we're clicking map, i.e. manually resizing, then save state
  1388. // Don't save state when minimizing/maximizing map via [M]
  1389.  
  1390.  
  1391. if (tempState.clickingMap) {
  1392. state.mapWidth = mapWidthStr;
  1393. state.mapHeight = mapHeightStr;
  1394. (0, _state.saveState)();
  1395. } else {
  1396. const isMaximized = mapWidth > tempState.lastMapWidth && mapHeight > tempState.lastMapHeight;
  1397.  
  1398. if (!isMaximized) {
  1399. $map.style.width = state.mapWidth;
  1400. $map.style.height = state.mapHeight;
  1401. }
  1402. } // Store last map width/height in temp state, so we know if we've minimized or maximized
  1403.  
  1404.  
  1405. tempState.lastMapWidth = mapWidth;
  1406. tempState.lastMapHeight = mapHeight;
  1407. } // We need to observe canvas resizes to tell when the user presses M to open the big map
  1408. // At that point, we resize the map to match the canvas
  1409.  
  1410.  
  1411. function triggerMapResize() {
  1412. if (!document.querySelector('.layout')) {
  1413. return;
  1414. }
  1415.  
  1416. const $map = document.querySelector('.container canvas').parentNode;
  1417. const $canvas = $map.querySelector('canvas'); // Get real values of map height/width, excluding padding/margin/etc
  1418.  
  1419. const mapWidthStr = window.getComputedStyle($map, null).getPropertyValue('width');
  1420. const mapHeightStr = window.getComputedStyle($map, null).getPropertyValue('height');
  1421. const mapWidth = Number(mapWidthStr.slice(0, -2));
  1422. const mapHeight = Number(mapHeightStr.slice(0, -2)); // If height/width are 0 or unset, we don't care about resizing yet
  1423.  
  1424. if (!mapWidth || !mapHeight) {
  1425. return;
  1426. }
  1427.  
  1428. if ($canvas.width !== mapWidth) {
  1429. $map.style.width = `${$canvas.width}px`;
  1430. }
  1431.  
  1432. if ($canvas.height !== mapHeight) {
  1433. $map.style.height = `${$canvas.height}px`;
  1434. }
  1435. }
  1436.  
  1437. },{"../../utils/state":24}],17:[function(require,module,exports){
  1438. "use strict";
  1439.  
  1440. Object.defineProperty(exports, "__esModule", {
  1441. value: true
  1442. });
  1443. exports.default = void 0;
  1444.  
  1445. var _state = require("../../utils/state");
  1446.  
  1447. var helpers = _interopRequireWildcard(require("./helpers"));
  1448.  
  1449. var _misc = require("../../utils/misc");
  1450.  
  1451. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  1452.  
  1453. 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; }
  1454.  
  1455. function resizableMap() {
  1456. const state = (0, _state.getState)();
  1457. const tempState = (0, _state.getTempState)();
  1458. const $map = document.querySelector('.container canvas').parentNode;
  1459. const $canvas = $map.querySelector('canvas');
  1460. $map.classList.add('js-map-resize'); // Track whether we're clicking (resizing) map or not
  1461. // Used to detect if resize changes are manually done, or from minimizing/maximizing map (with [M])
  1462.  
  1463. $map.addEventListener('mousedown', () => {
  1464. tempState.clickingMap = true;
  1465. }); // Sometimes the mouseup event may be registered outside of the map - we account for this
  1466.  
  1467. document.body.addEventListener('mouseup', () => {
  1468. tempState.clickingMap = false;
  1469. });
  1470.  
  1471. if (state.mapWidth && state.mapHeight) {
  1472. $map.style.width = state.mapWidth;
  1473. $map.style.height = state.mapHeight;
  1474. helpers.onMapResize(); // Update canvas size on initial load of saved map size
  1475. } // On resize of map, resize canvas to match
  1476. // Debouncing allows map to be visible while resizing
  1477.  
  1478.  
  1479. const debouncedMapResize = (0, _misc.debounce)(helpers.onMapResize, 1);
  1480. const resizeObserverMap = new ResizeObserver(debouncedMapResize);
  1481. helpers.onMapResize();
  1482. resizeObserverMap.observe($map); // We debounce the canvas resize, so it doesn't resize every single
  1483. // pixel you move when resizing the DOM. If this were to happen,
  1484. // resizing would constantly be interrupted. You'd have to resize a tiny bit,
  1485. // lift left click, left click again to resize a tiny bit more, etc.
  1486. // Resizing is smooth when we debounce this canvas.
  1487.  
  1488. const debouncedTriggerResize = (0, _misc.debounce)(helpers.triggerMapResize, 50);
  1489. const resizeObserverCanvas = new ResizeObserver(debouncedTriggerResize);
  1490. resizeObserverCanvas.observe($canvas);
  1491. }
  1492.  
  1493. var _default = {
  1494. name: 'Resizable map',
  1495. description: 'Allows you to resize the map by clicking and dragging from the bottom left',
  1496. run: resizableMap
  1497. };
  1498. exports.default = _default;
  1499.  
  1500. },{"../../utils/misc":22,"../../utils/state":24,"./helpers":16}],18:[function(require,module,exports){
  1501. "use strict";
  1502.  
  1503. Object.defineProperty(exports, "__esModule", {
  1504. value: true
  1505. });
  1506. exports.default = void 0;
  1507.  
  1508. // The last clicked UI window displays above all other UI windows
  1509. // This is useful when, for example, your inventory is near the market window,
  1510. // and you want the window and the tooltips to display above the market window.
  1511. function selectedWindowIsTop() {
  1512. Array.from(document.querySelectorAll('.window:not(.js-is-top-initd)')).forEach($window => {
  1513. $window.classList.add('js-is-top-initd');
  1514. $window.addEventListener('mousedown', () => {
  1515. // First, make the other is-top window not is-top
  1516. const $otherWindowContainer = document.querySelector('.js-is-top');
  1517.  
  1518. if ($otherWindowContainer) {
  1519. $otherWindowContainer.classList.remove('js-is-top');
  1520. } // Then, make our window's container (the z-index container) is-top
  1521.  
  1522.  
  1523. $window.parentNode.classList.add('js-is-top');
  1524. });
  1525. });
  1526. }
  1527.  
  1528. var _default = {
  1529. name: 'Make Selected Window Top',
  1530. description: 'The UI window you click will always be displayed over other UI windows',
  1531. run: ({
  1532. registerOnDomChange
  1533. }) => {
  1534. selectedWindowIsTop(); // As windows are opened, we want to enable them to become the top window when they're clicked
  1535.  
  1536. registerOnDomChange(selectedWindowIsTop);
  1537. }
  1538. };
  1539. exports.default = _default;
  1540.  
  1541. },{}],19:[function(require,module,exports){
  1542. "use strict";
  1543.  
  1544. Object.defineProperty(exports, "__esModule", {
  1545. value: true
  1546. });
  1547. exports.getCurrentCharacterLvl = getCurrentCharacterLvl;
  1548. exports.getCurrentXp = getCurrentXp;
  1549. exports.getNextLevelXp = getNextLevelXp;
  1550. exports.resetXpMeterState = resetXpMeterState;
  1551. exports.toggleXpMeterVisibility = toggleXpMeterVisibility;
  1552. exports.msToString = msToString;
  1553.  
  1554. var _state = require("../../utils/state");
  1555.  
  1556. function getCurrentCharacterLvl() {
  1557. return Number(document.querySelector('#ufplayer .bgmana > .left').textContent.split('Lv. ')[1]);
  1558. }
  1559.  
  1560. function getCurrentXp() {
  1561. return Number(document.querySelector('#expbar .progressBar > .left').textContent.split('/')[0].trim());
  1562. }
  1563.  
  1564. function getNextLevelXp() {
  1565. return Number(document.querySelector('#expbar .progressBar > .left').textContent.split('/')[1].trim());
  1566. } // user invoked reset of xp meter stats
  1567.  
  1568.  
  1569. function resetXpMeterState() {
  1570. const state = (0, _state.getState)();
  1571. state.xpMeterState.xpGains = []; // array of xp deltas every second
  1572.  
  1573. state.xpMeterState.averageXp = 0;
  1574. state.xpMeterState.gainedXp = 0;
  1575. (0, _state.saveState)();
  1576. document.querySelector('.js-xp-time').textContent = '-:-:-';
  1577. } // toggle the xp meter
  1578.  
  1579.  
  1580. function toggleXpMeterVisibility() {
  1581. const xpMeterContainer = document.querySelector('.js-xpmeter');
  1582. xpMeterContainer.style.display = xpMeterContainer.style.display === 'none' ? 'block' : 'none';
  1583. }
  1584.  
  1585. function msToString(ms) {
  1586. const pad = value => value < 10 ? `0${value}` : value;
  1587.  
  1588. const hours = pad(Math.floor(ms / (1000 * 60 * 60) % 60));
  1589. const minutes = pad(Math.floor(ms / (1000 * 60) % 60));
  1590. const seconds = pad(Math.floor(ms / 1000 % 60));
  1591. return `${hours}:${minutes}:${seconds}`;
  1592. }
  1593.  
  1594. },{"../../utils/state":24}],20:[function(require,module,exports){
  1595. "use strict";
  1596.  
  1597. Object.defineProperty(exports, "__esModule", {
  1598. value: true
  1599. });
  1600. exports.default = void 0;
  1601.  
  1602. var _state = require("../../utils/state");
  1603.  
  1604. var helpers = _interopRequireWildcard(require("./helpers"));
  1605.  
  1606. var _misc = require("../../utils/misc");
  1607.  
  1608. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  1609.  
  1610. 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; }
  1611.  
  1612. // Adds XP Meter DOM icon and window, starts continuous interval to get current xp over time
  1613. function xpMeter() {
  1614. const state = (0, _state.getState)();
  1615. const tempState = (0, _state.getTempState)();
  1616. const $layoutContainer = document.querySelector('body > div.layout > div.container:nth-child(1)');
  1617. const $dpsMeterToggleElement = document.querySelector('#systrophy');
  1618. const $xpMeterToggleElement = (0, _misc.makeElement)({
  1619. element: 'div',
  1620. class: 'js-sysxp js-xpmeter-icon btn border black',
  1621. content: 'XP'
  1622. });
  1623. const xpMeterHTMLString = `
  1624. <div class="l-corner-lr container uimod-xpmeter-1 js-xpmeter" style="display: none">
  1625. <div class="window panel-black uimod-xpmeter-2">
  1626. <div class="titleframe uimod-xpmeter-2">
  1627. <img src="/assets/ui/icons/trophy.svg?v=3282286" class="titleicon svgicon uimod-xpmeter-2">
  1628. <div class="textprimary title uimod-xpmeter-2">
  1629. <div name="title">Experience / XP</div>
  1630. </div>
  1631. <img src="/assets/ui/icons/cross.svg?v=3282286" class="js-xpmeter-close-icon btn black svgicon">
  1632. </div>
  1633. <div class="slot uimod-xpmeter-2" style="">
  1634. <div class="wrapper uimod-xpmeter-1">
  1635. <div class="bar uimod-xpmeter-3" style="z-index: 0;">
  1636. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  1637. <span class="left uimod-xpmeter-3">XP per minute:</span>
  1638. <span class="right uimod-xpmeter-3 js-xpm">-</span>
  1639. </div>
  1640. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  1641. <span class="left uimod-xpmeter-3">XP per hour:</span>
  1642. <span class="right uimod-xpmeter-3 js-xph">-</span>
  1643. </div>
  1644. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  1645. <span class="left uimod-xpmeter-3">XP Gained:</span>
  1646. <span class="right uimod-xpmeter-3 js-xpg">-</span>
  1647. </div>
  1648. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  1649. <span class="left uimod-xpmeter-3">XP Left:</span>
  1650. <span class="right uimod-xpmeter-3 js-xpl">-</span>
  1651. </div>
  1652. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  1653. <span class="left uimod-xpmeter-3">Session Time: </span>
  1654. <span class="right uimod-xpmeter-3 js-xp-s-time">-</span>
  1655. </div>
  1656. <div class="progressBar bgc1 uimod-xpmeter-3" style="width: 100%; font-size: 1em;">
  1657. <span class="left uimod-xpmeter-3">Time to lvl: </span>
  1658. <span class="right uimod-xpmeter-3 js-xp-time">-</span>
  1659. </div>
  1660. </div>
  1661. </div>
  1662. <div class="grid buttons marg-top uimod-xpmeter-1 js-xpmeter-reset-button">
  1663. <div class="btn grey">Reset</div>
  1664. </div>
  1665. </div>
  1666. </div>
  1667. </div>
  1668. `;
  1669. $dpsMeterToggleElement.parentNode.insertBefore($xpMeterToggleElement, $dpsMeterToggleElement.nextSibling);
  1670. const $xpMeterElement = (0, _misc.makeElement)({
  1671. element: 'div',
  1672. content: xpMeterHTMLString.trim()
  1673. });
  1674. $layoutContainer.appendChild($xpMeterElement.firstChild); // Wire up icon and xpmeter window
  1675.  
  1676. document.querySelector('.js-sysxp').addEventListener('click', helpers.toggleXpMeterVisibility);
  1677. document.querySelector('.js-xpmeter-close-icon').addEventListener('click', helpers.toggleXpMeterVisibility);
  1678. document.querySelector('.js-xpmeter-reset-button').addEventListener('click', helpers.resetXpMeterState);
  1679. state.xpMeterState.currentXp = helpers.getCurrentXp();
  1680. state.xpMeterState.currentLvl = helpers.getCurrentCharacterLvl();
  1681. (0, _state.saveState)();
  1682. if (tempState.xpMeterInterval) clearInterval(tempState.xpMeterInterval); // every second we run the operations for xp meter, update xps, calc delta, etc
  1683. // TODO Cleanup: This interval may not be cleaned up if the UI mod reinitializes,
  1684. // e.g. user is away from tab for a while then comes back
  1685. // Should confirm if this is an issue, and try to fix it if possible.
  1686.  
  1687. tempState.xpMeterInterval = setInterval(() => {
  1688. if (!document.querySelector('#expbar')) {
  1689. return;
  1690. }
  1691.  
  1692. const currentXp = helpers.getCurrentXp();
  1693. const nextLvlXp = helpers.getNextLevelXp();
  1694. const currentLvl = helpers.getCurrentCharacterLvl();
  1695. state.xpMeterState.gainedXp += currentXp - state.xpMeterState.currentXp;
  1696. state.xpMeterState.xpGains.push(currentXp - state.xpMeterState.currentXp); // array of xp deltas every second
  1697.  
  1698. state.xpMeterState.currentXp = currentXp;
  1699. state.xpMeterState.averageXp = state.xpMeterState.xpGains.reduce((a, b) => a + b) / state.xpMeterState.xpGains.length;
  1700. (0, _state.saveState)();
  1701.  
  1702. if (document.querySelector('.js-xpmeter')) {
  1703. document.querySelector('.js-xpm').textContent = parseInt((state.xpMeterState.averageXp * 60).toFixed(0)).toLocaleString();
  1704. document.querySelector('.js-xph').textContent = parseInt((state.xpMeterState.averageXp * 60 * 60).toFixed(0)).toLocaleString();
  1705. document.querySelector('.js-xpg').textContent = state.xpMeterState.gainedXp.toLocaleString();
  1706. document.querySelector('.js-xpl').textContent = (nextLvlXp - currentXp).toLocaleString();
  1707. document.querySelector('.js-xp-s-time').textContent = helpers.msToString(state.xpMeterState.xpGains.length * 1000); // need a positive integer for averageXp to calc time left
  1708.  
  1709. if (state.xpMeterState.averageXp > 0) document.querySelector('.js-xp-time').textContent = helpers.msToString((nextLvlXp - currentXp) / state.xpMeterState.averageXp * 1000);
  1710. }
  1711.  
  1712. if (state.xpMeterState.currentLvl < currentLvl) {
  1713. helpers.resetXpMeterState();
  1714. state.xpMeterState.currentLvl = currentLvl;
  1715. (0, _state.saveState)();
  1716. }
  1717. }, 1000);
  1718. }
  1719.  
  1720. var _default = {
  1721. name: 'XP Meter',
  1722. description: "Tracks your XP/minute and displays how much XP you're getting and lets you know how long until you level up",
  1723. run: xpMeter
  1724. };
  1725. exports.default = _default;
  1726.  
  1727. },{"../../utils/misc":22,"../../utils/state":24,"./helpers":19}],21:[function(require,module,exports){
  1728. "use strict";
  1729.  
  1730. Object.defineProperty(exports, "__esModule", {
  1731. value: true
  1732. });
  1733. exports.setGMChatVisibility = setGMChatVisibility;
  1734. exports.filterAllChat = filterAllChat;
  1735. exports.whisperPlayer = whisperPlayer;
  1736. exports.partyPlayer = partyPlayer;
  1737. exports.addChatMessage = addChatMessage;
  1738.  
  1739. var _state = require("./state");
  1740.  
  1741. var _misc = require("./misc");
  1742.  
  1743. // Updates state.chat.GM and the DOM to make text white/grey depending on if gm chat is visible/filtered
  1744. // Then filters chat and saves updated chat state
  1745. function setGMChatVisibility(isGMChatVisible) {
  1746. const state = (0, _state.getState)();
  1747. const $chatGM = document.querySelector(`.js-chat-gm`);
  1748. state.chat.GM = isGMChatVisible;
  1749. $chatGM.classList.toggle('textgrey', !state.chat.GM);
  1750. filterAllChat();
  1751. (0, _state.saveState)();
  1752. } // Filters all chat based on custom filters
  1753.  
  1754.  
  1755. function filterAllChat() {
  1756. const state = (0, _state.getState)(); // Blocked user filter
  1757.  
  1758. Object.keys(state.blockList).forEach(blockedName => {
  1759. // Get the `.name` elements from the blocked user, if we haven't already hidden their messages
  1760. const $blockedChatNames = Array.from(document.querySelectorAll(`[data-chat-name="${blockedName}"]:not(.js-line-blocked)`)); // Hide each of their messages
  1761.  
  1762. $blockedChatNames.forEach($name => {
  1763. // Add the class name to $name so we can track whether it's been hidden in our CSS selector $blockedChatNames
  1764. $name.classList.add('js-line-blocked');
  1765. const $line = $name.parentNode.parentNode.parentNode; // Add the class name to $line so we can visibly hide the entire chat line
  1766.  
  1767. $line.classList.add('js-line-blocked');
  1768. });
  1769. }); // Custom channel filter
  1770.  
  1771. Object.keys(state.chat).forEach(channel => {
  1772. Array.from(document.querySelectorAll(`.text${channel}.content`)).forEach($textItem => {
  1773. const $line = $textItem.parentNode.parentNode;
  1774. $line.classList.toggle('js-line-hidden', !state.chat[channel]);
  1775. });
  1776. });
  1777. }
  1778.  
  1779. function enterTextIntoChat(text) {
  1780. // Open chat input
  1781. const enterEvent = new KeyboardEvent('keydown', {
  1782. bubbles: true,
  1783. cancelable: true,
  1784. keyCode: 13
  1785. });
  1786. document.body.dispatchEvent(enterEvent); // Place text into chat
  1787.  
  1788. const $input = document.querySelector('#chatinput input');
  1789. $input.value = text; // Get chat input to recognize slash commands and change the channel
  1790. // by triggering the `input` event.
  1791. // (Did some debugging to figure out the channel only changes when the
  1792. // svelte `input` event listener exists.)
  1793.  
  1794. const inputEvent = new KeyboardEvent('input', {
  1795. bubbles: true,
  1796. cancelable: true
  1797. });
  1798. $input.dispatchEvent(inputEvent);
  1799. }
  1800.  
  1801. function submitChat() {
  1802. const $input = document.querySelector('#chatinput input');
  1803. const kbEvent = new KeyboardEvent('keydown', {
  1804. bubbles: true,
  1805. cancelable: true,
  1806. keyCode: 13
  1807. });
  1808. $input.dispatchEvent(kbEvent);
  1809. } // Automated chat command helpers
  1810. // (We've been OK'd to do these by the dev - all automation like this should receive approval from the dev)
  1811.  
  1812.  
  1813. function whisperPlayer(playerName) {
  1814. enterTextIntoChat(`/${playerName} `);
  1815. }
  1816.  
  1817. function partyPlayer(playerName) {
  1818. enterTextIntoChat(`/partyinvite ${playerName}`);
  1819. submitChat();
  1820. } // Pushes message to chat
  1821. // TODO: The margins for the message are off slightly compared to other messages - why?
  1822.  
  1823.  
  1824. function addChatMessage(text) {
  1825. const newMessageHTML = `
  1826. <div class="linewrap svelte-1vrlsr3">
  1827. <span class="time svelte-1vrlsr3">00.00</span>
  1828. <span class="textuimod content svelte-1vrlsr3">
  1829. <span class="capitalize channel svelte-1vrlsr3">UIMod</span>
  1830. </span>
  1831. <span class="svelte-1vrlsr3">${text}</span>
  1832. </div>
  1833. `;
  1834. const element = (0, _misc.makeElement)({
  1835. element: 'article',
  1836. class: 'line svelte-1vrlsr3',
  1837. content: newMessageHTML
  1838. });
  1839. document.querySelector('#chat').appendChild(element);
  1840. }
  1841.  
  1842. },{"./misc":22,"./state":24}],22:[function(require,module,exports){
  1843. "use strict";
  1844.  
  1845. Object.defineProperty(exports, "__esModule", {
  1846. value: true
  1847. });
  1848. exports.makeElement = makeElement;
  1849. exports.debounce = debounce;
  1850. exports.uuid = uuid;
  1851.  
  1852. // Nicer impl to create elements in one method call
  1853. function makeElement(args) {
  1854. const $node = document.createElement(args.element);
  1855.  
  1856. if (args.class) {
  1857. $node.className = args.class;
  1858. }
  1859.  
  1860. if (args.content) {
  1861. $node.innerHTML = args.content;
  1862. }
  1863.  
  1864. if (args.src) {
  1865. $node.src = args.src;
  1866. }
  1867.  
  1868. return $node;
  1869. } // Credit: David Walsh
  1870.  
  1871.  
  1872. function debounce(func, wait, immediate) {
  1873. var timeout;
  1874. return function () {
  1875. var context = this,
  1876. args = arguments;
  1877.  
  1878. var later = function () {
  1879. timeout = null;
  1880. if (!immediate) func.apply(context, args);
  1881. };
  1882.  
  1883. var callNow = immediate && !timeout;
  1884. clearTimeout(timeout);
  1885. timeout = setTimeout(later, wait);
  1886. if (callNow) func.apply(context, args);
  1887. };
  1888. } // Credit: https://gist.github.com/jcxplorer/823878
  1889. // Generate random UUID string
  1890.  
  1891.  
  1892. function uuid() {
  1893. var uuid = '',
  1894. i,
  1895. random;
  1896.  
  1897. for (i = 0; i < 32; i++) {
  1898. random = Math.random() * 16 | 0;
  1899.  
  1900. if (i == 8 || i == 12 || i == 16 || i == 20) {
  1901. uuid += '-';
  1902. }
  1903.  
  1904. uuid += (i == 12 ? 4 : i == 16 ? random & 3 | 8 : random).toString(16);
  1905. }
  1906.  
  1907. return uuid;
  1908. }
  1909.  
  1910. },{}],23:[function(require,module,exports){
  1911. "use strict";
  1912.  
  1913. Object.defineProperty(exports, "__esModule", {
  1914. value: true
  1915. });
  1916. exports.friendPlayer = friendPlayer;
  1917. exports.unfriendPlayer = unfriendPlayer;
  1918. exports.blockPlayer = blockPlayer;
  1919. exports.unblockPlayer = unblockPlayer;
  1920.  
  1921. var _state = require("./state");
  1922.  
  1923. var chat = _interopRequireWildcard(require("./chat"));
  1924.  
  1925. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  1926.  
  1927. 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; }
  1928.  
  1929. function friendPlayer(playerName) {
  1930. const state = (0, _state.getState)();
  1931.  
  1932. if (state.friendsList[playerName]) {
  1933. return;
  1934. }
  1935.  
  1936. state.friendsList[playerName] = true;
  1937. chat.addChatMessage(`${playerName} has been added to your friends list.`);
  1938. (0, _state.saveState)();
  1939. }
  1940.  
  1941. function unfriendPlayer(playerName) {
  1942. const state = (0, _state.getState)();
  1943.  
  1944. if (!state.friendsList[playerName]) {
  1945. return;
  1946. }
  1947.  
  1948. delete state.friendsList[playerName];
  1949. delete state.friendNotes[playerName];
  1950. chat.addChatMessage(`${playerName} is no longer on your friends list.`);
  1951. (0, _state.saveState)();
  1952. } // Adds player to block list, to be filtered out of chat
  1953.  
  1954.  
  1955. function blockPlayer(playerName) {
  1956. const state = (0, _state.getState)();
  1957.  
  1958. if (state.blockList[playerName]) {
  1959. return;
  1960. }
  1961.  
  1962. state.blockList[playerName] = true;
  1963. chat.filterAllChat();
  1964. chat.addChatMessage(`${playerName} has been blocked.`);
  1965. (0, _state.saveState)();
  1966. } // Removes player from block list and makes their messages visible again
  1967.  
  1968.  
  1969. function unblockPlayer(playerName) {
  1970. const state = (0, _state.getState)();
  1971. delete state.blockList[playerName];
  1972. chat.addChatMessage(`${playerName} has been unblocked.`);
  1973. (0, _state.saveState)(); // Make messages visible again
  1974.  
  1975. const $chatNames = Array.from(document.querySelectorAll(`.js-line-blocked[data-chat-name="${playerName}"]`));
  1976. $chatNames.forEach($name => {
  1977. $name.classList.remove('js-line-blocked');
  1978. const $line = $name.parentNode.parentNode.parentNode;
  1979. $line.classList.remove('js-line-blocked');
  1980. });
  1981. }
  1982.  
  1983. },{"./chat":21,"./state":24}],24:[function(require,module,exports){
  1984. "use strict";
  1985.  
  1986. Object.defineProperty(exports, "__esModule", {
  1987. value: true
  1988. });
  1989. exports.getState = getState;
  1990. exports.getTempState = getTempState;
  1991. exports.saveState = saveState;
  1992. exports.loadState = loadState;
  1993.  
  1994. var _version = require("./version");
  1995.  
  1996. const STORAGE_STATE_KEY = 'hordesio-uimodsakaiyo-state'; // Manually saved in local state
  1997.  
  1998. const state = {
  1999. breakingVersion: _version.BREAKING_VERSION,
  2000. chat: {
  2001. GM: true
  2002. },
  2003. windowsPos: {},
  2004. blockList: {},
  2005. friendsList: {},
  2006. mapOpacity: 70,
  2007. // e.g. 70 = opacity: 0.7
  2008. friendNotes: {},
  2009. chatTabs: [],
  2010. xpMeterState: {
  2011. currentXp: 0,
  2012. xpGains: [],
  2013. // array of xp deltas every second
  2014. averageXp: 0,
  2015. gainedXp: 0,
  2016. currentLvl: 0
  2017. }
  2018. }; // tempState is saved only between page refreshes.
  2019.  
  2020. const tempState = {
  2021. // The last name clicked in chat
  2022. chatName: null,
  2023. lastMapWidth: 0,
  2024. lastMapHeight: 0,
  2025. xpMeterInterval: null // tracks the interval for fetching xp data
  2026.  
  2027. };
  2028.  
  2029. function getState() {
  2030. return state;
  2031. }
  2032.  
  2033. function getTempState() {
  2034. return tempState;
  2035. }
  2036.  
  2037. function saveState() {
  2038. localStorage.setItem(STORAGE_STATE_KEY, JSON.stringify(state));
  2039. }
  2040.  
  2041. function loadState() {
  2042. const storedStateJson = localStorage.getItem(STORAGE_STATE_KEY);
  2043.  
  2044. if (storedStateJson) {
  2045. const storedState = JSON.parse(storedStateJson);
  2046.  
  2047. if (storedState.breakingVersion !== _version.BREAKING_VERSION) {
  2048. localStorage.setItem(STORAGE_STATE_KEY, JSON.stringify(state));
  2049. return;
  2050. }
  2051.  
  2052. for (let [key, value] of Object.entries(storedState)) {
  2053. state[key] = value;
  2054. }
  2055. }
  2056. }
  2057.  
  2058. },{"./version":25}],25:[function(require,module,exports){
  2059. "use strict";
  2060.  
  2061. Object.defineProperty(exports, "__esModule", {
  2062. value: true
  2063. });
  2064. exports.VERSION = exports.BREAKING_VERSION = void 0;
  2065. // If this version is different from the user's stored state,
  2066. // e.g. they have upgraded the version of this script and there are breaking changes,
  2067. // then their stored state will be deleted.
  2068. const BREAKING_VERSION = 1; // Used for initialization message in chat, and userscript version
  2069.  
  2070. exports.BREAKING_VERSION = BREAKING_VERSION;
  2071. const VERSION = '1.0.2';
  2072. exports.VERSION = VERSION;
  2073.  
  2074. },{}]},{},[1]);