Repository navigation
Expand file tree
/
Copy pathpatch4_content.js
More file actions
39 lines (34 loc) · 1.54 KB
/
Copy pathpatch4_content.js
File metadata and controls
39 lines (34 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const fs = require('fs');
const path = './extension/content.js';
let content = fs.readFileSync(path, 'utf8');
// 1. Patch scrapeJobData to use try/catch for every property
const scrapeJobDataRegex = /function scrapeJobData\(\) \{[\s\S]*?const rawUrl = scraper\.url\?\.\(\) \|\| window\.location\.href;/m;
const scrapeJobDataReplacement = `function scrapeJobData() {
const scraper = getScraper();
const safeExtract = (key, fallback) => {
try {
if (typeof scraper[key] === 'function') {
const res = scraper[key]();
return res !== undefined && res !== null ? res : fallback;
}
return fallback;
} catch (e) {
console.error(\`[JobAutomator] Extractor error for \${key}:\`, e);
return fallback;
}
};
const rawLocation = safeExtract('location', '');
const rawWorkplaceType = safeExtract('workplaceType', '');
const rawDatePosted = safeExtract('datePosted', null);
const rawSalary = safeExtract('salary', null);
const rawType = safeExtract('type', null);
const rawTitle = safeExtract('title', null);
const rawCompany = safeExtract('company', null);
const rawDescription = safeExtract('description', null);
const rawCompanyLogo = safeExtract('companyLogo', null);
const rawApplyLink = safeExtract('applyLink', null);
const rawDeadline = safeExtract('deadline', null);
const rawUrl = safeExtract('url', window.location.href);`;
content = content.replace(scrapeJobDataRegex, scrapeJobDataReplacement);
fs.writeFileSync(path, content, 'utf8');
console.log("Patched scrapeJobData with safeExtract");