【问题标题】:Editing .js with Jint使用 Jint 编辑 .js
【发布时间】:2021-09-02 00:50:14
【问题描述】:

我正在尝试使用 jint 编辑以下 javascript。我真的只想在运行时编辑var antiCapthaPredefinedApiKey = ''; 并在defaultConfig 中设置代理设置。我有一个 winforms,我会将这两个值传递给我调用的方法来编辑它。这是js,

// Public config

var antiCapthaPredefinedApiKey = '';

var defaultConfig = {
    // settings
    enable: true,
    account_key: antiCapthaPredefinedApiKey,
    auto_submit_form: true,
    play_sounds: false,
    delay_onready_callback: false,

    where_solve_list: [], // i.e. ['example.com', 'www.ladysproblems.com']
    where_solve_white_list_type: false, // true -- considered as white list, false -- black list

    solve_recaptcha2: true,
    solve_recaptcha3: true,
    recaptcha3_score: 0.3,
    solve_invisible_recaptcha: true,
    solve_funcaptcha: true,
    solve_geetest: true,
    solve_hcaptcha: true,
    use_predefined_image_captcha_marks: true,

    solve_proxy_on_tasks: false,
    user_proxy_protocol: 'HTTP',
    user_proxy_server: '',
    user_proxy_port: '',
    user_proxy_login: '',
    user_proxy_password: '',

    use_recaptcha_precaching: false,
    k_precached_solution_count_min: 2,
    k_precached_solution_count_max: 4,

    dont_reuse_recaptcha_solution: true,
    start_recaptcha2_solving_when_challenge_shown: false,
    solve_only_presented_recaptcha2: false,

    // use_recaptcha_accelerator: false,

    // status
    account_key_checked: antiCapthaPredefinedApiKey ? true : false, // set after account_key check
    free_attempts_left_count: 15 // move to config
};

这是我当前执行的代码,但它不会改变我所知道的变量。我也没有先添加编辑代理设置,因为我想尝试查看是否可以更改 api 键变量。完成后,我只想保存文件。这是我第一次使用jint,所以我对它非常缺乏经验。

        public static void ReadJsFile(string api, string proxy)
        {
            string workingDirectory1 = Environment.CurrentDirectory;
            string filePath = workingDirectory1 + "\\anticaptcha\\js\\config_ac_api_key.js";

            var engine = new Engine();

            var antiCap = File.ReadAllText(filePath);
            engine.Execute(antiCap);

            engine.SetValue("antiCapthaPredefinedApiKey", api);      
        }

【问题讨论】:

    标签: javascript c# jint


    【解决方案1】:

    在执行engine.Execute(antiCap)这一行后,defaultConfig已经被求值并填充了求值时antiCapthaPredefinedApiKey的值,它是一个空字符串。之后更改antiCapthaPredefinedApiKey 的值不会影响defaultConfig。

    要得到你想要的,不要在JS文件中定义antiCapthaPredefinedApiKey,在执行脚本之前使用Jint设置它的值:

    public static void ReadJsFile(string api, string proxy)
    {
        string workingDirectory1 = Environment.CurrentDirectory;
        string filePath = workingDirectory1 + "\\anticaptcha\\js\\config_ac_api_key.js";
        var engine = new Engine();
        var antiCap= File.ReadAllText(filePath);
        engine.SetValue("antiCapthaPredefinedApiKey", api);
        engine.Execute(antiCap);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-06
      • 1970-01-01
      • 2014-12-30
      • 2017-05-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多