Separated Opportunitues from Applied using headers, Added Date Posted to jobs.
This commit is contained in:
@@ -8,7 +8,12 @@ function isLoginPage() {
|
||||
var hasLoginForm = !!(emailInput && emailLabel);
|
||||
var isLoginUrl = window.location.pathname.indexOf('/login') === 0;
|
||||
|
||||
console.log('[Andela Content Script] Login check - hasForm:', hasLoginForm, 'isLoginUrl:', isLoginUrl);
|
||||
console.log(
|
||||
'[Andela Content Script] Login check - hasForm:',
|
||||
hasLoginForm,
|
||||
'isLoginUrl:',
|
||||
isLoginUrl,
|
||||
);
|
||||
return hasLoginForm || (isLoginUrl && !!emailInput);
|
||||
}
|
||||
|
||||
@@ -28,19 +33,23 @@ function enterEmailAndClickLogin(email) {
|
||||
emailInput.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
emailInput.dispatchEvent(new KeyboardEvent('keyup', { bubbles: true }));
|
||||
|
||||
console.log('[Andela Content Script] Email entered, looking for submit button...');
|
||||
console.log(
|
||||
'[Andela Content Script] Email entered, looking for submit button...',
|
||||
);
|
||||
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
var submitButton = document.querySelector('button[type="submit"]');
|
||||
|
||||
if (!submitButton) {
|
||||
var buttons = document.querySelectorAll('button');
|
||||
for (var i = 0; i < buttons.length; i++) {
|
||||
var btnText = buttons[i].textContent.toLowerCase();
|
||||
if (btnText.indexOf('login') !== -1 ||
|
||||
btnText.indexOf('sign in') !== -1 ||
|
||||
btnText.indexOf('continue') !== -1 ||
|
||||
btnText.indexOf('submit') !== -1) {
|
||||
if (
|
||||
btnText.indexOf('login') !== -1 ||
|
||||
btnText.indexOf('sign in') !== -1 ||
|
||||
btnText.indexOf('continue') !== -1 ||
|
||||
btnText.indexOf('submit') !== -1
|
||||
) {
|
||||
submitButton = buttons[i];
|
||||
break;
|
||||
}
|
||||
@@ -48,10 +57,15 @@ function enterEmailAndClickLogin(email) {
|
||||
}
|
||||
|
||||
if (submitButton) {
|
||||
console.log('[Andela Content Script] Clicking submit button:', submitButton.textContent);
|
||||
console.log(
|
||||
'[Andela Content Script] Clicking submit button:',
|
||||
submitButton.textContent,
|
||||
);
|
||||
submitButton.click();
|
||||
} else {
|
||||
console.log('[Andela Content Script] Submit button not found, trying form submit');
|
||||
console.log(
|
||||
'[Andela Content Script] Submit button not found, trying form submit',
|
||||
);
|
||||
var form = emailInput.closest('form');
|
||||
if (form) {
|
||||
if (form.requestSubmit) form.requestSubmit();
|
||||
@@ -67,17 +81,61 @@ function enterEmailAndClickLogin(email) {
|
||||
}
|
||||
}
|
||||
|
||||
// A section counts as "opportunities" if its heading contains this word —
|
||||
// matches "Open Full-Stack Engineer opportunities", "Open AI Engineer
|
||||
// opportunities", etc. Anything else (e.g. "Your applications") is
|
||||
// treated as already-applied.
|
||||
function isOpportunitySection(headingText) {
|
||||
return /opportunit/i.test(headingText || '');
|
||||
}
|
||||
|
||||
// Walks the page in DOM order and tags every "See more" button and every
|
||||
// job-posting link with the heading text of the section it falls under.
|
||||
function getPageSections() {
|
||||
var elements = document.querySelectorAll(
|
||||
'h3, button, a[href*="/job-postings/"]',
|
||||
);
|
||||
var currentHeading = '';
|
||||
var seeMoreButtons = []; // { button, heading }
|
||||
var jobLinks = []; // { link, heading }
|
||||
|
||||
elements.forEach(function (el) {
|
||||
if (el.tagName === 'H3') {
|
||||
currentHeading = el.textContent.trim();
|
||||
console.log(
|
||||
'[Andela Content Script] Section heading found:',
|
||||
currentHeading,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (el.tagName === 'BUTTON') {
|
||||
var text = (el.textContent || '').trim().toLowerCase();
|
||||
if (text.indexOf('see') === 0 && text.indexOf('more') !== -1) {
|
||||
seeMoreButtons.push({ button: el, heading: currentHeading });
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (el.tagName === 'A') {
|
||||
jobLinks.push({ link: el, heading: currentHeading });
|
||||
}
|
||||
});
|
||||
|
||||
return { seeMoreButtons: seeMoreButtons, jobLinks: jobLinks };
|
||||
}
|
||||
|
||||
// Only expands "See more" under opportunity sections — leaves the
|
||||
// applied-jobs section collapsed as-is.
|
||||
function expandAllSeeMoreButtons(maxRounds) {
|
||||
maxRounds = maxRounds || 25;
|
||||
return new Promise(function(resolve) {
|
||||
return new Promise(function (resolve) {
|
||||
var rounds = 0;
|
||||
|
||||
function findSeeMoreButton() {
|
||||
var buttons = document.querySelectorAll('button');
|
||||
for (var i = 0; i < buttons.length; i++) {
|
||||
var text = (buttons[i].textContent || '').trim().toLowerCase();
|
||||
if (text.indexOf('see') === 0 && text.indexOf('more') !== -1) {
|
||||
return buttons[i];
|
||||
var sections = getPageSections();
|
||||
for (var i = 0; i < sections.seeMoreButtons.length; i++) {
|
||||
var entry = sections.seeMoreButtons[i];
|
||||
if (isOpportunitySection(entry.heading)) {
|
||||
return entry.button;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -87,7 +145,11 @@ function expandAllSeeMoreButtons(maxRounds) {
|
||||
rounds++;
|
||||
var btn = findSeeMoreButton();
|
||||
if (!btn || rounds > maxRounds) {
|
||||
console.log('[Andela Content Script] Done expanding "See more" buttons after', rounds - 1, 'click(s)');
|
||||
console.log(
|
||||
'[Andela Content Script] Done expanding opportunity "See more" buttons after',
|
||||
rounds - 1,
|
||||
'click(s)',
|
||||
);
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
@@ -105,11 +167,15 @@ function extractJobFromLink(link) {
|
||||
var idMatch = href.match(/\/job-postings\/(\d+)/);
|
||||
var id = idMatch ? idMatch[1] : href;
|
||||
|
||||
var card = link.closest('div.rounded-lg.border.border-neutral-200.bg-white') || link.parentElement;
|
||||
var card =
|
||||
link.closest('div.rounded-lg.border.border-neutral-200.bg-white') ||
|
||||
link.parentElement;
|
||||
|
||||
var title = '';
|
||||
var company = '';
|
||||
var titleEl = card ? card.querySelector('.text-primary-900.font-semibold') : null;
|
||||
var titleEl = card
|
||||
? card.querySelector('.text-primary-900.font-semibold')
|
||||
: null;
|
||||
|
||||
if (titleEl) {
|
||||
var clone = titleEl.cloneNode(true);
|
||||
@@ -125,8 +191,12 @@ function extractJobFromLink(link) {
|
||||
var startInfo = paragraphs[0] ? paragraphs[0].textContent.trim() : '';
|
||||
var locationInfo = paragraphs[1] ? paragraphs[1].textContent.trim() : '';
|
||||
|
||||
var skillEls = card ? card.querySelectorAll('.flex.flex-wrap.gap-2 span') : [];
|
||||
var skills = Array.prototype.map.call(skillEls, function(s) { return s.textContent.trim(); });
|
||||
var skillEls = card
|
||||
? card.querySelectorAll('.flex.flex-wrap.gap-2 span')
|
||||
: [];
|
||||
var skills = Array.prototype.map.call(skillEls, function (s) {
|
||||
return s.textContent.trim();
|
||||
});
|
||||
|
||||
var url = href;
|
||||
if (url && url.indexOf('http') !== 0) {
|
||||
@@ -140,7 +210,7 @@ function extractJobFromLink(link) {
|
||||
posted_date: startInfo || '',
|
||||
location: locationInfo || '',
|
||||
skills: skills,
|
||||
url: url
|
||||
url: url,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -148,33 +218,50 @@ function extractJobsFromPage() {
|
||||
console.log('[Andela Content Script] Extracting jobs...');
|
||||
var jobs = [];
|
||||
var seen = {};
|
||||
var links = document.querySelectorAll('a[href*="/job-postings/"]');
|
||||
console.log('[Andela Content Script] Found ' + links.length + ' job-posting links');
|
||||
var jobLinks = getPageSections().jobLinks;
|
||||
console.log(
|
||||
'[Andela Content Script] Found ' + jobLinks.length + ' job-posting links',
|
||||
);
|
||||
|
||||
links.forEach(function(link) {
|
||||
jobLinks.forEach(function (entry) {
|
||||
try {
|
||||
var job = extractJobFromLink(link);
|
||||
var job = extractJobFromLink(entry.link);
|
||||
if (!job.id || seen[job.id]) return;
|
||||
seen[job.id] = true;
|
||||
job.section = entry.heading;
|
||||
job.kind = isOpportunitySection(entry.heading)
|
||||
? 'opportunity'
|
||||
: 'applied';
|
||||
if (job.title) {
|
||||
jobs.push(job);
|
||||
console.log('[Andela Content Script] Extracted job:', job.title, '(' + job.id + ')');
|
||||
console.log(
|
||||
'[Andela Content Script] Extracted job:',
|
||||
job.title,
|
||||
'(' + job.id + ')',
|
||||
'-',
|
||||
job.kind,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Andela Content Script] Error extracting a job card:', err);
|
||||
console.error(
|
||||
'[Andela Content Script] Error extracting a job card:',
|
||||
err,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
console.log('[Andela Content Script] Extracted ' + jobs.length + ' jobs total');
|
||||
console.log(
|
||||
'[Andela Content Script] Extracted ' + jobs.length + ' jobs total',
|
||||
);
|
||||
return jobs;
|
||||
}
|
||||
|
||||
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
||||
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
|
||||
console.log('[Andela Content Script] Received message:', request);
|
||||
|
||||
if (request.action === 'extractJobs') {
|
||||
expandAllSeeMoreButtons().then(function() {
|
||||
setTimeout(function() {
|
||||
expandAllSeeMoreButtons().then(function () {
|
||||
setTimeout(function () {
|
||||
try {
|
||||
var jobs = extractJobsFromPage();
|
||||
sendResponse({ jobs: jobs });
|
||||
@@ -198,5 +285,15 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
||||
sendResponse({ success: success });
|
||||
}
|
||||
|
||||
if (request.action === 'extractPostedDate') {
|
||||
var el = document.querySelector('span.text-success-500');
|
||||
var postedText = el ? el.textContent.trim() : '';
|
||||
console.log(
|
||||
'[Andela Content Script] Extracted posted date text:',
|
||||
postedText,
|
||||
);
|
||||
sendResponse({ postedDate: postedText });
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user