fix(ReverseImageSearch): Don't apply to non image files

This commit is contained in:
Vendicated 2022-11-07 18:52:34 +01:00
parent 963a7332b4
commit 851d07f31a
No known key found for this signature in database
GPG key ID: EC781ADFB93EFFA3

View file

@ -31,7 +31,6 @@ const Engines = {
const Menu = lazyWebpack(filters.byProps("MenuItem")); const Menu = lazyWebpack(filters.byProps("MenuItem"));
export default definePlugin({ export default definePlugin({
name: "ReverseImageSearch", name: "ReverseImageSearch",
description: "yes", description: "yes",
@ -42,11 +41,27 @@ export default definePlugin({
replacement: { replacement: {
match: /key:"open-native-link".{0,200}\(\{href:(.{0,3}),.{0,200}\}\)/, match: /key:"open-native-link".{0,200}\(\{href:(.{0,3}),.{0,200}\}\)/,
replace: (m, src) => replace: (m, src) =>
`${m},Vencord.Plugins.plugins.ReverseImageSearch.makeMenu(${src})` `${m},Vencord.Plugins.plugins.ReverseImageSearch.makeMenu(${src}, arguments[2])`
}
}, {
// pass the target to the open link menu so we can check if it's an image
find: "REMOVE_ALL_REACTIONS_CONFIRM_BODY,",
replacement: {
// url1 = url2 = props.attachment.url
// ...
// OpenLinks(url2 != null ? url2 : url1, someStuffs)
//
// the back references are needed because the code is like Z(a!=null?b:c,d), no way to match that
// otherwise
match: /(?<props>.).onHeightUpdate.{0,200}(.)=(.)=.\.url;.+?\(null!=\3\?\3:\2[^)]+/,
replace: "$&,$<props>.target"
} }
}], }],
makeMenu(src: string) { makeMenu(src: string, target: HTMLElement) {
if (target && target.attributes["data-role"]?.value !== "img")
return null;
return ( return (
<Menu.MenuItem <Menu.MenuItem
label="Search Image" label="Search Image"