Repository navigation
Expand file tree
/
Copy pathpatch6_content.js
More file actions
76 lines (69 loc) · 2.81 KB
/
Copy pathpatch6_content.js
File metadata and controls
76 lines (69 loc) · 2.81 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const fs = require('fs');
const path = './extension/content.js';
let content = fs.readFileSync(path, 'utf8');
// 1. Patch Title
const titleRegex = /title: \(\) => firstMatch\(\[([\s\S]*?)\]\, getLIRoot\(\)\)\,/m;
const titleReplacement = `title: () => {
const root = getLIRoot();
const t = firstMatch([$1], root);
if (t) return t;
// Fallback: Find largest text node in right pane
let largest = null;
let maxFontSize = 0;
const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
let node;
while ((node = walker.nextNode())) {
if (node.children.length === 0 && node.innerText?.trim()) {
if (node.closest('ul, li, .jobs-search-results-list')) continue;
const style = window.getComputedStyle(node);
const size = parseFloat(style.fontSize) || 0;
if (size > maxFontSize) {
maxFontSize = size;
largest = node;
}
}
}
return largest?.innerText?.trim() || null;
},`;
content = content.replace(titleRegex, titleReplacement);
// 2. Patch Company
const compRegex = /company: \(\) => firstMatch\(\[([\s\S]*?)\]\, getLIRoot\(\)\)\,/m;
const compReplacement = `company: () => {
const root = getLIRoot();
const c = firstMatch([$1], root);
if (c) return c;
// Fallback: look for a company link
const links = root.querySelectorAll('a[href*="/company/"]');
for (const link of links) {
if (link.closest('ul, li, .jobs-search-results-list')) continue;
const text = link.innerText?.trim();
if (text && !/premium|see all|follow/i.test(text)) return text;
}
return null;
},`;
content = content.replace(compRegex, compReplacement);
// 3. Patch Description
const descRegex = /description: \(\) => firstMatch\(\[([\s\S]*?)\]\, document\),/m;
const descReplacement = `description: () => {
const root = getLIRoot();
const desc = firstMatch([$1], document);
if (desc) return desc;
// Fallback: Find the element with the most text in the right pane
let largest = null;
let maxLength = 0;
// We only care about block elements that could hold a description
const candidates = root.querySelectorAll('div, section, article, main');
for (const el of candidates) {
if (el.closest('ul, li, .jobs-search-results-list')) continue;
const text = el.innerText?.trim() || '';
// Avoid grabbing the absolute highest level container if possible, but taking it is better than null
if (text.length > maxLength && text.length > 200 && text.length < 30000) {
maxLength = text.length;
largest = el;
}
}
return largest?.innerText?.trim() || null;
},`;
content = content.replace(descRegex, descReplacement);
fs.writeFileSync(path, content, 'utf8');
console.log("Patched semantic fallbacks for Title, Company, Description");