Search with google image fix

Search with google image again cause fuck google lens

当前为 2022-04-16 提交的版本,查看 最新版本

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