坦克现形

可以让无影坦克现形

目前為 2021-02-06 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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

(function () {
    'use strict';

    // 1. 获取当前页面下的所有图片
    let imgs = document.querySelectorAll('img');
    // 2. 遍历所有图片,将图片替换为幻影坦克后图片
    imgs.forEach(img => {
        console.log('开始现形,原图地址:', img.src);
        show(img);
    });


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