49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
const HEADER_LINES = new Set([
|
|
"OVERVIEW",
|
|
"PRE-SCREENING",
|
|
"WORK TERM RATINGS",
|
|
"JOB POSTING INFORMATION",
|
|
"APPLICATION INFORMATION",
|
|
"COMPANY INFORMATION",
|
|
"SERVICE TEAM"
|
|
]);
|
|
|
|
function sanitizePostingText(text) {
|
|
let cleaned = text.replaceAll("fiber_manual_record", "");
|
|
const lines = cleaned.split(/\r?\n/);
|
|
const filtered = lines.filter((line) => {
|
|
const trimmed = line.trim();
|
|
if (!trimmed) return true;
|
|
return !HEADER_LINES.has(trimmed.toUpperCase());
|
|
});
|
|
|
|
cleaned = filtered.join("\n");
|
|
cleaned = cleaned.replace(/[ \t]+/g, " ");
|
|
cleaned = cleaned.replace(/\n{3,}/g, "\n\n");
|
|
return cleaned.trim();
|
|
}
|
|
|
|
function extractPostingText() {
|
|
const contents = [...document.getElementsByClassName("modal__content")];
|
|
if (!contents.length) {
|
|
return { ok: false, error: "No modal content found on this page." };
|
|
}
|
|
|
|
// WaterlooWorks renders multiple modal containers; choose the longest visible text block.
|
|
const el = contents.reduce((best, cur) =>
|
|
cur.innerText.length > best.innerText.length ? cur : best
|
|
);
|
|
|
|
const rawText = el.innerText;
|
|
const sanitized = sanitizePostingText(rawText);
|
|
|
|
return { ok: true, rawText, sanitized };
|
|
}
|
|
|
|
chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
|
|
if (message?.type !== "EXTRACT_POSTING") return;
|
|
|
|
const result = extractPostingText();
|
|
sendResponse(result);
|
|
});
|