搜同爬图片

搜同爬图片漫画

目前为 2021-11-21 提交的版本。查看 最新版本

// ==UserScript==
// @name         搜同爬图片
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  搜同爬图片漫画
// @author       Aelous
// @match        soutong.men/*
// @license      MIT
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant       unsafeWindow
// @grant       GM.xmlHttpRequest
// @grant       GM.setClipboard
// @grant       GM.setValue
// @grant       GM.getValue
// @grant       GM_addStyle
// @grant       GM_xmlhttpRequest
// @grant       GM_setClipboard
// @grant       GM_setValue
// @grant       GM_getValue
// @require     https://cdn.bootcdn.net/ajax/libs/jquery/2.2.4/jquery.min.js
// @require     https://cdn.bootcss.com/jszip/3.1.4/jszip.min.js
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    (function () {
        var num = document.getElementsByTagName('ignore_js_op').length
        console.log('总共'+ num + '条')
        console.log($('.ts a').text() + $('.ts #thread_subject').text() )
        if(num <= 10){
            $('#thread_subject').after('<button id="pic_download" style="margin-left: 10px;background: #f5d4d4;border-radius: 5px;">下载图片</button>')
        } else {
            var page = parseInt(num / 10) + 1;
            for (let index = page - 1 ; index >= 0 ; index--) {
                $('#thread_subject').after('<button id="pic_downloads" class = "pic_'+ index +'" style="margin-left: 10px;background: #545151;border-radius: 5px;color: white;">下载图片'+ index +'</button>')
            }
        }
       
    })();

    $('body').on('click', '#pic_download', function () {
        down(0,0)
    });

    $('body').on('click', '#pic_downloads', function () {
        var className = $(this).attr("class")
        className = className.replace('pic_','')
        console.log(className);
        down(className * 10 - 1,className * 10 + 10)
    });

    $('body').on('click', '#thread_subject', function () {
        copyToClipboard($('.ts a').text() + $('.ts #thread_subject').text())
    });

    function down(n,m){
        var imgs = document.images;
        var num = 1;
        for (var i = 0; i < imgs.length;i++){
            var id = imgs[i].id
            if(id.indexOf("aimg_") != -1){
                var src = imgs[i].src
                if(src!=''){
                  let xhr = new XMLHttpRequest()
                  let fileName = num + '.jpg' // 文件名称 
                  xhr.open('GET', src, true)
                  xhr.responseType = 'arraybuffer'
                  xhr.onload = function() {
                    if (this.status === 200) {
                      let type = xhr.getResponseHeader('Content-Type')
    
                      let blob = new Blob([this.response], {type: type})
                      if (typeof window.navigator.msSaveBlob !== 'undefined') {
                        /*
                         * IE workaround for "HTML7007: One or more blob URLs were revoked by closing
                         * the blob for which they were created. These URLs will no longer resolve as 
                         * the data backing the URL has been freed." 
                         */
                        window.navigator.msSaveBlob(blob, fileName)
                      } else {
                        let URL = window.URL || window.webkitURL
                        let objectUrl = URL.createObjectURL(blob)
                        if (fileName) {
                          var a = document.createElement('a')
                          // safari doesn't support this yet
                          if (typeof a.download === 'undefined') {
                            window.location = objectUrl
                          } else {
                            a.href = objectUrl
                            a.download = fileName
                            document.body.appendChild(a)
                            a.click()
                            a.remove()
                          }
                        } else {
                          window.location = objectUrl
                        }
                      }
                    }
                  }
                  if( n == 0 && m == 0){
                    xhr.send()
                  }
                  if(m != 0 && m >num && n < num){
                      xhr.send()
                  }
                  if( n!=0 && n < num && m == 0) {
                     xhr.send()
                  }
                  num = num + 1
                }
            }
        }
    }

    function copyToClipboard(s){
        if(window.clipboardData){
            window.clipboardData.setData('text',s);
        }else{
            (function(s){
                document.oncopy=function(e){
                    e.clipboardData.setData('text',s);
                    e.preventDefault();
                    document.oncopy=null;
                }
            })(s);
            document.execCommand('Copy');
        }
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址