-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontent.js
More file actions
582 lines (502 loc) · 26.3 KB
/
Copy pathcontent.js
File metadata and controls
582 lines (502 loc) · 26.3 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
// Prevent multiple instances
if (window.jobAssistantLoaded) {
console.log('Job Assistant already loaded, skipping...');
} else {
window.jobAssistantLoaded = true;
console.log('Loading Job Assistant...');
// Job Assistant functionality
const JobAssistant = {
userProfile: {},
jobKeywords: ['job', 'career', 'apply', 'application', 'resume', 'cv'],
jobPortals: ['linkedin.com', 'indeed.com', 'glassdoor.com', 'greenhouse.io', 'lever.co', 'myworkdayjobs.com'],
async init() {
await this.loadProfile();
this.setupMessageListener();
if (this.isJobPortal()) {
console.log('Job portal detected - activating assistant');
}
},
async scrapeLinkedInProfile() {
const profile = {};
// Scroll through page to load all sections
window.scrollTo(0, document.body.scrollHeight);
await new Promise(resolve => setTimeout(resolve, 4000)); // wait for lazy loading
// Full Name - try multiple selectors
// Name scraping with fallback to <h1>
const nameEl = document.querySelector('main h1');
if (nameEl && nameEl.innerText.trim()) {
profile.fullName = nameEl.innerText.trim();
console.log('Found name:', profile.fullName);
} else {
console.log('Name element not found');
}
// Location - try multiple selectors
const locationSelectors = [
'span.text-body-small.inline.t-black--light.break-words',
'.pv-text-details__left-panel .text-body-small',
'[data-anonymize="location"]'
];
for (const selector of locationSelectors) {
const locationEl = document.querySelector(selector);
if (locationEl && locationEl.innerText.trim()) {
profile.location = locationEl.innerText.trim();
console.log('Found location with selector:', selector, '-> Value:', profile.location);
break;
}
}
// About (Summary) - try multiple approaches
const aboutSpan = document.querySelector('div.inline-show-more-text--is-collapsed .visually-hidden');
if (aboutSpan && aboutSpan.innerText.trim()) {
profile.summary = aboutSpan.innerText.trim();
console.log('Extracted About Summary:', profile.summary.substring(0, 500) + '...');
} else {
console.log('Could not find the About summary text');
}
const contactInfoBtn = document.querySelector('a[href*="overlay/contact-info"]');
if (contactInfoBtn) {
contactInfoBtn.click();
console.log("Clicked contact info");
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait 5s
const emailEl = document.querySelector('a[href^="mailto:"]'); // dedupe
if (emailEl) {
profile.email = emailEl.innerText.trim();
console.log("Found email:", profile.email);
}
} else {
console.log("Contact info button not found");
}
// Helper to scrape sections based on the h2 title
const scrapeSectionByTitle = (title) => {
console.log(`Attempting to scrape section: ${title}`);
// Method 1: Find by h2 text content
let heading = Array.from(document.querySelectorAll('h2')).find(h2 =>
h2.innerText.toLowerCase().includes(title.toLowerCase())
);
// Method 2: Find by section id containing the title
if (!heading) {
const section = document.querySelector(`section[id*="${title}"]`);
if (section) {
heading = section.querySelector('h2');
}
}
// Method 3: Find by data-section attribute
if (!heading) {
const section = document.querySelector(`section[data-section*="${title}"]`);
if (section) {
heading = section.querySelector('h2');
}
}
let section = null;
if (heading) {
section = heading.closest('section');
}
if (section) {
const items = section.querySelectorAll('li.artdeco-list__item, .pvs-entity, .pv-entity__summary-info');
const content = Array.from(items).map(item => item.innerText.trim()).join('\n\n');
console.log(`Found ${items.length} items for ${title} section`);
return content;
}
console.log(`No section found for: ${title}`);
return '';
};
profile.experience = scrapeSectionByTitle('experience');
profile.education = scrapeSectionByTitle('education');
profile.projects = scrapeSectionByTitle('Projects');
// Skills
const skillsBtn = document.querySelector('a[href*="skills"]');
if (skillsBtn) {
skillsBtn.click();
console.log("Clicked skills button");
// Wait for modal and skills to load
await new Promise(resolve => setTimeout(resolve, 5000)); // Wait 5s
const allSpans = Array.from(document.querySelectorAll('.pvs-list__paged-list-item span[aria-hidden="true"]'));
const skillNames = allSpans
.filter((_, index) => index % 2 === 0)
.map(el => el.innerText.trim())
.filter((text, index, arr) => text.length > 0 && arr.indexOf(text) === index); // dedupe
profile.skills = skillNames.join(', ');
console.log('Found skills:', profile.skills);
} else {
profile.skills = scrapeSectionByTitle('Skills'); // fallback
}
// For popup compatibility, extract degree/university from the first education entry
if (profile.education) {
const educationLines = profile.education.split('\n').filter(line => line.trim() !== '');
// Find first education block
let firstUni = '';
let firstDegree = '';
for (let i = 0; i < educationLines.length - 1; i++) {
const line = educationLines[i].trim();
const nextLine = educationLines[i + 1].trim();
if (
line.match(/university|college|school|/i) &&
nextLine.match(/bachelor|bachelors|masters|msc|meng|a levels|degree/i)
) {
firstUni = line;
firstDegree = nextLine;
break;
}
}
if (!firstUni && educationLines.length > 0) {
firstUni = educationLines[0];
}
profile.university = firstUni;
profile.degree = firstDegree;
}
// Ensure all fields are defined to avoid undefined values in the popup
const fields = ['fullName', 'email', 'phone', 'location', 'summary', 'experience', 'skills', 'degree', 'university', 'projects', 'education'];
fields.forEach(field => {
profile[field] = profile[field] || '';
});
console.log('LinkedIn profile scraped:', profile);
// Debug: log each field that was scraped
console.log('Scraped fields:', {
fullName: profile.fullName,
location: profile.location,
summary: profile.summary,
experience: profile.experience,
education: profile.education,
skills: profile.skills,
projects: profile.projects,
degree: profile.degree,
university: profile.university
});
return profile;
},
loadProfile() {
return new Promise(resolve => {
chrome.storage.local.get(['userProfile'], (result) => {
this.userProfile = result.userProfile || {};
console.log('Profile loaded:', this.userProfile);
resolve();
});
});
},
isJobPortal() {
const url = window.location.href.toLowerCase();
const domain = window.location.hostname.toLowerCase();
const pageText = document.body.innerText.toLowerCase();
if (this.jobPortals.some(portal => domain.includes(portal))) return true;
const keywordCount = this.jobKeywords.filter(k =>
pageText.includes(k) || url.includes(k)
).length;
return keywordCount >= 2;
},
// Message listener for scraping job description and LinkedIn profiles
setupMessageListener() {
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "SCRAPE_JOB") {
let jobText = this.scrapeJobDescription();
sendResponse({ text: jobText || "No job description found on this site." });
return true;
}
if (request.action === "SCRAPE_LINKEDIN_PROFILE") {
this.scrapeLinkedInProfile()
.then(profile => {
sendResponse({ profile: profile || {}, error: null });
})
.catch(error => {
sendResponse({ profile: {}, error: error.message || "Scraping failed." });
});
return true;
}
if (request.action === "SCRAPE_QUESTIONS") {
let questions = this.scrapeApplicationQuestions();
sendResponse({ questions: questions || "No application questions found on this site." });
return true;
}
});
},
// Job Description Scraper (Platform-specific + generic fallback)
scrapeJobDescription() {
const host = window.location.hostname;
let jobText = "";
if (host.includes("linkedin.com")) {
const el = document.querySelector(".description__text, .show-more-less-html__markup, .jobs-description__container, .jobs-description__content.jobs-description-content");
jobText = el?.innerText?.trim();
}
else if (host.includes("greenhouse.io")) {
const el = document.querySelector(".content, .section-wrapper, .description, .job__description.body");
jobText = el?.innerText?.trim();
}
else if (host.includes("lever.co")) {
const el = document.querySelector("div.content, div.description");
jobText = el?.innerText?.trim();
}
else if (host.includes("myworkdayjobs.com")) {
const el = document.querySelector("[data-automation-id='jobPostingDescription']");
jobText = el?.innerText?.trim();
}
// Generic fallback
if (!jobText || jobText.length < 100) {
const selectors = [
".job-description", ".job-details-body", ".description", ".job-desc",
"[id*='description']", "[class*='description']",
"section", "article"
];
for (const sel of selectors) {
const el = document.querySelector(sel);
if (el && el.innerText.length > 100) {
jobText = el.innerText.trim();
break;
}
}
}
return jobText || "No job description found on this site.";
},
// Application Questions Scraper (Platform-specific + generic fallback)
scrapeApplicationQuestions() {
const host = window.location.hostname;
let questionsText = "";
if (host.includes("linkedin.com")) {
// LinkedIn application questions
const questionElements = document.querySelectorAll(
'.jobs-easy-apply-form-section__grouping label, ' +
'.fb-form-element label, ' +
'.artdeco-text-input--label, ' +
'.jobs-easy-apply-form-element label'
);
if (questionElements.length > 0) {
const questions = Array.from(questionElements)
.map(el => el.innerText.trim())
.filter(text => text.length > 3 && !text.includes('*'))
.filter(text =>
text.toLowerCase().includes('why') ||
text.toLowerCase().includes('experience') ||
text.toLowerCase().includes('tell') ||
text.toLowerCase().includes('describe') ||
text.toLowerCase().includes('explain') ||
text.toLowerCase().includes('what') ||
text.toLowerCase().includes('how') ||
text.toLowerCase().includes('cover letter') ||
text.toLowerCase().includes('additional information')
);
questionsText = questions.join('\n\n');
}
}
else if (host.includes("greenhouse.io")) {
// Greenhouse application questions
const questionElements = document.querySelectorAll(
'label, .field-label, .application-question, .question-text'
);
if (questionElements.length > 0) {
const questions = Array.from(questionElements)
.map(el => el.innerText.trim())
.filter(text => text.length > 10)
.filter(text =>
text.includes('?') ||
text.toLowerCase().includes('why') ||
text.toLowerCase().includes('tell') ||
text.toLowerCase().includes('describe') ||
text.toLowerCase().includes('cover letter')
);
questionsText = questions.join('\n\n');
}
}
else if (host.includes("lever.co")) {
// Lever application questions
const questionElements = document.querySelectorAll(
'.application-form label, .form-field label, .question'
);
if (questionElements.length > 0) {
const questions = Array.from(questionElements)
.map(el => el.innerText.trim())
.filter(text => text.length > 10)
.filter(text =>
text.includes('?') ||
text.toLowerCase().includes('why') ||
text.toLowerCase().includes('tell') ||
text.toLowerCase().includes('describe')
);
questionsText = questions.join('\n\n');
}
}
else if (host.includes("myworkdayjobs.com")) {
// Workday application questions
const questionElements = document.querySelectorAll(
'[data-automation-id*="question"], .WDAY-FORM-LABEL, label'
);
if (questionElements.length > 0) {
const questions = Array.from(questionElements)
.map(el => el.innerText.trim())
.filter(text => text.length > 10)
.filter(text =>
text.includes('?') ||
text.toLowerCase().includes('why') ||
text.toLowerCase().includes('tell') ||
text.toLowerCase().includes('describe') ||
text.toLowerCase().includes('cover letter')
);
questionsText = questions.join('\n\n');
}
}
// Enhanced fallback for Google Forms, Microsoft Forms, Typeform, and other form builders
if (!questionsText || questionsText.length < 50) {
const formBuilderSelectors = [
// Google Forms
'.freebirdFormviewerViewNumberedItemContainer .freebirdFormviewerViewItemsItemItemTitle',
'.freebirdFormviewerViewItemsItemItemTitle',
'.freebirdFormviewerComponentsQuestionBaseTitle',
'[data-params*="question"]',
'.exportFormQuestion',
'.freebirdFormviewerViewItemsTextItemTitle',
// Microsoft Forms
'.question-title-box .question-title',
'.office-form-question-title',
'[data-automation-id="questionTitle"]',
'.form-question-title',
'.question-title-container',
'.office-form-question-body .question-title',
// Typeform
'.typeform-question-title',
'[data-qa="question-title"]',
'.question-group h1',
'.question-group .question-title',
// JotForm
'.form-label',
'.form-label-top',
'.form-label-left',
'.form-label-right',
'.jf-label',
// Formstack
'.fsLabel',
'.fsSection .fsLabel',
// Wufoo
'.field label',
'.wufoo label',
// Gravity Forms
'.gfield_label',
'.ginput_container label',
// Generic form selectors (comprehensive)
'form label',
'.question',
'.question-text',
'.question-title',
'.application-question',
'[class*="question"]',
'[id*="question"]',
'textarea + label',
'input[type="text"] + label',
'input[type="email"] + label',
'.form-group label',
'.form-field label',
'.field label',
'.input-group label',
'.form-control + label',
'.form-item label',
'.control-label',
'.col-form-label',
'.form-label',
'.field-label',
'.input-label',
// Additional patterns for various form frameworks
'.mat-form-field label', // Angular Material
'.v-label', // Vuetify
'.ant-form-item-label', // Ant Design
'.form-floating label', // Bootstrap
'.mdc-floating-label', // Material Design Components
// Aria and accessibility selectors
'[aria-label]',
'[aria-labelledby]',
'legend',
'fieldset legend',
// Title and heading elements that might contain questions
'h1, h2, h3, h4, h5, h6',
'.title',
'.heading',
'.section-title'
];
for (const selector of formBuilderSelectors) {
try {
const elements = document.querySelectorAll(selector);
if (elements.length > 0) {
const questions = Array.from(elements)
.map(el => {
// Get text from aria-label if available, otherwise innerText
return el.getAttribute('aria-label') || el.innerText.trim();
})
.filter(text => text && text.length > 3)
.filter(text => {
const lowerText = text.toLowerCase();
return (
// Question indicators
text.includes('?') ||
lowerText.includes('why') ||
lowerText.includes('tell') ||
lowerText.includes('describe') ||
lowerText.includes('explain') ||
lowerText.includes('what') ||
lowerText.includes('how') ||
lowerText.includes('when') ||
lowerText.includes('where') ||
lowerText.includes('which') ||
lowerText.includes('cover letter') ||
lowerText.includes('additional information') ||
lowerText.includes('experience') ||
lowerText.includes('background') ||
lowerText.includes('qualification') ||
lowerText.includes('skill') ||
lowerText.includes('interest') ||
lowerText.includes('motivation') ||
lowerText.includes('reason') ||
lowerText.includes('goal') ||
lowerText.includes('expectation') ||
lowerText.includes('salary') ||
lowerText.includes('availability') ||
lowerText.includes('start date') ||
lowerText.includes('portfolio') ||
lowerText.includes('github') ||
lowerText.includes('linkedin') ||
lowerText.includes('reference') ||
lowerText.includes('work authorization') ||
lowerText.includes('visa') ||
lowerText.includes('sponsorship') ||
lowerText.includes('remote') ||
lowerText.includes('relocation') ||
lowerText.includes('travel')
);
})
.filter((text, index, arr) => arr.indexOf(text) === index); // Remove duplicates
if (questions.length > 0) {
questionsText = questions.join('\n\n');
console.log(`Found ${questions.length} questions using selector: ${selector}`);
break;
}
}
} catch (error) {
console.log(`Error with selector ${selector}:`, error);
continue;
}
}
// If still no questions found, try a more aggressive approach
if (!questionsText || questionsText.length < 20) {
console.log('Trying aggressive question detection...');
const allTextElements = document.querySelectorAll('*');
const potentialQuestions = Array.from(allTextElements)
.map(el => el.innerText || el.textContent || '')
.filter(text => text.trim().length > 10 && text.trim().length < 500)
.filter(text => {
const lowerText = text.toLowerCase();
return (
text.includes('?') ||
(lowerText.includes('why') && (lowerText.includes('you') || lowerText.includes('company'))) ||
(lowerText.includes('tell') && lowerText.includes('about')) ||
(lowerText.includes('describe') && lowerText.includes('your')) ||
lowerText.includes('cover letter')
);
})
.filter((text, index, arr) => arr.indexOf(text) === index)
.slice(0, 10); // Limit to first 10 matches
if (potentialQuestions.length > 0) {
questionsText = potentialQuestions.join('\n\n');
console.log(`Found ${potentialQuestions.length} questions using aggressive detection`);
}
}
}
return questionsText || "No application questions found on this site.";
},
// Debug helper function to test question scraping on current page
};
// Initialize the assistant
JobAssistant.init();
}