Greasy Fork

Greasy Fork is available in English.

坦克现形

可以让无影坦克现形

目前为 2021-02-07 提交的版本。查看 最新版本

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

(function () {
    'use strict';

    document.body.onmouseover = function (e) {
        if (e.target.tagName === 'IMG') {
            show(e.target);
        }
    }

    /**
     * 将无影坦克现形
     * @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;
    }
})();