Update CompleteTimestamps.plugin.js

This commit is contained in:
Mirco Wittrien 2022-10-28 13:21:33 +02:00
parent 44818f4e5f
commit 76af80c7ac
1 changed files with 55 additions and 79 deletions

View File

@ -2,7 +2,7 @@
* @name CompleteTimestamps
* @author DevilBro
* @authorId 278543574059057154
* @version 1.6.1
* @version 1.6.2
* @description Replaces Timestamps with your own custom Timestamps
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -57,11 +57,9 @@ module.exports = (_ => {
}
} : (([Plugin, BDFDB]) => {
var currentMode, tooltipIsSame;
var MessageTimestampComponent;
return class CompleteTimestamps extends Plugin {
onLoad () {
MessageTimestampComponent = (BDFDB.ModuleUtils.findByName("MessageTimestamp", false) || {exports: null}).exports;
this.defaults = {
general: {
@ -79,14 +77,12 @@ module.exports = (_ => {
}
};
this.patchedModules = {
after: {
Message: "default",
MessageTimestamp: "default",
Embed: "render",
SystemMessage: "default",
GuildSettingsAuditLogEntry: "render"
}
this.modulePatches = {
after: [
"AuditLogEntry",
"Embed",
"MessageTimestamp"
]
};
this.css = `
@ -170,13 +166,6 @@ module.exports = (_ => {
BDFDB.MessageUtils.rerenderAll();
}
processMessage (e) {
if (MessageTimestampComponent) {
let timestamp = BDFDB.ReactUtils.findChild(e.returnvalue, {filter: c => c && c.type && c.type.type && c.type.type.displayName == "MessageTimestamp"});
if (timestamp) timestamp.type.type = MessageTimestampComponent.default;
}
}
processMessageTimestamp (e) {
let tooltipWrapper = BDFDB.ReactUtils.findChild(e.returnvalue, {name: "Tooltip"});
if (!tooltipWrapper) return;
@ -202,51 +191,40 @@ module.exports = (_ => {
}
processEmbed (e) {
if (e.instance.props.embed && e.instance.props.embed.timestamp && this.settings.general.showInEmbed) {
let process = returnvalue => {
let [children, index] = BDFDB.ReactUtils.findParent(returnvalue, {props: [["className", BDFDB.disCN.embedfootertext]]});
if (index > -1) {
if (BDFDB.ArrayUtils.is(children[index].props.children)) children[index].props.children[children[index].props.children.length - 1] = this.formatTimestamp(this.settings.dates.timestampDate, e.instance.props.embed.timestamp._i);
else children[index].props.children = this.formatTimestamp(this.settings.dates.timestampDate, e.instance.props.embed.timestamp._i);
}
};
if (typeof e.returnvalue.props.children == "function") {
let childrenRender = e.returnvalue.props.children;
e.returnvalue.props.children = BDFDB.TimeUtils.suppress((...args) => {
let children = childrenRender(...args);
process(children);
return children;
}, "", this);
if (!this.settings.general.showInEmbed || !e.instance.props.embed || !e.instance.props.embed.timestamp) return;
let process = returnvalue => {
let [children, index] = BDFDB.ReactUtils.findParent(returnvalue, {props: [["className", BDFDB.disCN.embedfootertext]]});
if (index > -1) {
if (BDFDB.ArrayUtils.is(children[index].props.children)) children[index].props.children[children[index].props.children.length - 1] = this.formatTimestamp(this.settings.dates.timestampDate, e.instance.props.embed.timestamp._i);
else children[index].props.children = this.formatTimestamp(this.settings.dates.timestampDate, e.instance.props.embed.timestamp._i);
}
else process(e.returnvalue);
};
if (typeof e.returnvalue.props.children == "function") {
let childrenRender = e.returnvalue.props.children;
e.returnvalue.props.children = BDFDB.TimeUtils.suppress((...args) => {
let children = childrenRender(...args);
process(children);
return children;
}, "", this);
}
else process(e.returnvalue);
}
processSystemMessage (e) {
if (e.instance.props.timestamp && this.settings.general.showInChat) {
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {name: "time"});
if (index > -1) children[index].props.children = this.formatTimestamp(this.settings.dates.timestampDate, e.instance.props.timestamp._i);
processAuditLogEntry (e) {
if (!this.settings.general.showInAuditLogs || !e.instance.props.log) return;
let process = returnvalue => {
let [children, index] = BDFDB.ReactUtils.findParent(returnvalue, {props: [["className", BDFDB.disCN.auditlogtimestamp]]});
if (index > -1) children[index].props.children = this.formatTimestamp(this.settings.dates.timestampDate, e.instance.props.log.timestampStart._i);
};
if (typeof e.returnvalue.props.children == "function") {
let childrenRender = e.returnvalue.props.children;
e.returnvalue.props.children = BDFDB.TimeUtils.suppress((...args) => {
let children = childrenRender(...args);
process(children);
return children;
}, "", this);
}
}
processGuildSettingsAuditLogEntry (e) {
if (e.instance.props.log && this.settings.general.showInAuditLogs) {
if (typeof e.returnvalue.props.children == "function") {
let childrenRender = e.returnvalue.props.children;
e.returnvalue.props.children = BDFDB.TimeUtils.suppress((...args) => {
let children = childrenRender(...args);
this.editLog(e.instance.props.log, children);
return children;
}, "", this);
}
else this.editLog(e.instance.props.log, e.returnvalue);
}
}
editLog (log, returnvalue) {
if (!log || !returnvalue) return;
let [children, index] = BDFDB.ReactUtils.findParent(returnvalue, {props: [["className", BDFDB.disCN.auditlogtimestamp]]});
if (index > -1) children[index].props.children = this.formatTimestamp(this.settings.dates.timestampDate, log.timestampStart._i);
else process(e.returnvalue);
}
formatTimestamp (format, date) {
@ -254,28 +232,26 @@ module.exports = (_ => {
}
setMaxWidth (timestamp, compact) {
if (currentMode != compact) {
currentMode = compact;
if (timestamp.props.className && typeof timestamp.type == "string") {
let tempTimestamp = BDFDB.DOMUtils.create(`<div class="${BDFDB.disCN.messagecompact}"><${timestamp.type} class="${timestamp.props.className}" style="width: auto !important;">${this.formatTimestamp(this.settings.dates.timestampDate, new Date(253402124399995))}</${timestamp.type}></div>`);
document.body.appendChild(tempTimestamp);
let width = BDFDB.DOMUtils.getRects(tempTimestamp.firstElementChild).width + 10;
tempTimestamp.remove();
BDFDB.DOMUtils.appendLocalStyle(this.name + "CompactCorrection", `
${BDFDB.dotCN.messagecompact + BDFDB.dotCN.messagewrapper} {
padding-left: ${44 + width}px;
}
${BDFDB.dotCNS.messagecompact + BDFDB.dotCN.messagecontents} {
margin-left: -${44 + width}px;
padding-left: ${44 + width}px;
text-indent: calc(-${44 + width}px - -1rem);
}
${BDFDB.dotCNS.messagecompact + BDFDB.dotCNS.messageheader + BDFDB.dotCN.messagetimestamp} {
width: ${width}px;
}
`);
if (currentMode == compact) return;
currentMode = compact;
if (!timestamp.props.className || typeof timestamp.type != "string") return;
let tempTimestamp = BDFDB.DOMUtils.create(`<div class="${BDFDB.disCN.messagecompact}"><${timestamp.type} class="${timestamp.props.className}" style="width: auto !important;">${this.formatTimestamp(this.settings.dates.timestampDate, new Date(253402124399995))}</${timestamp.type}></div>`);
document.body.appendChild(tempTimestamp);
let width = BDFDB.DOMUtils.getRects(tempTimestamp.firstElementChild).width + 10;
tempTimestamp.remove();
BDFDB.DOMUtils.appendLocalStyle(this.name + "CompactCorrection", `
${BDFDB.dotCN.messagecompact + BDFDB.dotCN.messagewrapper} {
padding-left: ${44 + width}px;
}
}
${BDFDB.dotCNS.messagecompact + BDFDB.dotCN.messagecontents} {
margin-left: -${44 + width}px;
padding-left: ${44 + width}px;
text-indent: calc(-${44 + width}px - -1rem);
}
${BDFDB.dotCNS.messagecompact + BDFDB.dotCNS.messageheader + BDFDB.dotCN.messagetimestamp} {
width: ${width}px;
}
`);
}
};
})(window.BDFDB_Global.PluginUtils.buildPlugin(changeLog));