img_adjust

picture adjuect to 1200 * 1200

当前为 2021-11-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         img_adjust
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  picture adjuect to 1200 * 1200
// @author       yao
// @match        
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @include      https://www.blu-ray.com/movies/*
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// ==/UserScript==

(function() {
    'use strict';
    console.log("aaa");
    $('#frontimage_overlay').hover(function(e){
        return handle(e,$(this));
    },function(){
        setTimeout(function(){ removeImage(); },1000);
    });

    function handle(e,element){
        showImage(e);
        return false;
    }

    //获取图片
    function showImage(e){
        $('#tempId').remove();
        var tempBtn = $('<button id = "tempId">1200*1200</button>');
        tempBtn.css({
            width:50,
            height:50,
            position:'absolute',
            top:e.pageY,
            left:e.pageX+30
        });
        $(tempBtn).click(doHandle);
        $('body').eq(0).append(tempBtn);
    }
    // Your code here...
})();


function removeImage(){
    console.log('开始移除图片');
    $('#tempId').remove();
}

function doHandle() {
    console.log("do");
    $('#triggers img').trigger('click');
    let src = $('#frontimage').attr('src');
    adjust(src);
}

function adjust(src) {
    var canvas = document.createElement('canvas');

    canvas.width = 1200;
    canvas.height = 1200;

    var ctx = canvas.getContext('2d');

    ctx.fillStyle = "#fff";
    ctx.fillRect(0,0,canvas.width,canvas.height);
    let img = new Image;
    img.onload = _ => {
        console.log(img.naturalWidth, img.naturalHeight);
        let max = Math.max(img.naturalHeight, img.naturalWidth);
        let ratio = img.naturalWidth / img.naturalHeight;
        if (max === img.naturalHeight) {
            img.width = 300 * ratio;
            let height = 1200;
            let width = 1200 * ratio;
            ctx.drawImage(img, (1200 - width) / 2, 0, width, height);
            console.log("download");
            download(canvas);
        }
    }
    img.src = src;
    img.setAttribute("crossOrigin", "Anonymous");
}

function download(canvas) {
    let dom = document.createElement("a");
    dom.href = canvas.toDataURL("image/jpeg");
    dom.download = new Date().getTime() + ".jpg";
    dom.click();
}