Search with google image fix

Search with google image again cause fuck google lens

当前为 2022-05-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Search with google image fix
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1.2.1
  5. // @description Search with google image again cause fuck 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.  
  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.  
  26. (function() {
  27.  
  28. GM_addStyle(`
  29. .container__menu {
  30. /* Absolute position */
  31. position: absolute;
  32.  
  33. /* Reset */
  34. list-style: none;
  35. margin: 0;
  36. padding: 0;
  37. display: none;
  38.  
  39. /* Misc */
  40. border: 1px solid #cbd5e0;
  41. border-radius: 0.25rem;
  42. background-color: #f7fafc;
  43. }
  44. `);
  45.  
  46.  
  47. GM_addStyle(`
  48. .open {
  49. display: block;
  50. z-index: 9999;
  51. }
  52. `);
  53.  
  54. GM_addStyle(`
  55. .container__item {
  56. padding: 0.5rem 1rem;
  57. white-space: nowrap;
  58. cursor: pointer;
  59. color: black;
  60. }
  61. `);
  62.  
  63. GM_addStyle(`
  64. .container__item:hover {
  65. background-color: #bee3f8;
  66. }
  67. `);
  68.  
  69. GM_addStyle(`
  70. .container__divider {
  71. border-bottom: 1px solid #cbd5e0;
  72. height: 1px;
  73. }
  74. `);
  75.  
  76.  
  77. $("body").append(`
  78. <ul id="fucklens" class="container__menu">
  79. <li class="container__item">Search with google image</li>
  80. </ul>
  81. `);
  82.  
  83. var cntxtMn = $("#fucklens");
  84. var mouseX;
  85. var mouseY;
  86. var currentTarget = null;
  87.  
  88. $(document).mousemove(function(e) {
  89. mouseX = e.pageX;
  90. mouseY = e.pageY;
  91. });
  92. $("img").on('contextmenu', displayContextMenu);
  93.  
  94.  
  95. const observer = new MutationObserver(function(mutations_list) {
  96. mutations_list.forEach(function(mutation) {
  97. mutation.addedNodes.forEach(function(added_node) {
  98. var img = $(added_node).find("img");
  99. if (img){
  100. img.on('contextmenu', displayContextMenu);
  101. }
  102. });
  103. });
  104. });
  105.  
  106. observer.observe(document, { subtree: true, childList: true });
  107.  
  108. //thank you for this guy https://jsfiddle.net/JCJDesigns/6zsvmt10/
  109. function displayContextMenu(e) {
  110. (cntxtMn.hasClass("open")) ? cntxtMn.removeClass("open") : false;
  111. if (e.ctrlKey)
  112. return;
  113. cntxtMn.css({'top':mouseY,'left':mouseX}).addClass("open");
  114. e.preventDefault();
  115. currentTarget = e.target;
  116. }
  117. cntxtMn.click(function(e) {
  118. e.stopPropagation();
  119. });
  120.  
  121. $(document).click(function() {
  122. (cntxtMn.hasClass("open")) ? cntxtMn.removeClass("open") : false;
  123. });
  124.  
  125. $(".container__item").click(function(){
  126. var src = "https://www.google.com/searchbyimage?image_url=" + $(currentTarget).prop("src");
  127. console.log($(currentTarget).prop("src"));
  128. (cntxtMn.hasClass("open")) ? cntxtMn.removeClass("open") : false;
  129. window.open(src);
  130. });
  131.  
  132.  
  133. })();