-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
30 lines (27 loc) · 887 Bytes
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Function to create Google Lens URL with the image URL
function searchWithGoogleLens(imageUrl) {
const googleLensBaseUrl = "https://lens.google.com/uploadbyurl";
const params = new URLSearchParams({
url: imageUrl,
hl: "en-PH",
re: "df",
st: Date.now().toString(),
vpw: window.innerWidth.toString(),
vph: window.innerHeight.toString(),
ep: "gsbubu"
});
return `${googleLensBaseUrl}?${params.toString()}`;
}
// Create context menu for images
chrome.contextMenus.create({
id: "searchGoogleLens",
title: "Search image with Google Lens",
contexts: ["image"]
});
// Handle context menu click
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "searchGoogleLens") {
const googleLensUrl = searchWithGoogleLens(info.srcUrl);
chrome.tabs.create({ url: googleLensUrl });
}
});