Purpose
Search CivilJobs for a departmental reference using the site's direct query-parameter filter and return matching vacancy links and titles.
When to Use
Use when the caller provides a CivilJobs departmental reference such as {reference} and needs to determine whether it identifies a vacancy, optionally checking its title.
Workflow
- Navigate directly to
https://civiljobs.co.uk/?q={url-encoded-reference}. Theqparameter initializes the same client-side filtering performed by the homepage search field; do not visit the homepage or type into the field separately. - Wait approximately 2.2 seconds for the client-side vacancy filtering to finish.
- Run this evaluator on the loaded page, substituting the caller's values for
{reference}and the optional{title-pattern}(a case-insensitive regular expression such asteam leader; leave it empty to skip title filtering):
(() => {
const reference = "{reference}";
const titlePattern = "{title-pattern}";
const matches = [...new Set(
[...document.querySelectorAll('a[href*="/jobs/"]')]
.map(a => ({
href: new URL(a.getAttribute('href'), location.origin).href,
title: a.textContent.replace(/\s+/g, ' ').trim()
}))
.filter(x => /\/jobs\/.*ref-\d+/i.test(x.href))
.filter(x => (x.href + " " + x.title).toLowerCase().includes(reference.toLowerCase()))
)];
return {
reference,
found: matches.length > 0,
matches,
titleMatches: titlePattern ? matches.filter(x => new RegExp(titlePattern, "i").test(x.title)) : matches
};
})()Site-Specific Gotchas
- CivilJobs filtering is client-side, but
https://civiljobs.co.uk/?q={reference}directly reaches the filtered state and avoids homepage interaction. - URL-encode the reference when constructing the
qparameter. - Wait for the dynamic filter to update before extracting results.
- The search input, useful as a fallback if direct
qinitialization ever fails, isinput#filter-search; setting its value must dispatch aninputevent. - Vacancy links use
/jobs/paths containing aref-{digits}segment. Restrict extraction to those links rather than treating every/jobs/link as a result.
Expected Output
An object of the form {reference, found, matches, titleMatches}, where each match contains its absolute href and visible vacancy title. found is true only when at least one vacancy link or title contains {reference}, so a failed ?q= filter cannot report a false positive; titleMatches narrows matches to titles matching {title-pattern} when one was supplied, otherwise it equals matches.