Advertisement
Inquisitor

Vichan reverse image search

Nov 14th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. onready(function(){
  2.  
  3.     var googlesearch = 'https://images.google.com/searchbyimage?image_url=';
  4.     var host = window.location.hostname;
  5.  
  6.     var add_imgsearch = function(elem) {
  7.         var images = elem.querySelectorAll(".fileinfo > a"); // Получаем все прямые ссылки на файлы
  8.         for(var i = 0; i < images.length; i++) {
  9.             var search_link = document.createElement('a');
  10.             search_link.setAttribute('target', '_blank');
  11.             search_link.setAttribute('href', googlesearch + host + images[i].getAttribute('href'));
  12.             search_link.setAttribute('class', 'fa fa-search');
  13.             search_link.setAttribute('style', 'text-decoration:none');
  14.  
  15.             images[i].parentNode.insertBefore(search_link, images[i].nextSibling);
  16.         };
  17.     };
  18.  
  19.     add_imgsearch(document); // Добавляем ссылки к пикчам
  20.    
  21.     if (window.jQuery) { // Добавляем ссылки к пикчам при аякс-подгрузке
  22.         $(document).on('new_post', function(e, post) {
  23.             add_imgsearch(post);
  24.         });
  25.     }
  26.  
  27. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement