aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/reverseImageSearch.tsx
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2022-11-07 18:52:34 +0100
committerVendicated <vendicated@riseup.net>2022-11-07 18:52:34 +0100
commit851d07f31a117cf342d09c0886ae0b38ae0c9050 (patch)
tree7c425c629c2e182f0976f8d98f91be074c59af86 /src/plugins/reverseImageSearch.tsx
parent963a7332b4daa183ec2d8d3ddf10f3f73b01746a (diff)
downloadVencord-851d07f31a117cf342d09c0886ae0b38ae0c9050.tar.gz
Vencord-851d07f31a117cf342d09c0886ae0b38ae0c9050.tar.bz2
Vencord-851d07f31a117cf342d09c0886ae0b38ae0c9050.zip
fix(ReverseImageSearch): Don't apply to non image files
Diffstat (limited to 'src/plugins/reverseImageSearch.tsx')
-rw-r--r--src/plugins/reverseImageSearch.tsx21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/plugins/reverseImageSearch.tsx b/src/plugins/reverseImageSearch.tsx
index da7d844..79c2488 100644
--- a/src/plugins/reverseImageSearch.tsx
+++ b/src/plugins/reverseImageSearch.tsx
@@ -31,7 +31,6 @@ const Engines = {
const Menu = lazyWebpack(filters.byProps("MenuItem"));
-
export default definePlugin({
name: "ReverseImageSearch",
description: "yes",
@@ -42,11 +41,27 @@ export default definePlugin({
replacement: {
match: /key:"open-native-link".{0,200}\(\{href:(.{0,3}),.{0,200}\}\)/,
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 (
<Menu.MenuItem
label="Search Image"