ReverseImageSearch: add support for image modal
This commit is contained in:
parent
4d198e46bc
commit
13961a4ba5
|
@ -36,17 +36,8 @@ function search(src: string, engine: string) {
|
|||
open(engine + encodeURIComponent(src), "_blank");
|
||||
}
|
||||
|
||||
const imageContextMenuPatch: NavContextMenuPatchCallback = (children, props) => () => {
|
||||
if (!props) return;
|
||||
const { reverseImageSearchType, itemHref, itemSrc } = props;
|
||||
|
||||
if (!reverseImageSearchType || reverseImageSearchType !== "img") return;
|
||||
|
||||
const src = itemHref ?? itemSrc;
|
||||
|
||||
const group = findGroupChildrenByChildId("copy-link", children);
|
||||
if (group) {
|
||||
group.push((
|
||||
function makeSearchItem(src: string) {
|
||||
return (
|
||||
<Menu.MenuItem
|
||||
label="Search Image"
|
||||
key="search-image"
|
||||
|
@ -90,8 +81,23 @@ const imageContextMenuPatch: NavContextMenuPatchCallback = (children, props) =>
|
|||
action={() => Object.values(Engines).forEach(e => search(src, e))}
|
||||
/>
|
||||
</Menu.MenuItem>
|
||||
));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const messageContextMenuPatch: NavContextMenuPatchCallback = (children, props) => () => {
|
||||
if (props?.reverseImageSearchType !== "img") return;
|
||||
|
||||
const src = props.itemHref ?? props.itemSrc;
|
||||
|
||||
const group = findGroupChildrenByChildId("copy-link", children);
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue