[INTERFACE]
DIALOG, "Сохранить JS скрипт", 657, 81;
STATIC, "Путь к папке", 4, 4, 68, 20;
EDIT, 76, 4, 400, 20, string Path;
BUTTON_PATH, "Выбрать путь для сохранения", 480, 4, 168, 20, Path;
BUTTON_OK, "Принять", 436, 32, 100, 20;
BUTTON_CANCEL, "Закрыть", 548, 32, 100, 20;
[END]

[APPEARANCE]
COLOR = 255, 125, 55;
SIZE_X = 10;
SIZE_Y =4;
[END]

[ASSOC_VAR]
Path=pathfolder()+"BrowserExtension\Chrome\";
[END]

[GLOBAL_VAR]
string Script_JS="";
string Var_JS="";
string Global_Var_C_JS="";
string Global_Var_B_JS="";
string Send_Global_Var_JS="";
string Call_Get_Fun_JS="";
string Get_Global_Var_JS="";
string Send_Back_Global_Var_JS = "";
string Get_Back_Global_Var_JS = "";
string All_Call_Send="";
string Global_Reflesh_Var_JS = "";
[END]


[FUNCTION_BODY]
function(string path)
{
string t_Script_JS="^r^n { ^r^nif (T==1) return;^r^nT=1;^r^nif (Date.now()<T_Pz+Pz){T=0; return;}^r^n";
t_Script_JS=t_Script_JS+"if (UpdatePade==2){if (T_OBN==1){" + "if (document.readyState == ^"complete^")" + "{UpdatePade=1; waiUpdatePade=1; addUpdatePade(); T=0; return;}}}^r^n";
t_Script_JS=t_Script_JS+"if (UpdatePade==2) {^r^n";
t_Script_JS=t_Script_JS+"if (waiUpdatePade-Date.now()<0){st=NUpdatePade; addNum(); " + "UpdatePade=1; waiUpdatePade=1; addUpdatePade(); T_Pz=Date.now(); Pz=1; addPz(); " + "wai=Date.now(); addWai(); T=0; All_Call_Send(); return;} T=0; return;}^r^n" + Script_JS;
t_Script_JS=t_Script_JS+"st=500; wai=1; T_Pz=Date.now(); Pz=1; UpdatePade=1; waiUpdatePade=1;^r^n";
t_Script_JS=t_Script_JS+"addNum(); addUpdatePade(); addPz(); addWai(); All_Call_Send();^r^n}^r^n";
string t, content="";
  if (fopen (path+"content_template.js", "r")!=0)
  {
  while (freadline (t))content=content+t+"^r^n";
  fclose();
  }
regexreplace(1, #content, content, "(?<=function Run\(\))([\s\S])+(?=/^/EndRun\(\))", t_Script_JS);
content=Global_Var_C_JS+Var_JS+Call_Get_Fun_JS+content+"^r^n"+Get_Global_Var_JS+Send_Global_Var_JS;
content=content+"function All_Call_Send()^r^n{^r^n"+All_Call_Send+"}";
content=ansitoutf8(content);
  if (fopen (path+"content.js", "w")!=0)
  {
  fwrite(content);
  fclose();
  }
content=Global_Var_B_JS;
  if (fopen (path+"background_template.js", "r")!=0)
  {
  while (freadline (t))content=content+t+"^r^n";
  fclose();
  }
regexreplace(1, #content, content, "if \(S==0\)", Get_Back_Global_Var_JS+"if (S==0)");
regexreplace(1, #content, content, "if \(S==0\)^r^n\{^r^n", "if (S==0)^r^n{^r^n"+Send_Back_Global_Var_JS);
regexreplace(1, #content, content, "chrome.runtime.reload\(\);", Global_Reflesh_Var_JS+"  chrome.runtime.reload();");
content=ansitoutf8(content);
  if (fopen (path+"background.js", "w")!=0)
  {
  fwrite(content);
  fclose();
  }
}
[END]

[CALL]
(Path)
[END]