Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- SauceNao Reverse Image Search
- Add 'Search by Image' in browser context menu when you
- right click on image to search Google with that image.
- Copyright (C) 2012 LouCypher
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>
- */
- // ==UserScript==
- // @name SauceNao Reverse Image Search
- // @description Adds a "Search on SauceNao" option to the context menu
- // @version 1.0
- // @author BasedPeacock, updated for HTTP by Dildoer the Cocknight
- // @license GPL
- // @include *
- // @exclude file://*
- // @grant GM_openInTab
- // @namespace https://greasyfork.org/users/148462
- // ==/UserScript==
- if (!("contextMenu" in document.documentElement &&
- "HTMLMenuItemElement" in window)) return;
- var body = document.body;
- body.addEventListener("contextmenu", initMenu, false);
- var menu = body.appendChild(document.createElement("menu"));
- menu.outerHTML = '<menu id="userscript-search-by-image" type="context">\
- <menuitem class="image-search" label="Search SauceNao for image" icon="https://i.imgur.com/3Fn1aTv.png"></menuitem>\
- <menuitem class="image-search-http" label="Search SauceNao for HTTP version image" icon="https://i.imgur.com/3Fn1aTv.png"></menuitem> </menu>';
- document.querySelector("#userscript-search-by-image menuitem.image-search")
- .addEventListener("click", searchImage, false);
- document.querySelector("#userscript-search-by-image menuitem.image-search-http")
- .addEventListener("click", searchImageHTTP, false);
- function initMenu(aEvent) {
- // Executed when user right click on web page body
- // aEvent.target is the element you right click on
- var node = aEvent.target;
- var item = document.querySelector("#userscript-search-by-image menuitem.image-search");
- var item2 = document.querySelector("#userscript-search-by-image menuitem.image-search-http");
- if (node.localName == "img") {
- body.setAttribute("contextmenu", "userscript-search-by-image");
- item.setAttribute("imageURL", node.src);
- item2.setAttribute("imageURL", node.src);
- } else {
- body.removeAttribute("contextmenu");
- item.removeAttribute("imageURL");
- }
- }
- function addParamsToForm(aForm, aKey, aValue) {
- var hiddenField = document.createElement("input");
- hiddenField.setAttribute("type", "hidden");
- hiddenField.setAttribute("name", aKey);
- hiddenField.setAttribute("value", aValue);
- aForm.appendChild(hiddenField);
- }
- function searchImage(aEvent) {
- // Executed when user click on menuitem
- // aEvent.target is the <menuitem> element
- var imageURL = aEvent.target.getAttribute("imageURL");
- window.open(`https://saucenao.com/search.php?url=${imageURL}`);
- }
- function searchImageHTTP(aEvent) {
- // Executed when user click on menuitem
- // aEvent.target is the <menuitem> element
- var imageURL = aEvent.target.getAttribute("imageURL");
- let url = new URL(imageURL);
- window.open(`https://saucenao.com/search.php?url=http://${url.host}${url.pathname}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment