+
95
-

回答

在option中增加 reservedNames: ['^globalVariable1$'],假如你想要保留globalVariable1变量名不混淆。

  <script type="text/javascript">

const obfuscationResult = JavaScriptObfuscator.obfuscate(
    `
    var you="11";
    function test(){
      let   globalVariable1 = 'This will not be obfuscated';
        alert(globalVariable1);
    }
    alert(you);
    var globalVariable1 = 'This will not be obfuscated';
    var globalVariable2 = 'This will be obfuscated';
    `,
    {
        // 正则表达式匹配不被混淆的变量名
        reservedNames: ['^globalVariable1$'],
         compact: false,
                controlFlowFlattening: true,
                controlFlowFlatteningThreshold: 1,
                numbersToExpressions: true,
                simplify: true,
                stringArrayShuffle: true,
                splitStrings: true,
                stringArrayThreshold: 1,
                debugProtection: true,
        debugProtectionInterval: 2,
        disableConsoleOutput: false,
      domainLock:[] ,
    domainLockRedirectUrl:'about:blank',
    }
);

console.log(obfuscationResult.getObfuscatedCode());

    </script>

网友回复

我知道答案,我要回答