-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUnit1.cpp
229 lines (206 loc) · 7.07 KB
/
Unit1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <memory>
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SHDocVw_OCX"
#pragma resource "*.dfm"
TMainForm *MainForm;
int Step = 0;
String LastTime = "";
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
//Настройки
MainForm->Caption = Application->Title;
Tray->Hint = Application->Title;
}
//---------------------------------------------------------------------------
void TMainForm::OneStart(bool minimized)
{
MainForm->AlphaBlend = false;
ShowWeb();
MainForm->Position = poScreenCenter;
StatusBar->SimpleText = "Статус: открываю hh.ru ...";
Navigate(Domain + "locale?language=RU");
StartTimer->Enabled = true;
HelpLabel->Caption = "Авторизуйтесь на сайте в этом браузере, после чего программа начнет работу.";
StatusBar->SimpleText = "Статус: проверяю авторизацию ...";
if (minimized == true) {
Application->Minimize();
ShowWindow(Handle, SW_HIDE);
Tray->Visible = true;
}
}
//---------------------------------------------------------------------------
void TMainForm::Navigate(String URL)
{
try {
Web->Navigate(WideString(URL).c_bstr());
}
catch(...) {}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::StartTimerTimer(TObject *Sender)
{
Web->ExecuteScript("function check_auth() { let link = document.querySelectorAll('.supernova-link'); link = Array.from( link ).filter( e => (/Мои резюме/i).test( e.textContent ) ); return(link.length); } check_auth();");
if(Web->LocationURL.Pos("login")) {
StatusBar->SimpleText = "Статус: жду авторизации пользователя ...";
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::MainTimerTimer(TObject *Sender)
{
// переход в "Мои резюме"
if(Step == 0) {
Navigate(Domain + "applicant/resumes");
Step = 1;
return;
}
// проверка авторизации
if(Step == 1) {
Web->ExecuteScript("function check_auth() { let link = document.querySelectorAll('.supernova-link'); link = Array.from( link ).filter( e => (/Мои резюме/i).test( e.textContent ) ); return(link.length); } check_auth();");
return;
}
if(Step == 2) {
//Считаем кол-во доступных резюме для поднятия
Web->ExecuteScript("function check_resumes_col() { let link = document.querySelectorAll('.bloko-link'); link = Array.from( link ).filter( e => (/Поднять в поиске/i).test( e.textContent ) ); return(link.length); } check_resumes_col();");
return;
}
if(Step == 3) {
// поднимаем резюме в поиске
StatusBar->SimpleText = "Статус: поднимаю резюме в поиске.";
Web->ExecuteScript("function update_resumes() { let link = document.querySelectorAll('.bloko-link'); link = Array.from( link ).filter( e => (/Поднять в поиске/i).test( e.textContent ) ); link.forEach((el) => { el.click(); }); } update_resumes();");
return;
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::LongTimerTimer(TObject *Sender)
{
LongTimer->Enabled = false;
Step = 0;
MainTimer->Enabled = true;
}
//---------------------------------------------------------------------------
void TMainForm::ClearMemory()
{
try {
THandle MainHandle;
HANDLE ProcessHandle, ThreadHandle;
DWORD ProcessID = GetCurrentProcessId();
ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, false, ProcessID);
SetProcessWorkingSetSize(ProcessHandle, DWORD(-1), DWORD(-1));
CloseHandle(ProcessHandle);
}
catch(...) {}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ApplicationEventsMinimize(TObject *Sender)
{
Application->Minimize();
ShowWindow(Handle, SW_HIDE);
Tray->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::TrayClick(TObject *Sender)
{
Tray->Visible = false;
Application->Restore();
ShowWindow(Handle, SW_SHOW);
MainForm->FormStyle = fsStayOnTop;
MainForm->FormStyle = fsNormal;
}
//---------------------------------------------------------------------------
void TMainForm::ShowWeb()
{
Web->Align = alTop;
MainForm->Height = 685;
HelpLabel->Top = 606;
Web->ClientHeight = 600;
Web->Visible = true;
}
//---------------------------------------------------------------------------
void TMainForm::HideWeb()
{
Web->Visible = false;
HelpLabel->Top = 5;
MainForm->Height = 75;
Web->Navigate(L"edge://");
ClearMemory();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::WebExecuteScript(TCustomEdgeBrowser *Sender, HRESULT AResult,
const UnicodeString AResultObjectAsJson)
{
if (AResultObjectAsJson != 'null') {
if (Step == 0) {
if (StrToInt(AResultObjectAsJson) > 0) {
StatusBar->SimpleText = "Статус: авторизация успешна. Открываю список резюме ...";
HelpLabel->Visible = false;
StartTimer->Enabled = false;
MainTimer->Enabled = true;
}
else
{
StatusBar->SimpleText = "Статус: жду авторизации ...";
HelpLabel->Visible = true;
}
}
if (Step == 1) {
if (StrToInt(AResultObjectAsJson) > 0) {
StatusBar->SimpleText = "Авторизация в порядке ...";
Step = 2;
return;
}
else
{
MainTimer->Enabled = false;
Step = 0;
LastTime = "";
ShowWeb();
StartTimer->Enabled = true;
MainForm->Height = 685;
HelpLabel->Top = 606;
Web->ClientHeight = 600;
HelpLabel->Font->Style = TFontStyles() << fsBold;
HelpLabel->Font->Color = clRed;
HelpLabel->Caption = "Возникла проблема с авторизацией на сайте.";
}
}
if (Step == 2) {
if (StrToInt(AResultObjectAsJson) > 0) {
StatusBar->SimpleText = "Статус: могу поднять " + AResultObjectAsJson + " резюме.";
Step = 3;
return;
}
else
{
StatusBar->SimpleText = "Статус: поднятие недоступно. Ожидаем ...";
MainTimer->Enabled = false;
Step = 0;
HideWeb();
LongTimer->Enabled = true;
return;
}
}
if (Step == 3) {
LastTime = Now().FormatString("hh:nn");
StatusBar->SimpleText = "Статус: резюме подняты в " + LastTime + ". Ожидаем ...";
MainTimer->Enabled = false;
Step = 0;
HideWeb();
LongTimer->Enabled = true;
return;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::N1Click(TObject *Sender)
{
SettingsForm->Show();
}
//---------------------------------------------------------------------------