//META{"name":"ShowImageDetails"}*//
class ShowImageDetails {
initConstructor () {
this.patchModules = {
"LazyImageZoomable":"componentDidMount",
"StandardSidebarView":"componentWillUnmount"
};
this.css = `
.image-details .image-details-size {
margin: 0 10px;
}
.image-details-tooltip {
max-width: 500px;
}
.image-details-tooltip .image-details-tooltip-size {
margin: 10px 0;
}
`;
this.updateDetails = false;
this.defaults = {
settings: {
showOnHover: {value:false, description:"Show the details as Tooltip instead:"}
},
amounts: {
hoverDelay: {value:0, description:"Tooltip delay in millisec:"}
}
};
}
getName () {return "ShowImageDetails";}
getDescription () {return "Display the name, size and dimensions of uploaded images (does not include embed images) in the chat as an header or as a tooltip.";}
getVersion () {return "1.1.1";}
getAuthor () {return "DevilBro";}
getSettingsPanel () {
if (!this.started || typeof BDFDB !== "object") return;
let settings = BDFDB.getAllData(this, "settings");
let amounts = BDFDB.getAllData(this, "amounts");
let settingshtml = `
${this.getName()}
`;
for (let key in settings) {
settingshtml += `
`;
}
for (let key in amounts) {
settingshtml += `
`;
}
settingshtml += `
`;
let settingspanel = $(settingshtml)[0];
BDFDB.initElements(settingspanel);
$(settingspanel)
.on("click", BDFDB.dotCN.switchinner, () => {this.updateSettings(settingspanel);})
.on("input", ".amountInput", (e) => {
let input = parseInt(e.currentTarget.value);
if (!isNaN(input) && input > -1) BDFDB.saveData(e.currentTarget.getAttribute("option"), input, this, "amounts");
});
return settingspanel;
}
//legacy
load () {}
start () {
let libraryScript = null;
if (typeof BDFDB !== "object" || typeof BDFDB.isLibraryOutdated !== "function" || BDFDB.isLibraryOutdated()) {
libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]');
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
libraryScript.setAttribute("type", "text/javascript");
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js");
document.head.appendChild(libraryScript);
}
this.startTimeout = setTimeout(() => {this.initialize();}, 30000);
if (typeof BDFDB === "object" && typeof BDFDB.isLibraryOutdated === "function") this.initialize();
else libraryScript.addEventListener("load", () => {this.initialize();});
}
initialize () {
if (typeof BDFDB === "object") {
BDFDB.loadMessage(this);
BDFDB.WebModules.forceAllUpdates(this);
}
else {
console.error(this.getName() + ": Fatal Error: Could not load BD functions!");
}
}
stop () {
if (typeof BDFDB === "object") {
document.querySelectorAll(".image-details-added").forEach(image => {this.resetImage(image);});
BDFDB.unloadMessage(this);
}
}
// begin of own functions
updateSettings (settingspanel) {
let settings = {};
for (let input of settingspanel.querySelectorAll(BDFDB.dotCN.switchinner)) {
settings[input.value] = input.checked;
}
BDFDB.saveAllData(settings, this, "settings");
this.updateDetails = true;
}
resetImage (image) {
image.classList.remove("image-details-added");
$(image).off("." + this.getName());
let wrapper = image.parentElement;
if (wrapper.classList.contains("image-details-wrapper")) {
wrapper.parentElement.insertBefore(image, wrapper);
wrapper.remove();
}
}
processLazyImageZoomable (instance, image) {
let fiber = instance._reactInternalFiber;
if (fiber.return && fiber.return.return && fiber.return.return.memoizedProps && fiber.return.return.memoizedProps.attachment) {
let info = fiber.return.return.memoizedProps.attachment;
if (info && !info.filename.endsWith(".bdemote.png") && !info.filename.endsWith(".bdemote.gif")) {
let scroller = BDFDB.getParentEle(BDFDB.dotCN.messages, image);
image.classList.add("image-details-added");
if (BDFDB.getData("showOnHover", this, "settings")) {
$(image).on("mouseenter." + this.getName(), () => {
BDFDB.createTooltip(`${info.filename}
${BDFDB.formatBytes(info.size)}
${info.width}x${info.height}px
`, image, {type:"right", html:true, selector:"image-details-tooltip", delay:BDFDB.getData("hoverDelay", this, "amounts")});
});
}
else {
$(``).insertBefore(image).append(image);
scroller.scrollTop += image.parentElement.getBoundingClientRect().height - image.getBoundingClientRect().height;
}
}
}
}
processStandardSidebarView (instance) {
if (this.updateDetails) {
this.updateDetails = false;
document.querySelectorAll(".image-details-added").forEach(image => {this.resetImage(image);});
BDFDB.WebModules.forceAllUpdates(this);
}
}
}