|
6 | 6 | "chat",
|
7 | 7 | () => settings.pages.chat.tradeTimer,
|
8 | 8 | initialise,
|
9 |
| - detectChat, |
| 9 | + showTimer, |
10 | 10 | cleanup,
|
11 | 11 | {
|
12 | 12 | storage: ["settings.pages.chat.tradeTimer", "localdata.tradeMessage"],
|
|
18 | 18 | CUSTOM_LISTENERS[EVENT_CHANNELS.CHAT_OPENED].push(({ chat }) => {
|
19 | 19 | if (chat.find("[class*='chat-box-header__info__']").textContent !== "Trade") return;
|
20 | 20 |
|
21 |
| - listenTradeChatInput(chat); |
| 21 | + showTimer(chat); |
22 | 22 | });
|
23 | 23 | }
|
24 | 24 |
|
25 | 25 | let timer;
|
26 |
| - async function detectChat() { |
| 26 | + async function showTimer(tradeChat = null) { |
27 | 27 | await requireChatsLoaded();
|
28 | 28 |
|
29 |
| - const tradeChatButton = document.find("#chatRoot [class*='minimized-menu-item__'][title='Trade']"); |
30 |
| - if (!tradeChatButton) { |
31 |
| - console.error("TornTools - Trade Chat Button not found."); |
32 |
| - return; |
33 |
| - } |
| 29 | + if (!tradeChat) |
| 30 | + tradeChat = getTradeChat(); |
| 31 | + |
| 32 | + if (!tradeChat) return; |
| 33 | + |
| 34 | + const sendButton = tradeChat.find("[class*='chat-box-footer__send-icon-wrapper__']"); |
| 35 | + sendButton.parentElement.classList.add("tt-modified"); |
34 | 36 |
|
35 |
| - tradeChatButton.find("svg").classList.add("tt-hidden"); |
36 | 37 | if (!timer) {
|
37 | 38 | timer = document.newElement({
|
38 | 39 | type: "div",
|
|
43 | 44 | },
|
44 | 45 | });
|
45 | 46 | }
|
46 |
| - if (!countdownTimers.includes(timer)) countdownTimers.push(timer); |
| 47 | + countdownTimers = countdownTimers.filter((x) => x.getAttribute("id") !== "tt-trade-timer"); |
| 48 | + countdownTimers.push(timer); |
47 | 49 |
|
48 | 50 | const now = Date.now();
|
49 | 51 | if (localdata.tradeMessage > now) {
|
|
52 | 54 | } else {
|
53 | 55 | timer.textContent = "OK";
|
54 | 56 | }
|
55 |
| - tradeChatButton.appendChild(timer); |
56 | 57 |
|
57 |
| - listenTradeChatInput(); |
| 58 | + sendButton.insertAdjacentElement("afterbegin", timer); |
| 59 | + |
| 60 | + listenTradeChatInput(tradeChat); |
58 | 61 | }
|
59 | 62 |
|
60 | 63 | function getTradeChat() {
|
|
64 | 67 | return [...openChats].filter((chat) => chat.find("[class*='chat-box-header__info__']").textContent === "Trade")?.[0];
|
65 | 68 | }
|
66 | 69 |
|
67 |
| - function listenTradeChatInput(tradeChat = null) { |
| 70 | + function listenTradeChatInput(tradeChat) { |
68 | 71 | if (!tradeChat) tradeChat = getTradeChat();
|
69 | 72 | if (!tradeChat) return;
|
70 | 73 |
|
|
73 | 76 |
|
74 | 77 | async function onKeyUp(event) {
|
75 | 78 | if (event.key !== "Enter") return;
|
76 |
| - // if (!event.target.value) return; |
77 | 79 |
|
78 | 80 | const tradeChat = event.target.closest("[class^='chat-box__']");
|
79 | 81 | const chatBody = tradeChat.find("[class*='chat-box-body___']");
|
|
101 | 103 | timer.remove();
|
102 | 104 | timer = null;
|
103 | 105 |
|
104 |
| - const tradeChatButton = document.find("#chatRoot [class*='minimized-menu-item__'][title='Trade']"); |
105 |
| - if (tradeChatButton) tradeChatButton.find("svg").classList.remove("tt-hidden"); |
106 |
| - |
107 | 106 | const tradeChat = getTradeChat();
|
108 | 107 | if (!tradeChat) return;
|
109 | 108 |
|
| 109 | + tradeChat.find("[class*='chat-box-footer__send-icon-wrapper__']").parentElement.classList.remove("tt-modified"); |
| 110 | + |
110 | 111 | tradeChat.find("textarea").removeEventListener("keypress", onKeyUp);
|
111 | 112 | }
|
112 | 113 | })();
|
0 commit comments