google origin image download

快速下载谷歌图片搜索原图

As of 2021-06-02. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

  1. // ==UserScript==
  2. // @name google origin image download
  3. // @namespace http://zxctp.top
  4. // @version 0.3
  5. // @description 快速下载谷歌图片搜索原图
  6. // @author tao
  7. // @include /^https?://(?:www|encrypted|ipv[46])\.google\.[^/]+/(?:$|[#?]|search|webhp|imgres)/
  8. // @grant GM_download
  9. // @grant GM_xmlhttpRequest
  10. // @require https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.slim.min.js
  11. // @run-at document-idle
  12. // @connect *
  13. // ==/UserScript==
  14.  
  15. (function(){
  16. 'use strict';
  17.  
  18. var allImgPanel = $('#islrg').find('.islrc');
  19.  
  20. function handleTag(){
  21. var aTags = allImgPanel.find('div a.wXeWr[data-lanling-mark!=1]');
  22.  
  23. function handleOpen(event, url, el){
  24. event.stopPropagation();
  25. event.preventDefault();
  26. el.text('图片地址已访问').css({ 'color': 'blue' });
  27. window.open(url);
  28. }
  29.  
  30. function handleDownload(event, el){
  31. if($(el).attr('href')){
  32. event.stopPropagation();
  33. event.preventDefault();
  34. }
  35.  
  36. setTimeout(function(){
  37. if($(el).find('div[data-lanling-mark=1]').length !== 0){
  38. $(el).find('div[data-lanling-mark=1]').remove();
  39. }
  40. var marked = $('<div data-lanling-mark="1" style="position:absolute;top:10px;left:10px;z-index:9999;background:blue;padding:5px;color:#fff;">正在下载 0%</div>');
  41. $(el).append(marked);
  42. var url = $(el).attr('href');
  43. var query = url.split('?')[1];
  44. var imgParam = query.split('&')[0];
  45. var imgUrl = unescape(imgParam.split('=')[1]);
  46. GM_download({
  47. url: imgUrl,
  48. name: escape(imgUrl),
  49. onprogress: function(e){
  50. var progress = '';
  51. if(e.totalSize <= 0){
  52. progress = ''
  53. }else{
  54. progress = (e.loaded / e.totalSize) * 100;
  55. }
  56. marked.text('正在下载...' + progress.toFixed(2) +'%').css({ 'background': 'blue' });
  57. },
  58. onerror: function(){
  59. var tip = $('<div style="text-decoration:underline;">图片地址</div>');
  60. tip.on('click', (event) => handleOpen(event, imgUrl, tip));
  61.  
  62. marked.text('下载失败,请手动保存!').css({ 'background': 'red' });
  63. marked.append(tip);
  64. },
  65. onload: function(){
  66. marked.text('下载成功').css({ 'background': 'green' });
  67. }
  68. });
  69. });
  70. }
  71.  
  72. aTags.each(function(){
  73. var downloadBtn = $('<button style="position:absolute;top:10px;right:10px;z-index:9999;">下载</button>');
  74. downloadBtn.on('click', (event) => handleDownload(event, this));
  75. $(this).append(downloadBtn);
  76. $(this).attr('data-lanling-mark', '1');
  77. })
  78. }
  79.  
  80. var tagBtn = $('<button style="position:fixed;top:0;left:0;z-index:9999;">添加下载按钮</button>');
  81. tagBtn.on('click', handleTag);
  82. $('body').append(tagBtn);
  83. })();