Andela Notifications Updated
This commit is contained in:
76
job-notifier/popup.js
Normal file
76
job-notifier/popup.js
Normal file
@@ -0,0 +1,76 @@
|
||||
// popup.js
|
||||
|
||||
function sortJobsById(jobs) {
|
||||
return jobs.slice().sort(function(a, b) {
|
||||
return (parseInt(b.id, 10) || 0) - (parseInt(a.id, 10) || 0);
|
||||
});
|
||||
}
|
||||
|
||||
function updateUI(data) {
|
||||
var lastAndelaJobs = data.lastAndelaJobs || [];
|
||||
var lastAndelaUpdated = data.lastAndelaUpdated;
|
||||
var totalAndelaMatching = data.totalAndelaMatching || 0;
|
||||
|
||||
document.getElementById('jobCount').textContent = totalAndelaMatching + ' jobs found';
|
||||
|
||||
var jobList = document.getElementById('jobList');
|
||||
jobList.innerHTML = '';
|
||||
|
||||
if (lastAndelaJobs.length === 0) {
|
||||
jobList.innerHTML = '<div class="no-jobs">No jobs found yet. Click "Check Now" to scan for jobs.</div>';
|
||||
} else {
|
||||
var sortedJobs = sortJobsById(lastAndelaJobs);
|
||||
|
||||
sortedJobs.slice(0, 10).forEach(function(job) {
|
||||
var jobElement = document.createElement('div');
|
||||
jobElement.className = 'job-item';
|
||||
|
||||
var postedDate = job.posted_date || 'Recently posted';
|
||||
var companyName = typeof job.company === 'object' ? (job.company && job.company.name || 'Company') : (job.company || 'Company');
|
||||
|
||||
jobElement.innerHTML =
|
||||
'<div class="job-title">' + job.title + '</div>' +
|
||||
'<div class="job-company">' + companyName + '</div>' +
|
||||
'<div class="job-location">' + (job.location || 'Remote') + '</div>' +
|
||||
'<div class="job-posted">' + postedDate + '</div>';
|
||||
|
||||
jobElement.addEventListener('click', function() {
|
||||
var url = job.url || ('https://app.andela.com/job-postings/' + job.id);
|
||||
chrome.tabs.create({ url: url });
|
||||
});
|
||||
|
||||
jobList.appendChild(jobElement);
|
||||
});
|
||||
}
|
||||
|
||||
var status = document.getElementById('status');
|
||||
status.textContent = lastAndelaUpdated ?
|
||||
'Last checked: ' + new Date(lastAndelaUpdated).toLocaleString() :
|
||||
'Not checked yet';
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
document.getElementById('checkNow').addEventListener('click', function() {
|
||||
console.log('Manual check triggered');
|
||||
chrome.runtime.sendMessage({ action: 'checkNow' }, function(response) {
|
||||
console.log('Check initiated');
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById('openSettings').addEventListener('click', function() {
|
||||
chrome.tabs.create({ url: 'settings.html' });
|
||||
});
|
||||
|
||||
chrome.storage.local.get(['lastAndelaJobs', 'lastAndelaUpdated', 'totalAndelaMatching'], function(result) {
|
||||
updateUI(result);
|
||||
});
|
||||
|
||||
chrome.storage.onChanged.addListener(function(changes, areaName) {
|
||||
if (areaName === 'local' && (changes.lastAndelaJobs || changes.lastAndelaUpdated || changes.totalAndelaMatching)) {
|
||||
console.log('Storage updated, refreshing UI...');
|
||||
chrome.storage.local.get(['lastAndelaJobs', 'lastAndelaUpdated', 'totalAndelaMatching'], function(result) {
|
||||
updateUI(result);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user