-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontentScript.js
More file actions
80 lines (62 loc) · 3.72 KB
/
contentScript.js
File metadata and controls
80 lines (62 loc) · 3.72 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
// contentScript.js
// Function to extract LinkedIn Experience details
function getLinkedInExperience() {
const experiences = [];
let experienceSection = document.querySelector("#profile-content > div > div.scaffold-layout.scaffold-layout--breakpoint-md.scaffold-layout--main-aside.scaffold-layout--reflow.pv-profile.pvs-loader-wrapper__shimmer--animate > div > div > main")
// Select the experience section by looking for the appropriate class
// const experienceSection = Array.from(document.querySelectorAll("section"))
// .find(section => section.innerText.includes("Experience")); // Find the section containing the word "Experience"
experienceSection = Array.from(document.querySelectorAll("div"))
.find(section => section.innerText.toLowerCase().includes("experience"));
// Check if the experience section exists
if (!experienceSection) {
console.log("Experience section not found.");
return experiences; // Return empty array if not found
}
// Select all experience items within the experience section
const experienceItems = experienceSection.querySelectorAll('.artdeco-list__item');
// console.log(`Found ${experienceItems.length} experience items.`); // Log the number of experience items
const nameElement = document.querySelector('h1[class*="inline"][class*="t-24"]');
experienceItems.forEach((item, index) => {
if (index >= 10) return; // Stop after 10 items
// Extract name
const titleElement = item.querySelector('.display-flex.align-items-center .t-bold span[aria-hidden="true"]'); // Select job title
const companyElement = item.querySelector('span.t-normal'); // Select company name with job type
const descriptionElement = item.querySelector('.inline-show-more-text--is-collapsed'); // Select description
const name = nameElement ? nameElement.innerText.trim() : 'Name not found';
const title = titleElement ? titleElement.innerText.trim() : 'Title not found';
const company = companyElement ? companyElement.innerText.trim() : 'Company not found';
const description = descriptionElement ? descriptionElement.innerText.trim() : 'Description not found';
// console.log(`Name: "${name}", Experience ${index + 1}: Title: "${title}", Company: "${company}", Description: "${description}"`); // Log extracted details
experiences.push({ name, title, company, description }); // Add extracted details to experiences array
});
if (experiences.length === 0) {
console.log("No experience details found.");
} else {
// console.log("Successfully extracted experience details:", experiences); // Log the array of experiences
}
return experiences; // Return the array of experience details
}
// Define the function to retrieve profile data asynchronously
function getProfileData(callback) {
chrome.storage.local.get('profileData', (result) => {
const savedData = result.profileData || {}; // Default to empty object if not found
// console.log('Retrieved Profile Data:', savedData); // Log to verify retrieval
callback(savedData); // Use a callback to return data
});
}
// Listen for messages from popup.js
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'getProfileDetails' && request.profileAction === 'getProfileData') {
const experienceDetails = getLinkedInExperience();
// Retrieve profile data and send it with experience data
getProfileData((profileDetails) => {
sendResponse({
profile: profileDetails,
experience: experienceDetails
});
});
// Return true to indicate that the response will be sent asynchronously
return true;
}
});