Update ImageUtilities.plugin.js
This commit is contained in:
parent
177d235536
commit
bc529c9f4c
|
@ -2,7 +2,7 @@
|
|||
* @name ImageUtilities
|
||||
* @author DevilBro
|
||||
* @authorId 278543574059057154
|
||||
* @version 4.4.0
|
||||
* @version 4.4.1
|
||||
* @description Adds several Utilities for Images/Videos (Gallery, Download, Reverse Search, Zoom, Copy, etc.)
|
||||
* @invite Jx3TjNS
|
||||
* @donate https://www.paypal.me/MircoWittrien
|
||||
|
@ -17,12 +17,12 @@ module.exports = (_ => {
|
|||
"info": {
|
||||
"name": "ImageUtilities",
|
||||
"author": "DevilBro",
|
||||
"version": "4.4.0",
|
||||
"version": "4.4.1",
|
||||
"description": "Adds several Utilities for Images/Videos (Gallery, Download, Reverse Search, Zoom, Copy, etc.)"
|
||||
},
|
||||
"changeLog": {
|
||||
"fixed": {
|
||||
"Avatars/Icons": "No longer uses .WEBP type for Avatars and Icons"
|
||||
"added": {
|
||||
"User Banners": "Right Click Banner to get Options"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -189,7 +189,8 @@ module.exports = (_ => {
|
|||
},
|
||||
after: {
|
||||
ImageModal: ["render", "componentDidMount"],
|
||||
LazyImage: ["render", "componentDidMount"]
|
||||
LazyImage: ["render", "componentDidMount"],
|
||||
UserBanner: "default"
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -274,14 +275,6 @@ module.exports = (_ => {
|
|||
}
|
||||
|
||||
onStart () {
|
||||
// REMOVE 24.04.2021
|
||||
let oldData = BDFDB.DataUtils.load(this);
|
||||
if (oldData.settings) {
|
||||
this.settings.general = oldData.settings;
|
||||
BDFDB.DataUtils.save(this.settings.general, this, "general");
|
||||
BDFDB.DataUtils.remove(this, "settings");
|
||||
}
|
||||
|
||||
BDFDB.ListenerUtils.add(this, document.body, "click", BDFDB.dotCNS.message + BDFDB.dotCNS.imagewrapper + "img", e => {
|
||||
clickedImage = e.target;
|
||||
BDFDB.TimeUtils.timeout(_ => {clickedImage = null;});
|
||||
|
@ -509,18 +502,18 @@ module.exports = (_ => {
|
|||
if (e.instance.props.guild && this.settings.places.guildIcons) {
|
||||
let banner = BDFDB.DOMUtils.getParent(BDFDB.dotCN.guildheader, e.instance.props.target) || BDFDB.DOMUtils.getParent(BDFDB.dotCN.guildchannels, e.instance.props.target) && !e.instance.props.target.className && e.instance.props.target.parentElement.firstElementChild == e.instance.props.target;
|
||||
if (banner) {
|
||||
if (e.instance.props.guild.banner) this.injectItem(e, (BDFDB.LibraryModules.IconUtils.getGuildBannerURL(e.instance.props.guild) || "").replace(".webp", ".png"));
|
||||
if (e.instance.props.guild.banner) this.injectItem(e, (BDFDB.LibraryModules.IconUtils.getGuildBannerURL(e.instance.props.guild) || "").replace(/\.webp|\.gif/, ".png"));
|
||||
}
|
||||
else if (e.type != "GuildChannelListContextMenu") this.injectItem(e, (e.instance.props.guild.getIconURL() || "").replace(".webp", ".png"), e.instance.props.guild.icon && BDFDB.LibraryModules.IconUtils.isAnimatedIconHash(e.instance.props.guild.icon) && e.instance.props.guild.getIconURL(true));
|
||||
else if (e.type != "GuildChannelListContextMenu") this.injectItem(e, (e.instance.props.guild.getIconURL() || "").replace(/\.webp|\.gif/, ".png"), e.instance.props.guild.icon && BDFDB.LibraryModules.IconUtils.isAnimatedIconHash(e.instance.props.guild.icon) && e.instance.props.guild.getIconURL(true));
|
||||
}
|
||||
}
|
||||
|
||||
onUserContextMenu (e) {
|
||||
if (e.instance.props.user && this.settings.places.userAvatars) this.injectItem(e, (e.instance.props.user.getAvatarURL() || "").replace(".webp", ".png"), BDFDB.LibraryModules.IconUtils.isAnimatedIconHash(e.instance.props.user.avatar) && e.instance.props.user.getAvatarURL(null, true))
|
||||
if (e.instance.props.user && this.settings.places.userAvatars) this.injectItem(e, (e.instance.props.user.getAvatarURL() || "").replace(/\.webp|\.gif/, ".png"), BDFDB.LibraryModules.IconUtils.isAnimatedIconHash(e.instance.props.user.avatar) && e.instance.props.user.getAvatarURL(null, true));
|
||||
}
|
||||
|
||||
onGroupDMContextMenu (e) {
|
||||
if (e.instance.props.channel && e.instance.props.channel.isGroupDM() && this.settings.places.groupIcons) this.injectItem(e, (BDFDB.DMUtils.getIcon(e.instance.props.channel.id) || "").replace(".webp", ".png"));
|
||||
if (e.instance.props.channel && e.instance.props.channel.isGroupDM() && this.settings.places.groupIcons) this.injectItem(e, (BDFDB.DMUtils.getIcon(e.instance.props.channel.id) || "").replace(/\.webp|\.gif/, ".png"));
|
||||
}
|
||||
|
||||
onNativeContextMenu (e) {
|
||||
|
@ -556,19 +549,7 @@ module.exports = (_ => {
|
|||
}
|
||||
|
||||
injectItem (e, ...urls) {
|
||||
let fileTypes = [];
|
||||
let validUrls = urls.filter(n => this.isValid(n && n.file || n)).map(n => {
|
||||
let srcUrl = (n.file || n).replace(/^url\(|\)$|"|'/g, "").replace(/\?size\=\d+$/, "?size=4096");
|
||||
let url = srcUrl.replace(/[\?\&](height|width)=\d+/g, "").split("%3A")[0];
|
||||
let original = (n.original || n).replace(/^url\(|\)$|"|'/g, "").replace(/\?size\=\d+$/, "?size=4096").replace(/[\?\&](height|width)=\d+/g, "").split("%3A")[0];
|
||||
if (url.indexOf("https://images-ext-1.discordapp.net/external/") > -1 || url.indexOf("https://images-ext-2.discordapp.net/external/") > -1) {
|
||||
if (url.split("/https/").length > 1) url = "https://" + url.split("/https/").pop();
|
||||
else if (url.split("/http/").length > 1) url = "http://" + url.split("/http/").pop();
|
||||
}
|
||||
const file = url && (BDFDB.LibraryModules.URLParser.parse(url).pathname || "").toLowerCase();
|
||||
const fileType = file && (file.split(".").pop() || "");
|
||||
return url && fileType && !fileTypes.includes(fileType) && fileTypes.push(fileType) && {file: url, src: srcUrl, original: original, fileType};
|
||||
}).filter(n => n);
|
||||
let validUrls = this.filterUrls(...urls);
|
||||
if (!validUrls.length) return;
|
||||
|
||||
let [removeParent, removeIndex] = BDFDB.ContextMenuUtils.findItem(e.returnvalue, {id: "copy-native-link", group: true});
|
||||
|
@ -581,11 +562,7 @@ module.exports = (_ => {
|
|||
|
||||
let type = this.isValid(validUrls[0].file, "video") ? BDFDB.LanguageUtils.LanguageStrings.VIDEO : BDFDB.LanguageUtils.LanguageStrings.IMAGE;
|
||||
let isNative = validUrls.length == 1 && removeIndex > -1;
|
||||
let subMenu = validUrls.length == 1 ? this.createUrlMenu(e, validUrls[0]) : validUrls.map((urlData, i) => BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
|
||||
label: urlData.fileType.toUpperCase(),
|
||||
id: BDFDB.ContextMenuUtils.createItemId(this.name, "subitem", i),
|
||||
children: this.createUrlMenu(e, urlData)
|
||||
}));
|
||||
let subMenu = this.createSubMenus(e.instance, validUrls);
|
||||
|
||||
let [children, index] = isNative ? [removeParent, removeIndex] : BDFDB.ContextMenuUtils.findItem(e.returnvalue, {id: "devmode-copy-id", group: true});
|
||||
children.splice(index > -1 ? index : children.length, 0, isNative ? subMenu : BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuGroup, {
|
||||
|
@ -597,13 +574,37 @@ module.exports = (_ => {
|
|||
}));
|
||||
}
|
||||
|
||||
filterUrls (...urls) {
|
||||
let fileTypes = [];
|
||||
return urls.filter(n => this.isValid(n && n.file || n)).map(n => {
|
||||
let srcUrl = (n.file || n).replace(/^url\(|\)$|"|'/g, "").replace(/\?size\=\d+$/, "?size=4096");
|
||||
let url = srcUrl.replace(/[\?\&](height|width)=\d+/g, "").split("%3A")[0];
|
||||
let original = (n.original || n).replace(/^url\(|\)$|"|'/g, "").replace(/\?size\=\d+$/, "?size=4096").replace(/[\?\&](height|width)=\d+/g, "").split("%3A")[0];
|
||||
if (url.indexOf("https://images-ext-1.discordapp.net/external/") > -1 || url.indexOf("https://images-ext-2.discordapp.net/external/") > -1) {
|
||||
if (url.split("/https/").length > 1) url = "https://" + url.split("/https/").pop();
|
||||
else if (url.split("/http/").length > 1) url = "http://" + url.split("/http/").pop();
|
||||
}
|
||||
const file = url && (BDFDB.LibraryModules.URLParser.parse(url).pathname || "").toLowerCase();
|
||||
const fileType = file && (file.split(".").pop() || "");
|
||||
return url && fileType && !fileTypes.includes(fileType) && fileTypes.push(fileType) && {file: url, src: srcUrl, original: original, fileType};
|
||||
}).filter(n => n);
|
||||
}
|
||||
|
||||
isValid (url, type) {
|
||||
if (!url) return false;
|
||||
const file = url && (BDFDB.LibraryModules.URLParser.parse(url).pathname || "").split("%3A")[0].toLowerCase();
|
||||
return file && (!type && (url.startsWith("https://images-ext-1.discordapp.net/") || url.startsWith("https://images-ext-2.discordapp.net/") || Object.keys(fileTypes).some(t => file.endsWith(`/${t}`) || file.endsWith(`.${t}`))) || type && Object.keys(fileTypes).filter(t => fileTypes[t][type]).some(t => file.endsWith(`/${t}`) || file.endsWith(`.${t}`)));
|
||||
}
|
||||
|
||||
createUrlMenu (e, urls) {
|
||||
createSubMenus (instance, validUrls) {
|
||||
return validUrls.length == 1 ? this.createUrlMenu(instance, validUrls[0]) : validUrls.map((urlData, i) => BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
|
||||
label: urlData.fileType.toUpperCase(),
|
||||
id: BDFDB.ContextMenuUtils.createItemId(this.name, "subitem", i),
|
||||
children: this.createUrlMenu(instance, urlData)
|
||||
}));
|
||||
}
|
||||
|
||||
createUrlMenu (instance, urls) {
|
||||
let enabledEngines = BDFDB.ObjectUtils.filter(this.settings.engines, n => n);
|
||||
let enginesWithoutAll = BDFDB.ObjectUtils.filter(enabledEngines, n => n != "_all", true);
|
||||
let engineKeys = Object.keys(enginesWithoutAll);
|
||||
|
@ -695,7 +696,7 @@ module.exports = (_ => {
|
|||
id: BDFDB.ContextMenuUtils.createItemId(this.name, "single-search"),
|
||||
persisting: true,
|
||||
action: event => {
|
||||
if (!event.shiftKey) BDFDB.ContextMenuUtils.close(e.instance);
|
||||
if (!event.shiftKey) BDFDB.ContextMenuUtils.close(instance);
|
||||
BDFDB.DiscordUtils.openLink(this.defaults.engines[engineKeys[0]].url.replace(imgUrlReplaceString, encodeURIComponent(urls.file)), {
|
||||
minimized: event.shiftKey
|
||||
});
|
||||
|
@ -714,7 +715,7 @@ module.exports = (_ => {
|
|||
persisting: true,
|
||||
action: event => {
|
||||
const open = (url, k) => BDFDB.DiscordUtils.openLink(this.defaults.engines[k].url.replace(imgUrlReplaceString, this.defaults.engines[k].raw ? url : encodeURIComponent(url)), {minimized: event.shiftKey});
|
||||
if (!event.shiftKey) BDFDB.ContextMenuUtils.close(e.instance);
|
||||
if (!event.shiftKey) BDFDB.ContextMenuUtils.close(instance);
|
||||
if (key == "_all") {
|
||||
for (let key2 in enginesWithoutAll) open(urls.file, key2);
|
||||
}
|
||||
|
@ -1004,6 +1005,20 @@ module.exports = (_ => {
|
|||
}
|
||||
}
|
||||
|
||||
processUserBanner (e) {
|
||||
if (e.instance.props.user && this.settings.places.userAvatars && BDFDB.UserUtils.getBanner(e.instance.props.user.id)) console.log(e, );
|
||||
if (e.instance.props.user && this.settings.places.userAvatars && BDFDB.UserUtils.getBanner(e.instance.props.user.id)) e.returnvalue.props.onContextMenu = event => {
|
||||
let validUrls = this.filterUrls((e.instance.props.user.getBannerURL() || "").replace(/\.webp|\.gif/, ".png"), BDFDB.LibraryModules.IconUtils.isAnimatedIconHash(e.instance.props.user.banner) && e.instance.props.user.getBannerURL(true));
|
||||
if (validUrls.length) BDFDB.ContextMenuUtils.open(this, event, BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuGroup, {
|
||||
children: validUrls.length == 1 ? this.createSubMenus({}, validUrls) : BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
|
||||
label: BDFDB.LanguageUtils.LanguageStrings.IMAGE + " " + BDFDB.LanguageUtils.LanguageStrings.ACTIONS,
|
||||
id: BDFDB.ContextMenuUtils.createItemId(this.name, "main-subitem"),
|
||||
children: this.createSubMenus({}, validUrls)
|
||||
})
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
downloadFile (url, path) {
|
||||
url = url.startsWith("/assets") ? (window.location.origin + url) : url;
|
||||
BDFDB.LibraryRequires.request(url, {encoding: null}, (error, response, body) => {
|
||||
|
|
Loading…
Reference in New Issue