I am trying to edit the below javascript with jint. I really only want to edit var antiCapthaPredefinedApiKey = ''; and set the proxy settings in defaultConfig while at runtime. I have a winforms, I will be passing the two values into the method I call to edit it. Here is the 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
};
Here is my current code which executes, but it doesn't change the variable from what I can tell. I also haven't added editing the proxy settings first as I want to try to see if I can even change the api key variable. Once done I want to just save the file. This is my first time using jint so I am pretty inexperienced with it.
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);
}
After executing the line
engine.Execute(antiCap),defaultConfigis already evaluated and filled with the value ofantiCapthaPredefinedApiKeyat the time of the evaluation, which is an empty string. Changing the value ofantiCapthaPredefinedApiKeyafterwards won't affectdefaultConfig.To get what you want, do not define
antiCapthaPredefinedApiKeyin the JS file, and set its value using Jint before executing the script: