Reverse Image Search

Search largest image on the page or current image on Google, TinEye, Yandex, SauceNAO and iqdb.org

بۇ قوليازمىنى قاچىلاش؟
ئاپتورنىڭ تەۋسىيەلىگەن قوليازمىسى

سىز بەلكىم Github - Hide bots and github-actions from dashboards نى ياقتۇرۇشىڭىز مۇمكىن.

بۇ قوليازمىنى قاچىلاش
  1. // ==UserScript==
  2. // @name Reverse Image Search
  3. // @namespace github.com/cvzi/
  4. // @version 1.0.3
  5. // @description Search largest image on the page or current image on Google, TinEye, Yandex, SauceNAO and iqdb.org
  6. // @author cuzi
  7. // @copyright 2022, cuzi (https://github.com/cvzi/)
  8. // @license GPL-3.0-or-later
  9. // @match *://*/*
  10. // @icon https://raw.githubusercontent.com/hfg-gmuend/openmoji/master/color/72x72/1F5BC.png
  11. // @grant GM_openInTab
  12. // @grant GM_registerMenuCommand
  13. // ==/UserScript==
  14.  
  15. /*
  16. Reverse Image Search
  17. Search largest image on the page or current image on Google, TinEye, Yandex, SauceNAO and iqdb.org
  18. Copyright (C) 2022, cuzi (https://github.com/cvzi/)
  19.  
  20. This program is free software: you can redistribute it and/or modify
  21. it under the terms of the GNU General Public License as published by
  22. the Free Software Foundation, either version 3 of the License, or
  23. (at your option) any later version.
  24.  
  25. This program is distributed in the hope that it will be useful,
  26. but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. GNU General Public License for more details.
  29.  
  30. You should have received a copy of the GNU General Public License
  31. along with this program. If not, see <https://www.gnu.org/licenses/>.
  32. */
  33.  
  34. /* globals GM_openInTab, GM_registerMenuCommand */
  35. /* jshint asi: true, esversion: 8 */
  36.  
  37. (function () {
  38. 'use strict'
  39.  
  40. function onKeyDown (keyCode, cb) {
  41. return function (ev) {
  42. if (document.activeElement === document.body) {
  43. if (ev.ctrlKey && ev.key === keyCode) {
  44. ev.preventDefault()
  45. cb(ev)
  46. }
  47. }
  48. }
  49. }
  50.  
  51. function getUrl () {
  52. if (document && document.body && document.body.firstChild.tagName === 'IMG') {
  53. return document.location.href
  54. } else {
  55. const biggestImage = Array.from(document.querySelectorAll('img[src^=http],img[srcset]')).filter(img => img.src.startsWith('http')).map(img => {
  56. return {
  57. img,
  58. size: img.clientWidth + img.clientHeight + img.naturalHeight + img.naturalWidth
  59. }
  60. }).sort((a, b) => a.size - b.size).map(o => o.img.src).pop()
  61. if (biggestImage) {
  62. return biggestImage
  63. }
  64. }
  65. return document.location.href
  66. }
  67.  
  68. function google () {
  69. /* Google reverse image search */
  70. GM_openInTab('https://www.google.com/imghp?sbi=1#habibi=' + encodeURIComponent(getUrl()), { active: true })
  71. }
  72.  
  73. function tinEye () {
  74. /* TinEye reverse image search */
  75. GM_openInTab('https://tineye.com/search?url=' + encodeURIComponent(getUrl()))
  76. }
  77. function yandex () {
  78. /* Yandex reverse image search */
  79. GM_openInTab('https://yandex.com/images/search?rpt=imageview&url=' + encodeURIComponent(getUrl()))
  80. }
  81. function sauceNAO () {
  82. /* SauceNAO reverse image search */
  83. GM_openInTab('https://saucenao.com/search.php?url=' + encodeURIComponent(getUrl()))
  84. }
  85. function iqdb () {
  86. /* iqdb.org reverse image search */
  87. GM_openInTab('http://iqdb.org/?url=' + encodeURIComponent(getUrl()))
  88. }
  89.  
  90. GM_registerMenuCommand('Reverse Image Search - Google', google, 'g')
  91. GM_registerMenuCommand('Reverse Image Search - TinEye', tinEye, 'q')
  92. GM_registerMenuCommand('Reverse Image Search - Yandex', yandex, 'y')
  93. GM_registerMenuCommand('Reverse Image Search - SauceNAO', sauceNAO, 'x')
  94. GM_registerMenuCommand('Reverse Image Search - iqdb.org', iqdb, ',')
  95.  
  96. if (document && document.body && document.body.firstChild.tagName === 'IMG') {
  97. document.addEventListener('keydown', onKeyDown('g', google))
  98. document.addEventListener('keydown', onKeyDown('q', tinEye))
  99. document.addEventListener('keydown', onKeyDown('y', yandex))
  100. document.addEventListener('keydown', onKeyDown('x', sauceNAO))
  101. document.addEventListener('keydown', onKeyDown(',', iqdb))
  102. } else if (document.location.href.startsWith('/imghp') !== -1 && document.location.hash.startsWith('#habibi=')) {
  103. // Enter url into Google search form
  104. window.setTimeout(() => {
  105. const button = Array.from(document.querySelectorAll('[role="button"][jscontroller]>img[src],[role="button"][jscontroller]>svg')).pop()
  106. if (button.click) {
  107. button.click()
  108. } else {
  109. button.parentElement.click()
  110. }
  111. window.setTimeout(() => {
  112. document.querySelector('input[text=text]').value = decodeURIComponent(document.location.hash.substring(8))
  113. document.querySelector('input[text=text]').nextElementSibling.click()
  114. }, 500)
  115. }, 500)
  116. }
  117. })()