Skip to content

Commit 5b61b1d

Browse files
committed
Change location of Trade Chat Timer.
1 parent f78160d commit 5b61b1d

File tree

6 files changed

+35
-23
lines changed

6 files changed

+35
-23
lines changed

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55
.vscode
66

77
extension/scripts/jshint.json
8-
extension/scripts/eslint.json
8+
extension/scripts/eslint.json
9+
.gitignore
10+
11+
extension/find.txt
12+
extension/find.txtf

extension/changelog.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"version": { "major": 6, "minor": 20, "build": 0 },
44
"title": "Beta",
55
"date": false,
6-
"logs": { "features": [], "fixes": [], "changes": [], "removed": [] }
6+
"logs": { "features": [], "fixes": [], "changes": [
7+
{ "message": "Change the location of Trade Chat Timer.", "contributor": "TheFoxMan" }
8+
], "removed": [] }
79
},
810
{
911
"version": { "major": 6, "minor": 19, "build": 0 },

extension/scripts/content/global/ttGlobal.entry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const countdownTimers = [];
3+
let countdownTimers = [];
44
const countTimers = [];
55

66
(async () => {

extension/scripts/features/trade-timer/ttTradeTimer.css

+5
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@
1717
#tt-trade-timer:not([data-seconds]) {
1818
background: var(--tt-color-green);
1919
}
20+
21+
[class*="chat-box-footer__"].tt-modified [class*="chat-box-footer__send-icon-wrapper__"] {
22+
display: flex;
23+
flex-flow: column;
24+
}

extension/scripts/features/trade-timer/ttTradeTimer.js

+18-17
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"chat",
77
() => settings.pages.chat.tradeTimer,
88
initialise,
9-
detectChat,
9+
showTimer,
1010
cleanup,
1111
{
1212
storage: ["settings.pages.chat.tradeTimer", "localdata.tradeMessage"],
@@ -18,21 +18,22 @@
1818
CUSTOM_LISTENERS[EVENT_CHANNELS.CHAT_OPENED].push(({ chat }) => {
1919
if (chat.find("[class*='chat-box-header__info__']").textContent !== "Trade") return;
2020

21-
listenTradeChatInput(chat);
21+
showTimer(chat);
2222
});
2323
}
2424

2525
let timer;
26-
async function detectChat() {
26+
async function showTimer(tradeChat = null) {
2727
await requireChatsLoaded();
2828

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");
3436

35-
tradeChatButton.find("svg").classList.add("tt-hidden");
3637
if (!timer) {
3738
timer = document.newElement({
3839
type: "div",
@@ -43,7 +44,8 @@
4344
},
4445
});
4546
}
46-
if (!countdownTimers.includes(timer)) countdownTimers.push(timer);
47+
countdownTimers = countdownTimers.filter((x) => x.getAttribute("id") !== "tt-trade-timer");
48+
countdownTimers.push(timer);
4749

4850
const now = Date.now();
4951
if (localdata.tradeMessage > now) {
@@ -52,9 +54,10 @@
5254
} else {
5355
timer.textContent = "OK";
5456
}
55-
tradeChatButton.appendChild(timer);
5657

57-
listenTradeChatInput();
58+
sendButton.insertAdjacentElement("afterbegin", timer);
59+
60+
listenTradeChatInput(tradeChat);
5861
}
5962

6063
function getTradeChat() {
@@ -64,7 +67,7 @@
6467
return [...openChats].filter((chat) => chat.find("[class*='chat-box-header__info__']").textContent === "Trade")?.[0];
6568
}
6669

67-
function listenTradeChatInput(tradeChat = null) {
70+
function listenTradeChatInput(tradeChat) {
6871
if (!tradeChat) tradeChat = getTradeChat();
6972
if (!tradeChat) return;
7073

@@ -73,7 +76,6 @@
7376

7477
async function onKeyUp(event) {
7578
if (event.key !== "Enter") return;
76-
// if (!event.target.value) return;
7779

7880
const tradeChat = event.target.closest("[class^='chat-box__']");
7981
const chatBody = tradeChat.find("[class*='chat-box-body___']");
@@ -101,12 +103,11 @@
101103
timer.remove();
102104
timer = null;
103105

104-
const tradeChatButton = document.find("#chatRoot [class*='minimized-menu-item__'][title='Trade']");
105-
if (tradeChatButton) tradeChatButton.find("svg").classList.remove("tt-hidden");
106-
107106
const tradeChat = getTradeChat();
108107
if (!tradeChat) return;
109108

109+
tradeChat.find("[class*='chat-box-footer__send-icon-wrapper__']").parentElement.classList.remove("tt-modified");
110+
110111
tradeChat.find("textarea").removeEventListener("keypress", onKeyUp);
111112
}
112113
})();

extension/scripts/global/functions/requires.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ function requireCondition(condition, options = {}) {
3737
if (options.maxCycles <= 0) return false;
3838

3939
if (count > options.maxCycles) {
40-
console.error("TornTools - Maximum cycles reached. Please report this to TornTools developers.");
41-
console.trace();
42-
reject("Maximum cycles reached.");
40+
// console.error("TornTools - Maximum cycles reached. Please report this to TornTools developers.");
41+
// console.trace();
42+
reject(new Error("Maximum cycles reached."));
4343
return true;
4444
}
4545
return false;

0 commit comments

Comments
 (0)