diff --git a/src/plugins/reverseImageSearch/index.tsx b/src/plugins/reverseImageSearch/index.tsx
index 811e7ff08..6c5f3e729 100644
--- a/src/plugins/reverseImageSearch/index.tsx
+++ b/src/plugins/reverseImageSearch/index.tsx
@@ -36,62 +36,68 @@ function search(src: string, engine: string) {
open(engine + encodeURIComponent(src), "_blank");
}
-const imageContextMenuPatch: NavContextMenuPatchCallback = (children, props) => () => {
- if (!props) return;
- const { reverseImageSearchType, itemHref, itemSrc } = props;
+function makeSearchItem(src: string) {
+ return (
+
+ {Object.keys(Engines).map((engine, i) => {
+ const key = "search-image-" + engine;
+ return (
+
+ = 3 // Do not round Google, Yandex & SauceNAO
+ ? "50%"
+ : void 0
+ }}
+ aria-hidden="true"
+ height={16}
+ width={16}
+ src={new URL("/favicon.ico", Engines[engine]).toString().replace("lens.", "")}
+ />
+ {engine}
+
+ }
+ action={() => search(src, Engines[engine])}
+ />
+ );
+ })}
+
+
+ All
+
+ }
+ action={() => Object.values(Engines).forEach(e => search(src, e))}
+ />
+
+ );
+}
- if (!reverseImageSearchType || reverseImageSearchType !== "img") return;
+const messageContextMenuPatch: NavContextMenuPatchCallback = (children, props) => () => {
+ if (props?.reverseImageSearchType !== "img") return;
- const src = itemHref ?? itemSrc;
+ const src = props.itemHref ?? props.itemSrc;
const group = findGroupChildrenByChildId("copy-link", children);
- if (group) {
- group.push((
-
- {Object.keys(Engines).map((engine, i) => {
- const key = "search-image-" + engine;
- return (
-
- = 3 // Do not round Google, Yandex & SauceNAO
- ? "50%"
- : void 0
- }}
- aria-hidden="true"
- height={16}
- width={16}
- src={new URL("/favicon.ico", Engines[engine]).toString().replace("lens.", "")}
- />
- {engine}
-
- }
- action={() => search(src, Engines[engine])}
- />
- );
- })}
-
-
- All
-
- }
- action={() => Object.values(Engines).forEach(e => search(src, e))}
- />
-
- ));
- }
+ group?.push(makeSearchItem(src));
+};
+
+const imageContextMenuPatch: NavContextMenuPatchCallback = (children, props) => () => {
+ if (!props?.src) return;
+
+ const group = findGroupChildrenByChildId("copy-native-link", children) ?? children;
+ group.push(makeSearchItem(props.src));
};
export default definePlugin({
@@ -111,10 +117,12 @@ export default definePlugin({
],
start() {
- addContextMenuPatch("message", imageContextMenuPatch);
+ addContextMenuPatch("message", messageContextMenuPatch);
+ addContextMenuPatch("image-context", imageContextMenuPatch);
},
stop() {
- removeContextMenuPatch("message", imageContextMenuPatch);
+ removeContextMenuPatch("message", messageContextMenuPatch);
+ removeContextMenuPatch("image-context", imageContextMenuPatch);
}
});