Greasy Fork

Greasy Fork is available in English.

Lofter原图下载助手

一键下载Lofter原图,将爬取所有原图

目前为 2024-02-19 提交的版本,查看 最新版本

// ==UserScript==
// @name         Lofter原图下载助手
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  一键下载Lofter原图,将爬取所有原图
// @author       Robert-Stackflow
// @match        *://*.lofter.com/*
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @require      https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js
// @grant        GM_info
// @grant        GM_download
// @grant        GM_openInTab
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_xmlhttpRequest
// @license      MIT
// ==/UserScript==
var $ = $ || window.$; //获得jquery的$标识符
const window_url = window.location.href;
const window_host = window.location.host;
(function() {
    'use strict';
  if (window_url.indexOf("lofter.com") != -1) {
    $("div[title='其他'] > div > div:nth-of-type(2) > div > div > a:nth-of-type(1) > span").html("大图/小图切换")
    $("div[title='其他'] > div > div:nth-of-type(2) > div > div > a:nth-of-type(1)").attr("href","javascript:void(0)")
    $("div[title='其他'] > div > div:nth-of-type(2) > div > div > a:nth-of-type(1)").click(function() {
      $("div.imgc > a > img").each(function () {
        $(this).click();
      });
    });
    $("div[title='其他'] > div > div:nth-of-type(2) > div > div > a:nth-of-type(2) > span").html("加载原图")
    $("div[title='其他'] > div > div:nth-of-type(2) > div > div > a:nth-of-type(2)").attr("href","javascript:void(0)")
    $("div[title='其他'] > div > div:nth-of-type(2) > div > div > a:nth-of-type(2)").click(function() {
      $("div.imgc > a > img").each(function () {
        var originUrl=getOrigin($(this))
        $(this).attr("src",originUrl);
      });
    });
    $("div[title='其他'] > div > div:nth-of-type(2) > div > div > a:nth-of-type(3) > span").html("下载所有图片")
    $("div[title='其他'] > div > div:nth-of-type(2) > div > div > a:nth-of-type(3)").attr("href","javascript:void(0)")
    $("div[title='其他'] > div > div:nth-of-type(2) > div > div > a:nth-of-type(3)").click(function() {
      var originUrls=[];
      $("div.imgc > a > img").each(function () {
        var originUrl=getOrigin($(this))
        if(originUrls.indexOf(originUrl)==-1)
          originUrls.push(originUrl)
      });
      for(let item of originUrls) {
        download(item);
      }
    });
    function getOrigin(img) {
      var url=img.attr("src");
      if(url==undefined)
        url=img.attr("imgsrc");
      return url.split("?imageView")[0];
    }
    function getName(url) {
      var list=url.split("/")
      return list[list.length-1]
    }
    function download(url){
      const x = new XMLHttpRequest()
      x.open("GET", url, true)
      x.responseType = 'blob'
      x.onload=function(e) {
        const url = window.URL.createObjectURL(x.response)
        const a = document.createElement('a')
        a.href = url
        a.target = '_blank'
        a.download = getName(url)
        a.click()
        a.remove()
      }
      x.send()
    }
  }
})();