/**
* @name ForceImagePreviews
* @authorId 278543574059057154
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
* @patreon https://www.patreon.com/MircoWittrien
* @website https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ForceImagePreviews
* @source https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ForceImagePreviews/ForceImagePreviews.plugin.js
* @updateUrl https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ForceImagePreviews/ForceImagePreviews.plugin.js
*/
module.exports = (_ => {
const config = {
"info": {
"name": "ForceImagePreviews",
"author": "DevilBro",
"version": "1.2.0",
"description": "Force embedded Image Previews, if Discord doesn't do it itself. Caution: Externals Images can contain malicious code and reveal your IP!"
}
};
return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class {
getName() {return config.info.name;}
getAuthor() {return config.info.author;}
getVersion() {return config.info.version;}
getDescription() {return config.info.description;}
load() {
if (!window.BDFDB_Global || !Array.isArray(window.BDFDB_Global.pluginQueue)) window.BDFDB_Global = Object.assign({}, window.BDFDB_Global, {pluginQueue: []});
if (!window.BDFDB_Global.downloadModal) {
window.BDFDB_Global.downloadModal = true;
BdApi.showConfirmationModal("Library Missing", `The library plugin needed for ${config.info.name} is missing. Please click "Download Now" to install it.`, {
confirmText: "Download Now",
cancelText: "Cancel",
onCancel: _ => {delete window.BDFDB_Global.downloadModal;},
onConfirm: _ => {
delete window.BDFDB_Global.downloadModal;
require("request").get("https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js", (e, r, b) => {
if (!e && b && b.indexOf(`* @name BDFDB`) > -1) require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0BDFDB.plugin.js"), b, _ => {});
else BdApi.alert("Error", "Could not download BDFDB library plugin, try again some time later.");
});
}
});
}
if (!window.BDFDB_Global.pluginQueue.includes(config.info.name)) window.BDFDB_Global.pluginQueue.push(config.info.name);
}
start() {this.load();}
stop() {}
getSettingsPanel() {
let template = document.createElement("template");
template.innerHTML = `
The library plugin needed for ${config.info.name} is missing.\nPlease click
Download Now to install it.
`;
template.content.firstElementChild.querySelector("a").addEventListener("click", _ => {
require("request").get("https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js", (e, r, b) => {
if (!e && b && b.indexOf(`* @name BDFDB`) > -1) require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0BDFDB.plugin.js"), b, _ => {});
else BdApi.alert("Error", "Could not download BDFDB library plugin, try again some time later.");
});
});
return template.content.firstElementChild;
}
} : (([Plugin, BDFDB]) => {
var loadedEmbeds, requestedEmbeds;
return class ForceImagePreviews extends Plugin {
onLoad() {
loadedEmbeds = {};
requestedEmbeds = [];
this.patchedModules = {
before: {
SimpleMessageAccessories: "default"
}
};
}
onStart() {
BDFDB.PatchUtils.forceAllUpdates(this);
BDFDB.MessageUtils.rerenderAll();
}
onStop() {
BDFDB.PatchUtils.forceAllUpdates(this);
BDFDB.MessageUtils.rerenderAll();
}
processSimpleMessageAccessories (e) {
if (e.instance.props.message && e.instance.props.message.content) {
let message = new BDFDB.DiscordObjects.Message(e.instance.props.message);
for (let link of e.instance.props.message.content.split(/\n|\s|\r|\t|\0/g)) if (link.indexOf("https://") > -1 || link.indexOf("http://") > -1) {
link = link.indexOf("<") == 0 && link.indexOf(">") == link.length - 1 ? link.slice(1, -1) : link;
if (!this.isEmbedded(message.embeds, link)) {
if (!requestedEmbeds.includes(link)) {
requestedEmbeds.push(link);
BDFDB.LibraryRequires.request(link, (error, response, result) => {
if (response && response.headers["content-type"] && response.headers["content-type"].indexOf("image") > -1) {
let imageThrowaway = document.createElement("img");
imageThrowaway.src = link;
imageThrowaway.onload = _ => {
if (!this.isEmbedded(message.embeds, link)) {
loadedEmbeds[link] = {
image: {
url: link,
proxyURL: link,
height: imageThrowaway.naturalHeight,
width: imageThrowaway.naturalWidth
},
type: "image",
url: link
};
message.embeds.push(loadedEmbeds[link]);
BDFDB.ReactUtils.forceUpdate(e.instance);
}
};
}
else if (response && response.headers["server"] && response.headers["server"].toLowerCase().indexOf("youtube") > -1 && result.indexOf("yt-user-info") > -1) {
if (!this.isEmbedded(message.embeds, link)) {
result = result.replace(/[\r|\n|\t]|[\s]{2,}/g, "");
let width = result.split(new RegExp(BDFDB.StringUtils.regEscape('')[1].split('<')[0],
url: `https://www.youtube.com${result.split(new RegExp(BDFDB.StringUtils.regEscape('