-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathamqChatTimestamps.user.js
More file actions
71 lines (63 loc) · 2.84 KB
/
amqChatTimestamps.user.js
File metadata and controls
71 lines (63 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// ==UserScript==
// @name AMQ Chat Timestamps
// @namespace https://github.com/TheJoseph98
// @version 1.5
// @description Adds timestamps to chat messages
// @author TheJoseph98
// @match https://animemusicquiz.com/*
// @grant none
// @require https://github.com/joske2865/AMQ-Scripts/raw/master/common/amqScriptInfo.js
// @downloadURL https://github.com/joske2865/AMQ-Scripts/raw/master/amqChatTimestamps.user.js
// @updateURL https://github.com/joske2865/AMQ-Scripts/raw/master/amqChatTimestamps.user.js
// ==/UserScript==
// Wait until the LOADING... screen is hidden and load script
if (typeof Listener === "undefined") return;
let loadInterval = setInterval(() => {
if ($("#loadingScreen").hasClass("hidden")) {
clearInterval(loadInterval);
setup();
}
}, 500);
const version = "1.5";
function setup() {
let gameChatNode = document.getElementById("gcMessageContainer");
let gameChatObserver = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (!mutation.addedNodes) return;
for (let i = 0; i < mutation.addedNodes.length; i++) {
let node = mutation.addedNodes[i];
if ($(node).hasClass("gcTimestamp")) return;
if ($(node).hasClass("ps__scrollbar-y-rail")) return;
if ($(node).hasClass("ps__scrollbar-x-rail")) return;
let d = new Date();
let mins = d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes();
let hours = d.getHours() < 10 ? "0" + d.getHours() : d.getHours();
let timeFormat = hours + ":" + mins;
if ($(node).find(".gcTeamMessageIcon").length === 1) {
$(node).find(".gcTeamMessageIcon").after($(`<span class="gcTimestamp" style="opacity: 0.5;">${timeFormat}</span>`));
}
else {
$(node).prepend($(`<span class="gcTimestamp" style="opacity: 0.5;">${timeFormat}</span>`));
}
// scroll to bottom
let chat = gameChat.$chatMessageContainer;
let atBottom = chat.scrollTop() + chat.innerHeight() >= chat[0].scrollHeight - 25;
if (atBottom) {
chat.scrollTop(chat.prop("scrollHeight"));
}
}
});
});
gameChatObserver.observe(gameChatNode, {
childList: true,
attributes: false,
CharacterData: false
});
AMQ_addScriptData({
name: "Chat Timestamps",
author: "TheJoseph98",
version: version,
link: "https://github.com/joske2865/AMQ-Scripts/raw/master/amqChatTimestamps.user.js",
description: `<p>Adds a timestamp to chat messages indicating when the message was sent, this is based on your local system time</p>`
});
}