Image search "bookmarklet"

Moderator: blueman

Post Reply
funlovin
Posts: 99
Joined: Mon 21-Mar-2016 8:14 pm
Been thanked: 2 times

Image search "bookmarklet"

Post by funlovin »

I don't know if this will be useful to anyone, but - inspired by something I saw on... I think it was reddit - here's an image search "bookmarklet" that might make it quicker to search multiple sites for suspicious pics. If you create a bookmark in Chrome (maybe also works in other browsers, haven't tested), and put the following code as the "URL", clicking the bookmark will embed in the open page a menu with quick links to send the current page URL to Bing, Google Lens, Reddit, Yandex or Tineye for reverse image search. (unfortunately Google Lens doesn't search for the image directly, you still have to click "Search for image source" after, but that's Google for ya).

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();
  }
})();
blueman
Posts: 4488
Joined: Tue 22-Dec-2015 8:34 pm
Has thanked: 19 times
Been thanked: 9 times

Re: Image search "bookmarklet"

Post by blueman »

Thanks for that, that's handy :)
Post Reply