Hordes UI Mod

Various UI mods for Hordes.io.

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

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