Greasy Fork

Greasy Fork is available in English.

坦克现形

可以让无影坦克现形

当前为 2021-02-06 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         坦克现形
// @namespace    blog.site.xiaobu
// @version      0.3
// @description  可以让无影坦克现形
// @author       xiaobu
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    $('body').on('mouseenter','img',function (){
        console.log($(this),'现形');
        show($(this)[0]);
    });


    /**
     * 将无影坦克现形
     * @param select 选择器
     * */
    function show(select) {
        let can = document.createElement("canvas");
        let con = can.getContext("2d");
        let img = new Image();
        img.crossOrigin = 'Anonymous';
        img.src = select.src;
        img.onload = function () {
            can.width = img.width;
            can.height = img.height;
            con.drawImage(img, 0, 0);
            let imgData = con.getImageData(0, 0, img.width, img.height);
            let list = de(imgData.data[2] % 8, imgData);
            let file = new File([list[1].buffer], utf8Decode(list[0][1]), {type: list[0][2]})
            let path = URL.createObjectURL(file);
            select.href = path;
            select.src = path;
            select.style.display = "block";
            select.innerHTML = file;
        }
    }

    /**
     * 解密图像主代码
     * */
    function de(mode, imgdata) {
        let aa = Math.ceil(3 * mode / 8);
        let n = imgdata.width * imgdata.height;
        let j = 0;
        let k = "";
        let i = 1;
        let mlist = [1, 2, 4, 8, 16, 32, 64, 128];
        let word = "";
        let blist//=new Uint8Array();
        let blength = 0;
        while (i < n && (word.length === 0 || word.slice(-1).charCodeAt(0) > 0)) {
            k = k + (imgdata.data[4 * i] + 256).toString(2).slice(-mode);
            k = k + (imgdata.data[4 * i + 1] + 256).toString(2).slice(-mode);
            k = k + (imgdata.data[4 * i + 2] + 256).toString(2).slice(-mode);
            i++
            for (let ii = 0; ii < aa; ii++) {
                if (k.length >= 8 && (word.length === 0 || word.slice(-1).charCodeAt(0) > 0)) {
                    word = word + String.fromCharCode(parseInt(k.slice(0, 8), 2));
                    k = k.slice(8);
                }
            }
        }
        // word分隔符:","
        blength = parseInt(word.split(String.fromCharCode(1))[0]);
        if (!(blength > -1)) {
            throw "error"
        }
        if (!(word.split(String.fromCharCode(1)).length > 2)) {
            throw "error"
        }
        blist = new Uint8Array(blength);
        if (k.length >= 8 && j < blength) {
            blist[j] = parseInt(k.slice(0, 8), 2);
            k = k.slice(8);
            j++
        }
        while (i < n && j < blength) {
            k = k + (imgdata.data[4 * i] + 256).toString(2).slice(-mode);
            k = k + (imgdata.data[4 * i + 1] + 256).toString(2).slice(-mode);
            k = k + (imgdata.data[4 * i + 2] + 256).toString(2).slice(-mode);
            i++
            for (let ii = 0; ii < aa; ii++) {
                if (k.length >= 8 && j < blength) {
                    blist[j] = parseInt(k.slice(0, 8), 2);
                    k = k.slice(8);
                    j++
                }
            }
        }
        return [word.split(String.fromCharCode(0))[0].split(String.fromCharCode(1)), blist]
    }

    /* utf8 加密 */
    function utf8Encode(string) {
        let utftext = "";
        for (let n = 0; n < string.length; n++) {
            let c = string.charCodeAt(n);
            if (c < 128) {
                utftext += String.fromCharCode(c);
            } else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            } else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }
        }
        return utftext;
    }

    /* utf8 解密 */
    function utf8Decode(inputStr) {
        let outputStr = "";
        let code1, code2, code3, code4;
        for (let i = 0; i < inputStr.length; i++) {
            code1 = inputStr.charCodeAt(i);
            if (code1 < 128) {
                outputStr += String.fromCharCode(code1);
            } else if (code1 < 224) {
                code2 = inputStr.charCodeAt(++i);
                outputStr += String.fromCharCode(((code1 & 31) << 6) | (code2 & 63));
            } else if (code1 < 240) {
                code2 = inputStr.charCodeAt(++i);
                code3 = inputStr.charCodeAt(++i);
                outputStr += String.fromCharCode(((code1 & 15) << 12) | ((code2 & 63) << 6) | (code3 & 63));
            } else {
                code2 = inputStr.charCodeAt(++i);
                code3 = inputStr.charCodeAt(++i);
                code4 = inputStr.charCodeAt(++i);
                outputStr += String.fromCharCode(((code1 & 7) << 18) | ((code2 & 63) << 12) | ((code3 & 63) << 6) | (code2 & 63));
            }
        }
        return outputStr;
    }
})();