Usajobs Retrieval
Usajobs Retrieval
addEventListener('DOMContentLoaded', function () {
const host = 'data.usajobs.gov';
const userAgent = 'clindeman@peregrineadvisors.com';
const authKey = 'XLNeOm1IYZ6JcF34elHhjQgfXeTe12NdkrDxZBOHPGc=';
let jobIndex = 0;
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function displayJobs(jobs) {
const jobListings = document.getElementById('jobListings');
jobListings.innerHTML = '';
jobs.forEach(job => {
const jobElement = document.createElement('div');
jobElement.className = 'job-listing';
jobElement.innerHTML = `
<h3>${job.MatchedObjectDescriptor.PositionTitle}</h3>
<p>${job.MatchedObjectDescriptor.PositionLocationDisplay}</p>
<p>$
{truncateText(job.MatchedObjectDescriptor.UserArea.Details.MajorDuties || 'No details
available', 100)}</p>
`;
jobListings.appendChild(jobElement);
});
}
function slideJobs(direction) {
const totalJobs = document.querySelectorAll('.job-listing').length;
const jobWidth = document.querySelector('.job-listing').offsetWidth;
const containerWidth = document.querySelector('.slideshow-
container').offsetWidth;
const visibleJobs = Math.floor(containerWidth / jobWidth);
const maxIndex = totalJobs - visibleJobs;
document.getElementById('nextButton').addEventListener('click', function ()
{
slideJobs('next');
});
document.getElementById('prevButton').addEventListener('click', function ()
{
slideJobs('prev');
});
setInterval(function () {
slideJobs('next');
}, 5000); // Rotate every 5 seconds
fetchJobs();
});
HTML
<style type="text/css">
body {
font-family: Arial, sans-serif;
}
.slideshow-container {
width: 80%;
margin: 0 auto;
overflow: hidden;
position: relative;
max-height: 280px;
/* Limit the height of the slideshow */
display: flex;
align-items: center;
/* Vertically center the content */
}
.job-listings {
display: flex;
transition: transform 0.5s ease-in-out;
width: 100%;
/* Ensure the job listings take the full width */
}
.job-listing {
flex: 0 0 33.3333%;
box-sizing: border-box;
padding: 20px;
max-height: 300px;
/* Ensure each job listing does not exceed the height limit */
overflow: hidden;
/* Hide overflow content */
}
.job-listing:not(:last-child) {
border-right: 1px solid #ddd;
}
.nav-buttons {
width: 100%;
display: flex;
justify-content: space-between;
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.nav-button {
background-color: rgba(0, 0, 0, 0.5);
color: white;
border: none;
padding: 10px;
cursor: pointer;
z-index: 1;
/* Ensure buttons are above the job listings */
}
</style>
<div class="slideshow-container">
<div class="job-listings" id="jobListings"> </div>
<div class="nav-buttons">
<button class="nav-button" id="prevButton">❮</button>
<button class="nav-button" id="nextButton">❯</button>
</div>
</div>
————————————————————
JS
document.addEventListener('DOMContentLoaded', function () {
const host = 'data.usajobs.gov';
const userAgent = 'clindeman@peregrineadvisors.com';
const authKey = 'XLNeOm1IYZ6JcF34elHhjQgfXeTe12NdkrDxZBOHPGc';
let jobIndex = 0;
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function displayJobs(jobs) {
const jobListings = document.getElementById('jobListings');
jobListings.innerHTML = '';
jobs.forEach(job => {
const jobElement = document.createElement('div');
jobElement.className = 'job-listing';
jobElement.innerHTML = `
<a href="${job.MatchedObjectDescriptor.ApplyURI[0]}" target="_blank"
class="apply-button">Apply Now</a>
<h3>${job.MatchedObjectDescriptor.PositionTitle}</h3>
<p>${job.MatchedObjectDescriptor.PositionLocationDisplay}</p>
<p>$
{truncateText(job.MatchedObjectDescriptor.UserArea.Details.MajorDuties || 'No details
available', 100)}</p>
`;
jobListings.appendChild(jobElement);
});
}
function slideJobs(direction) {
const totalJobs = document.querySelectorAll('.job-listing').length;
const jobWidth = document.querySelector('.job-listing').offsetWidth;
const containerWidth = document.querySelector('.slideshow-
container').offsetWidth;
const visibleJobs = Math.floor(containerWidth / jobWidth);
const maxIndex = totalJobs - visibleJobs;
document.getElementById('nextButton').addEventListener('click', function () {
slideJobs('next');
});
document.getElementById('prevButton').addEventListener('click', function () {
slideJobs('prev');
});
setInterval(function () {
slideJobs('next');
}, 5000); // Rotate every 5 seconds
fetchJobs();
});