It's not a very smart bookmarklet, so it'll only work if used on an image-only page (i.e "view image"/"open image in new tab"/etc before using it. If you try to use it on any other page it'll probably look weird (doesn't ignore page styling), and the search links will just open broken searches, but I didn't feel like trying to write code to parse a webpage looking for a "primary" image in a bookmarklet.
Click the bookmarklet a second time to close the menu again if you want/need to.
Code: Select all
javascript:(() => {
var menuID = "img-search-menu";
var getMenu = () => {
return document.getElementById(menuID);
};
var hideMenu = () => {
getMenu()?.remove();
};
const link = (label, href) => {
const a = document.createElement("a");
a.href = href;
a. innerHTML = label;
a.target = "_blank";
return a;
};
var googleLens = (url) => {
return link("Google Lens", `https://lens.google.com/uploadbyurl?url=${encodeURIComponent(url)}`);
};
const tineye = (url) => {
return link("Tineye", `https://tineye.com/search?pluginver=bookmark_1.0&url=${url}`);
};
const yandex = (url) => {
return link("Yandex", `https://yandex.com/images/search?rpt=imageview&url=${encodeURIComponent(url)}`)
};
const karmaDecay = (url) => {
return link("Reddit", `http://karmadecay.com/${window.location.href}`)
};
const bing = (url) => {
return link("Bing", `https://www.bing.com/images/searchbyimage?cbir=sbi&imgurl=${window.location.href}`)
};
var createMenu = () => {
var menu = document.createElement("div");
menu.id = menuID;
menu.style = "background-color:lightskyblue; border-radius:25px; border:2px solid orangered; float:left; font-family:arial,sans,verdana; font-size:20px; z-index:10000; display: inline-block;line-height:unset!important; line-height:1!important; overflow:visible; box-shadow: 1px 1px #000; position:fixed; top: 0; padding:5px;";
document.querySelector("body")?.append(menu);
const searchList = document.createElement("ul");
searchList.style = "padding-right: 20px";
for (const search of [googleLens, tineye, yandex, karmaDecay, bing]) {
const listItem = document.createElement("li");
listItem.append(search(window.location.href));
searchList.append(listItem);
}
menu.append(searchList);
};
if (getMenu()) {
hideMenu()
} else {
createMenu();
}
})();