Search with google image fix

Search with google image again cause fuck google lens, SHIFT + Left click to search

当前为 2022-03-31 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Search with google image fix
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.1
  5. // @description Search with google image again cause fuck google lens, SHIFT + Left click to search
  6. // @author You
  7. // @require http://code.jquery.com/jquery-3.4.1.min.js
  8. // @match http://*/*
  9. // @match https://*/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14.  
  15. function srcHasHostInformation(url) {
  16. var res = url.match(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g);
  17. return (res !== null)
  18. }
  19. function addHostInformationIfNeeded(src) {
  20. if (!srcHasHostInformation(src)) {
  21. if (src[0] != "/") {
  22. src = "/" + src ;
  23. }
  24.  
  25. return window.location.hostname + src;
  26. }
  27. return src;
  28. }
  29.  
  30. $(document).mousedown(function(event) {
  31. if ($(event.target).prop("tagName").toUpperCase() == "IMG"){
  32. if (window.event.shiftKey ){
  33. var origSrc = addHostInformationIfNeeded($(event.target).attr("src"));
  34. console.log("orig: " + origSrc);
  35. var src = "https://www.google.com/searchbyimage?image_url=" + origSrc;
  36. window.open(src);
  37. }
  38. }
  39. });
  40. })();