下黄图

下黄图,自用

Versione datata 14/05/2021. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         下黄图
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  下黄图,自用
// @author       You
// @match        http://www.177pic.info/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    /**
     * 通过图片链接获取base64
     * @param url   //图片链接
     * @param ext   //图片格式
     * @param callback  //回调函数,回调base64
     */
    function getUrlBase64(url, ext, callback) {
        var canvas = document.createElement("canvas");   //创建canvas DOM元素
        var ctx = canvas.getContext("2d");
        var img = new Image;
        img.crossOrigin = 'Anonymous';
        img.src = url;
        img.onload = function () {
            console.log(img.height+","+img.width);
            canvas.height = img.height; //指定画板的高度,自定义
            canvas.width = img.width; //指定画板的宽度,自定义
            ctx.drawImage(img, 0, 0, img.width, img.height); //参数可自定义
            var dataURL = canvas.toDataURL("image/" + ext);
            callback.call(this, dataURL); //回掉函数获取Base64编码
            canvas = null;
        };
    }
    $("body").prepend("<button id='downloadH' style='z-index:999999999;position: absolute;'>开始下H图</button>");
    $("#downloadH").click(function(){
       $(".single-content").find("img").each(function(){
          var imgurl = $(this).attr("src");
	      let link = document.createElement('a');
          link.download = imgurl.substring(imgurl.lastIndexOf("/")+1); 	//下载的资源重命名
          getUrlBase64(imgurl, 'jpg', function (base64Url) {
          link.href = base64Url;
          link.click();
          });
    })
    });
})();