Picture Downloader|Image Downloader|图片下载器

在页面顶部插入图片域名筛选框和下载按钮,根据关键词匹配图片URL并批量下载。默认针对所有站点开启,所以建议不需要时先禁用脚本,需要时再开启。

目前為 2017-07-30 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Picture Downloader|Image Downloader|图片下载器
// @namespace    https://tankywoo.com
// @version      0.1
// @description  在页面顶部插入图片域名筛选框和下载按钮,根据关键词匹配图片URL并批量下载。默认针对所有站点开启,所以建议不需要时先禁用脚本,需要时再开启。
// @author       Tanky Woo
// @include      http*://*/*
// @require      https://cdn.bootcss.com/jquery/3.2.1/jquery.js
// @grant        none
// @run-at       document-idle
// @license      MIT License
// ==/UserScript==

(function() {
  'use strict';
  // 说明:
  // - 现在很多网站的图片是延迟加载,需要手动看一遍加载后再点击下载
  $('body').prepend('<button type="button" class="download-btn">下载图片</button>');
  $('body').prepend('<input type="text" class="download-input" />');
  $('.download-btn').on('click', function() {
    var match_url = $(".download-input").val();
    var images = $('img').map(function(){
      return $(this).attr('src');
    }).get();

    // show all images
    $(images).each(function() {
      console.log(this);
    });

    $(images).each(function() {
      var image = this;
      if (image.indexOf(match_url) !== -1) {
        var a = $("<a>")
          .attr("href", image)
          .attr("download", "")
          .appendTo("body");
        a[0].click();
      }
    });
  });
})();