分类 javascript 下的文章

(function () {
    const originalSend = XMLHttpRequest.prototype.send;
    const originalOpen = XMLHttpRequest.prototype.open;

    XMLHttpRequest.prototype.open = function (method, url, async, user, password) {
        this._url = url;   // 保存请求 URL 以便后续使用
        this._method = method;
        this._async = async;
        originalOpen.apply(this, arguments);  // 保持原来的 open 方法
    };

    XMLHttpRequest.prototype.send = function (body) {
        const xhr = this;  // 保存当前 XMLHttpRequest 对象的引用

        console.log('拦截到 XHR 请求的响应:', xhr.responseText);
        // 拦截 onreadystatechange,获取响应数据
        xhr.addEventListener('readystatechange', function () {
            if (xhr.readyState === 4) {  // readyState 4 表示请求已完成
                console.log('拦截到 XHR 请求的响应:', xhr.responseText);

                // 在这里你可以对响应数据进行处理
                // alert(xhr.responseText)
                //拦截指定的url
                if (xhr._url.includes('keyword')) {
                    console.log(JSON.parse(xhr.responseText).data)
                }
            }
        });

        // 调用原始 send 方法
        originalSend.apply(this, arguments);
    };
})();

let selects = document.getElementsByTagName("select");
  if (selects.length !== selectAnswer.length) {
    layer.msg("页面上的题可能已经发生了变化", { icon: 0 });
    return;
  }
  let lastScope = NaN;
  let idx = -1;
  // 获取Angular作用域
  selectAnswer.forEach((answer, index) => {
    let scope = angular.element(selects[index]).scope();
    // console.log(scope.subject.sub_subjects);
    // console.log(lastScope === scope, lastScope);
    if (idx === -1) {
      idx = 0;
    } else if (lastScope === scope) {
      idx += 1;
    } else {
      idx = 0;
    }
    lastScope = scope;

    //angular.element(document.getElementsByTagName("select")[0]).scope().subject.sub_subjects;
    scope.$apply(() => {
      console.log(scope.subject.sub_subjects[idx]);
      let old = scope.subject.sub_subjects[idx].answeredOption;
      scope.subject.sub_subjects[idx].answeredOption = answer;
      scope.onChangeSubmission(scope.subject.sub_subjects[idx]);

      console.log(scope.subject.sub_subjects[idx]);
      console.log(
        `old: ${old},new:${answer}, now:${scope.subject.sub_subjects[idx].answeredOption}`,
      );
    });
    $(selects[index]).multiselect("refresh");
    angular.element(selects[index]).triggerHandler("change");
  });

安装依赖

pnpm install --save-dev rollup-plugin-obfuscator javascript-obfuscator

配置

// ...
import obfuscatorBox from 'rollup-plugin-obfuscator';

import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite';
import {ArcoResolver} from 'unplugin-vue-components/resolvers';
import obfuscatorBox from 'rollup-plugin-obfuscator';

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        //...
        obfuscatorBox({
            global: true,
            options: {
                compact: true,
                controlFlowFlattening: true,
                controlFlowFlatteningThreshold: 0.75,
                numbersToExpressions: true,
                simplify: true,
                stringArrayShuffle: true,
                splitStrings: true,
                splitStringsChunkLength: 10,
                rotateUnicodeArray: true,
                deadCodeInjection: true,
                deadCodeInjectionThreshold: 0.4,
                debugProtection: false,
                debugProtectionInterval: 2000,
                disableConsoleOutput: true,
                domainLock: [],
                identifierNamesGenerator: "hexadecimal",
                identifiersPrefix: "",
                inputFileName: "",
                log: true,
                renameGlobals: true,
                reservedNames: [],
                reservedStrings: [],
                seed: 0,
                selfDefending: true,
                sourceMap: false,
                sourceMapBaseUrl: "",
                sourceMapFileName: "",
                sourceMapMode: "separate",
                stringArray: true,
                stringArrayEncoding: ["base64"],
                stringArrayThreshold: 0.75,
                target: "browser",
                transformObjectKeys: true,
                unicodeEscapeSequence: true,


                domainLockRedirectUrl: "about:blank",
                forceTransformStrings: [],
                identifierNamesCache: null,
                identifiersDictionary: [],
                ignoreImports: true,
                optionsPreset: "default",
                renameProperties: false,
                renamePropertiesMode: "safe",
                sourceMapSourcesMode: "sources-content",

                stringArrayCallsTransform: true,
                stringArrayCallsTransformThreshold: 0.5,

                stringArrayIndexesType: ["hexadecimal-number"],
                stringArrayIndexShift: true,
                stringArrayRotate: true,
                stringArrayWrappersCount: 1,
                stringArrayWrappersChainedCalls: true,
                stringArrayWrappersParametersMaxCount: 2,
                stringArrayWrappersType: "variable",
            },
            apply: 'build' // 仅在生产环境下使用
        }),
    ],
//...
})

安装 crypto-js

pnpm install crypto-js

代码

import * as CryptoJS from 'crypto-js';


export async function decryptText(text: string): Promise<string> {
    // 16进制
    const keyHex = "cb69976b953380e5ff637b0bf9af35fdf1a56815c81296b3e5314e506d209a05";
    const ivHex = 'a312cc7df85e4d26dc65fb4f3fe82919'
    // console.log(`text: ${text}`)
    // Convert hex strings to Uint8Array
    const keyArray = new Uint8Array(
        keyHex.match(/.{1,2}/g).map(byte => parseInt(byte, 16))
    );
    const ivArray = new Uint8Array(
        ivHex.match(/.{1,2}/g).map(byte => parseInt(byte, 16))
    );

    const encryptedData = hexStringToByteArray(text)

    // AES decryption using crypto-js
    const decryptedData = CryptoJS.AES.decrypt(
        {
            ciphertext: CryptoJS.enc.Hex.parse(
                Array.from(encryptedData).map(byte => ('0' + (byte & 0xFF).toString(16)).slice(-2)).join('')
            )
        },
        CryptoJS.enc.Hex.parse(
            Array.from(keyArray).map(byte => ('0' + byte.toString(16)).slice(-2)).join('')
        ),
        {
            iv: CryptoJS.enc.Hex.parse(
                Array.from(ivArray).map(byte => ('0' + byte.toString(16)).slice(-2)).join('')
            ),
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7,
        }
    );

    return decryptedData.toString(CryptoJS.enc.Utf8)
}