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");
|
open(engine + encodeURIComponent(src), "_blank");
|
||||||
}
|
}
|
||||||
|
|
||||||
const imageContextMenuPatch: NavContextMenuPatchCallback = (children, props) => () => {
|
function makeSearchItem(src: string) {
|
||||||
if (!props) return;
|
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((
|
|
||||||
<Menu.MenuItem
|
<Menu.MenuItem
|
||||||
label="Search Image"
|
label="Search Image"
|
||||||
key="search-image"
|
key="search-image"
|
||||||
|
@ -90,8 +81,23 @@ const imageContextMenuPatch: NavContextMenuPatchCallback = (children, props) =>
|
||||||
action={() => Object.values(Engines).forEach(e => search(src, e))}
|
action={() => Object.values(Engines).forEach(e => search(src, e))}
|
||||||
/>
|
/>
|
||||||
</Menu.MenuItem>
|
</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({
|
export default definePlugin({
|
||||||
|
@ -111,10 +117,12 @@ export default definePlugin({
|
||||||
],
|
],
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
addContextMenuPatch("message", imageContextMenuPatch);
|
addContextMenuPatch("message", messageContextMenuPatch);
|
||||||
|
addContextMenuPatch("image-context", imageContextMenuPatch);
|
||||||
},
|
},
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
removeContextMenuPatch("message", imageContextMenuPatch);
|
removeContextMenuPatch("message", messageContextMenuPatch);
|
||||||
|
removeContextMenuPatch("image-context", imageContextMenuPatch);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue