🏠 返回首頁 

Greasy Fork is available in English.

Search with google image fix

Search with google image again cause #### google lens

  1. // ==UserScript==
  2. // @name Search with google image fix
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1.4
  5. // @description Search with google image again cause #### google lens
  6. // @author You
  7. // @require http://code.jquery.com/jquery-3.4.1.min.js
  8. // @match http://*/*
  9. // @match https://*/*
  10. // @exclude https://www.instant-gaming.com/*
  11. // @grant none
  12. // ==/UserScript==
  13. var invert = true;
  14. function GM_addStyle(css) {
  15. const style = document.getElementById("GM_addStyle") || (function() {
  16. const style = document.createElement('style');
  17. style.type = 'text/css';
  18. style.id = "GM_addStyle";
  19. document.head.appendChild(style);
  20. return style;
  21. })();
  22. const sheet = style.sheet;
  23. sheet.insertRule(css, (sheet.rules || sheet.cssRules || []).length);
  24. }
  25. (function() {
  26. GM_addStyle(`
  27. .container__menu {
  28. /* Absolute position */
  29. position: absolute;
  30. /* Reset */
  31. list-style: none;
  32. margin: 0;
  33. padding: 0;
  34. display: none;
  35. /* Misc */
  36. border: 1px solid #cbd5e0;
  37. border-radius: 0.25rem;
  38. background-color: #f7fafc;
  39. }
  40. `);
  41. GM_addStyle(`
  42. .open {
  43. display: block;
  44. z-index: 9999;
  45. }
  46. `);
  47. GM_addStyle(`
  48. .container__item {
  49. padding: 0.5rem 1rem;
  50. white-space: nowrap;
  51. cursor: pointer;
  52. color: black;
  53. }
  54. `);
  55. GM_addStyle(`
  56. .container__item:hover {
  57. background-color: #bee3f8;
  58. }
  59. `);
  60. GM_addStyle(`
  61. .container__divider {
  62. border-bottom: 1px solid #cbd5e0;
  63. height: 1px;
  64. }
  65. `);
  66. $("body").append(`
  67. <ul id="####lens" class="container__menu">
  68. <li class="container__item">Search with google image</li>
  69. </ul>
  70. `);
  71. var cntxtMn = $("#####lens");
  72. var mouseX;
  73. var mouseY;
  74. var currentTarget = null;
  75. $(document).mousemove(function(e) {
  76. mouseX = e.pageX;
  77. mouseY = e.pageY;
  78. });
  79. $("img").on('contextmenu', displayContextMenu);
  80. const observer = new MutationObserver(function(mutations_list) {
  81. mutations_list.forEach(function(mutation) {
  82. mutation.addedNodes.forEach(function(added_node) {
  83. var img = $(added_node).find("img");
  84. if (img){
  85. img.on('contextmenu', displayContextMenu);
  86. }
  87. });
  88. });
  89. });
  90. observer.observe(document, { subtree: true, childList: true });
  91. //thank you for this guy https://jsfiddle.net/JCJDesigns/6zsvmt10/
  92. function displayContextMenu(e) {
  93. (cntxtMn.hasClass("open")) ? cntxtMn.removeClass("open") : false;
  94. /*
  95. If inverte is true then ctrl key = special menu
  96. if invert is false then ctrl key = skip
  97. */
  98. if (invert == false && e.ctrlKey)
  99. return;
  100. else if (e.ctrlKey && invert)
  101. {
  102. cntxtMn.css({'top':mouseY,'left':mouseX}).addClass("open");
  103. e.preventDefault();
  104. currentTarget = e.target;
  105. return;
  106. }
  107. else if (invert == false){
  108. cntxtMn.css({'top':mouseY,'left':mouseX}).addClass("open");
  109. e.preventDefault();
  110. currentTarget = e.target;
  111. }
  112. }
  113. cntxtMn.click(function(e) {
  114. e.stopPropagation();
  115. });
  116. $(document).click(function() {
  117. (cntxtMn.hasClass("open")) ? cntxtMn.removeClass("open") : false;
  118. });
  119. $(".container__item").click(function(){
  120. var src = "https://lens.google.com/uploadbyurl?url=" + $(currentTarget).prop("src");
  121. console.log($(currentTarget).prop("src"));
  122. (cntxtMn.hasClass("open")) ? cntxtMn.removeClass("open") : false;
  123. window.open(src);
  124. });
  125. })();