Update CompleteTimestamps.plugin.js

This commit is contained in:
Mirco Wittrien 2018-12-14 12:08:12 +01:00
parent d4932a4a2f
commit 3e2fc091d0
1 changed files with 29 additions and 28 deletions

View File

@ -116,7 +116,6 @@ class CompleteTimestamps {
if (change.removedNodes) { if (change.removedNodes) {
change.removedNodes.forEach((node) => { change.removedNodes.forEach((node) => {
if (this.updateTimestamps && node.tagName && node.getAttribute("layer-id") == "user-settings") { if (this.updateTimestamps && node.tagName && node.getAttribute("layer-id") == "user-settings") {
this.setMaxWidth();
document.querySelectorAll(".complete-timestamp").forEach(timestamp => {timestamp.classList.remove("complete-timestamp");}); document.querySelectorAll(".complete-timestamp").forEach(timestamp => {timestamp.classList.remove("complete-timestamp");});
document.querySelectorAll(".complete-timestamp-divider").forEach(divider => {divider.remove();}); document.querySelectorAll(".complete-timestamp-divider").forEach(divider => {divider.remove();});
document.querySelectorAll("time").forEach(stamp => {this.changeTimestamp(stamp);}) document.querySelectorAll("time").forEach(stamp => {this.changeTimestamp(stamp);})
@ -134,8 +133,6 @@ class CompleteTimestamps {
BDFDB.languages BDFDB.languages
); );
this.setMaxWidth();
$(document) $(document)
.on("mouseenter." + this.getName(), BDFDB.dotCNS.message + BDFDB.dotCN.messagecontent, (e) => { .on("mouseenter." + this.getName(), BDFDB.dotCNS.message + BDFDB.dotCN.messagecontent, (e) => {
if (BDFDB.getData("showOnHover", this, "settings")) { if (BDFDB.getData("showOnHover", this, "settings")) {
@ -265,6 +262,7 @@ class CompleteTimestamps {
if (!stamp.className || stamp.className.toLowerCase().indexOf("timestamp") == -1 || stamp.classList.contains("complete-timestamp")) return; if (!stamp.className || stamp.className.toLowerCase().indexOf("timestamp") == -1 || stamp.classList.contains("complete-timestamp")) return;
let time = stamp.getAttribute("datetime"); let time = stamp.getAttribute("datetime");
if (time) { if (time) {
this.setMaxWidth();
let choice = BDFDB.getData("creationDateLang", this, "choices"); let choice = BDFDB.getData("creationDateLang", this, "choices");
stamp.classList.add("complete-timestamp"); stamp.classList.add("complete-timestamp");
let stampdivider = document.createElement("span"); let stampdivider = document.createElement("span");
@ -351,31 +349,34 @@ class CompleteTimestamps {
} }
setMaxWidth () { setMaxWidth () {
var timestamp = document.querySelector(BDFDB.dotCN.messagetimestampcompact); if (this.currentMode != BDFDB.getDiscordMode()) {
if (timestamp) { this.currentMode = BDFDB.getDiscordMode();
var choice = BDFDB.getData("creationDateLang", this, "choices"); var timestamp = document.querySelector(BDFDB.dotCN.messagetimestampcompact);
var testtimestamp = $(`<time class="${timestamp.className}" style="width: auto !important;">${this.getTimestamp(this.languages[choice].id, new Date(253402124399995))}</time>`); if (timestamp) {
$(testtimestamp).appendTo(document.body); var choice = BDFDB.getData("creationDateLang", this, "choices");
var width = testtimestamp.outerWidth() + 5; var testtimestamp = $(`<time class="${timestamp.className}" style="width: auto !important;">${this.getTimestamp(this.languages[choice].id, new Date(253402124399995))}</time>`);
testtimestamp.remove(); $(testtimestamp).appendTo(document.body);
BDFDB.appendLocalStyle(this.getName() + "CompactCorrection", ` var width = testtimestamp.outerWidth() + 5;
${BDFDB.dotCN.messagetimestampcompact} { testtimestamp.remove();
width: ${width}px !important; BDFDB.appendLocalStyle(this.getName() + "CompactCorrection", `
} ${BDFDB.dotCN.messagetimestampcompact} {
${BDFDB.dotCN.messagetimestampcompactismentioned} { width: ${width}px !important;
width: ${width + 2}px !important; }
} ${BDFDB.dotCN.messagetimestampcompactismentioned} {
${BDFDB.dotCN.messagemarkupiscompact} { width: ${width + 2}px !important;
margin-left: ${width}px !important; }
text-indent: -${width}px !important; ${BDFDB.dotCN.messagemarkupiscompact} {
} margin-left: ${width}px !important;
${BDFDB.dotCN.messageaccessorycompact} { text-indent: -${width}px !important;
padding-left: ${width}px !important; }
} ${BDFDB.dotCN.messageaccessorycompact} {
`); padding-left: ${width}px !important;
} }
else { `);
BDFDB.removeLocalStyle(this.getName() + "CompactCorrection"); }
else {
BDFDB.removeLocalStyle(this.getName() + "CompactCorrection");
}
} }
} }
} }