-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
347 lines (278 loc) · 8.96 KB
/
index.js
File metadata and controls
347 lines (278 loc) · 8.96 KB
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/usr/bin/env node
import * as fsPromise from "fs/promises";
import { fileURLToPath } from "url";
import path from "path";
import puppeteer from "puppeteer-core";
import createDesktopShortcut from "create-desktop-shortcuts";
import {WindowsToaster} from "node-notifier";
import { SysTray } from "node-systray-v2";
import arg from "arg";
import {hideConsole, showConsole} from "node-hide-console-window"
import image from "./image.js";
// import config from "./config.json" with { type: "json" };
const DEFAULT_UPDATE_TIME = 4 * 60 * 60 * 1000; // milliseconds
const DEFAULT_BROWSER_PATH =
"C:/Program Files/Google/Chrome/Application/chrome.exe";
const URL = "https://www.naukri.com/mnjuser/profile";
const isProduction = typeof process.pkg !== "undefined";
const __filename = isProduction? process.execPath:fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
console.log(fileURLToPath(import.meta.url))
function addToSysTray(){
const systray = new SysTray({
menu: {
// you should using .png icon in macOS/Linux, but .ico format in windows
icon: image,
title: "Profile updater",
tooltip: "Profile updater",
items: [
{
title: "Exit",
tooltip: "exit kar oe",
checked: false,
enabled: true,
},
],
},
debug: false,
copyDir: true, // copy go tray binary to outside directory, useful for packing tool like pkg.
});
systray.onClick((action) => {
if (action.seq_id === 0) {
systray.kill();
process.exit(0);
}
});
}
function startOnStartup() {
// let exePath = null;
// if (isProduction) {
// exePath = ;
// } else {
// exePath = __filename;
// }
const startupFolder = path.join(
process.env.APPDATA,
"Microsoft\\Windows\\Start Menu\\Programs\\Startup"
);
const result = createDesktopShortcut({
onlyCurrentOS: true,
windows: {
filePath: __filename,
outputPath: startupFolder,
name: "profile updater Shortcut",
comment: "Auto-created shortcut!",
windowMode: "normal",
// icon: "./profile-changer.ico", // optional
VBScriptPath: "./vendor/windows.vbs"
},
});
console.log(
result ? "Shortcut created successfully!" : "Failed to create shortcut."
);
}
function sendNotification(title, message) {
const notifier = new WindowsToaster({
withFallback: false, // Fallback to Growl or Balloons?
customPath: path.resolve(__dirname, "./vendor/snoreToast/snoretoast-x64.exe") // Relative/Absolute path if you want to use your fork of SnoreToast.exe
});
notifier.notify({
title,
message,
icon: path.resolve(__dirname, "./profile-changer.ico"),
sound: true,
wait: false,
appID: "Profile Updater",
});
}
async function openBrowser(config) {
const browser = await puppeteer.launch({
executablePath: config.browserUrl,
headless: isProduction,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
});
try {
const page = await browser.newPage();
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');
// await page.setViewport({ width: 1280, height: 800 });
await page.goto(URL, {
waitUntil: "networkidle0",
timeout: 0,
});
// await page.waitForSelector('#usernameField', { visible: true });
await page.type("#usernameField", config.email);
await page.type("#passwordField", config.password);
const loginButton = await page.$(
".waves-effect.waves-light.btn-large.btn-block.btn-bold.blue-btn.textTransform"
);
await Promise.all([page.waitForNavigation(), loginButton.click()]);
await page.goto(URL, {
waitUntil: "networkidle0",
timeout: 0,
});
//? updating resume
const [fileChooser] = await Promise.all([
page.waitForFileChooser(),
page.click("#attachCV"),
// some button that triggers file selection
]);
await fileChooser.accept([config.resumeUrl]);
await page.waitForSelector('#lazyAttachCV .msg', { visible: true });
if (config.resumeHeadlines?.length) {
// //? updating headline
await page.click("#lazyResumeHead .edit.icon");
await page.evaluate(() => {
const inputField = document.querySelector("#resumeHeadlineTxt");
inputField.value = ""; // Directly set the value to empty
});
await page.type(
"#resumeHeadlineTxt",
config.resumeHeadlines[Math.round(Math.random() * (config.resumeHeadlines?.length -1))]
);
await page.click(`form[name="resumeHeadlineForm"] .btn-dark-ot`);
await page.waitForSelector('#lazyResumeHead .msg', { visible: true });
}
return true;
} catch (err) {
showConsole();
console.log(err);
return false;
} finally {
browser.close();
}
}
async function handleBrowserNotification(config) {
const browserAction = await openBrowser(config);
if (browserAction) {
sendNotification(
"Profile updated successfully",
"Enjoy your life in peace"
);
} else {
sendNotification(
"There was some error while updating profile",
"Please don't disturb me for your task"
);
}
}
function usage() {
console.log(`tool [CMD]
--help\tTo check all the commands
--init\tInitialize the app
--email String\tadd your email using flag like this '--email example@ex.com'
--password String\tadd your password using flag like this '--password yourpassword'
--resumeUrl String\tadd your resume path using flag like this ' --resumeUrl "C:/Program Files/Google/Chrome/Application/chrome.exe" ' please notice the '/' and '"'
--resumeHeadlines String\tadd your resume path using flag like this ' --resumeHeadlines "Hi am jobless" ' you can use this command multiple times to add multiple headlines code will update one at random
--startOnStartup\tenable start on startups only works for windows
`);
}
async function writeConfig(config) {
await fsPromise.writeFile(
path.join(__dirname,"./config.json"),
JSON.stringify(config, null, 2)
);
}
async function logError(err) {
await fsPromise.appendFileSync('error.log', `[${new Date().toISOString()}] ${err.stack || err}\n`);
}
async function main() {
// addToSysTray();
let config = null;
try {
const args = arg({
"--init": Boolean,
"--help": Boolean,
"--email": String,
"--password": String,
"--resumeUrl": String,
"--resumeHeadlines": String,
"--startOnStartup": Boolean,
});
// console.log(args);
if (args["--help"]) {
usage();
return;
} else if (args["--init"]) {
await writeConfig({
browserUrl: DEFAULT_BROWSER_PATH,
timer: DEFAULT_UPDATE_TIME,
});
return;
}else if(args["--startOnStartup"]){
startOnStartup();
return;
}
config = await fsPromise.readFile(path.join(__dirname, "./config.json"), "utf8").catch((err) => {
console.log(`Ohh! configs not found please run this tool with --init flag
you can also use --help flag to check all the flags`);
});
if (!config) return;
config = JSON.parse(config);
if (!config) return;
if (args["--email"]) {
// console.log(args["--email"]);
config.email = args["--email"];
await writeConfig(config);
return;
}
if (!config.email) {
console.log(
`No email found please add your adding flag like '--email example@ex.com'`
);
return;
}
if (args["--password"]) {
// console.log(args["--email"]);
config.password = args["--password"];
await writeConfig(config);
return;
}
if (!config.password) {
console.log(
`No password found please add your adding flag like '--password yourpassword'`
);
return;
}
if (args["--resumeUrl"]) {
// console.log(args["--email"]);
config.resumeUrl = args["--resumeUrl"];
await writeConfig(config);
return;
}
if (!config.resumeUrl) {
console.log(
`No resume path found please add your adding flag like ' --resumeUrl "C:/Program Files/Google/Chrome/Application/chrome.exe" ' please notice the '/' and '"'`
);
return;
}
if (args["--resumeHeadlines"]) {
if (config.resumeHeadlines) {
config.resumeHeadlines.push(args["--resumeHeadlines"]);
}else{
config.resumeHeadlines = [args["--resumeHeadlines"]];
}
await writeConfig(config);
return;
}
} catch (err) {
if (err.message.includes("Unexpected token")) {
console.log(
"Looks like there is some error in parsing configs please try running with --init flag again"
);
return;
}
console.log(err.message);
usage();
}
addToSysTray();
hideConsole();
// console.log("here");
handleBrowserNotification(config);
setInterval(async () => {
// console.log("Running task at", new Date());
handleBrowserNotification(config);
}, config.timer);
}
(() => {
main();
})();