Repository navigation
Expand file tree
/
Copy pathcontent.js
More file actions
115 lines (95 loc) · 3.84 KB
/
Copy pathcontent.js
File metadata and controls
115 lines (95 loc) · 3.84 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// content.js — LinkedIn Jobs Remote Filter (production)
(() => {
'use strict';
// —— Config —— //
const BOOT_DELAY_MS = 4000; // aumente se necessário (ex.: 6000–8000)
const REAPPLY_INTERVAL_MS = 1500;
const REAPPLY_WINDOW_MS = 60000; // reaplica por 60s após o boot
const HIDE_CLASS = 'remote-filter--hidden';
// —— CSS base —— //
const ensureStyle = () => {
if (document.getElementById('remote-filter-style')) return;
const style = document.createElement('style');
style.id = 'remote-filter-style';
style.textContent = `
.${HIDE_CLASS}{ display:none !important; }
`;
(document.head || document.documentElement).appendChild(style);
};
// —— Helpers —— //
const normalize = (s) =>
(s || '')
.toLowerCase()
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, ''); // remove acentos (híbrido -> hibrido)
// aceita “Remote/Remoto”
const isRemoteText = (t) => /\bremote\b/.test(t) || /\bremoto\b/.test(t);
// marca explicitamente não-remoto
const isNonRemoteExplicit = (t) =>
/\bhybrid\b/.test(t) || /\bhibrido\b/.test(t) ||
/\bon[-\s]?site\b/.test(t) || /\bpresencial\b/.test(t);
// pistas entre parênteses em qualquer lugar do card
const hasParenRemote = (t) => /\(remote\)/.test(t) || /\(remoto\)/.test(t);
const hasParenNonRemote = (t) =>
/\(hybrid\)/.test(t) || /\(hibrido\)/.test(t) ||
/\(on[-\s]?site\)/.test(t) || /\(presencial\)/.test(t);
// —— Seletores —— //
const getCards = () =>
document.querySelectorAll(
'[data-occludable-job-id], li.scaffold-layout__list-item, li.jobs-search-results__list-item'
);
// bloco onde costuma aparecer a localização/arranjo
const getLocationNode = (root) =>
root.querySelector('.job-card-container__metadata-wrapper, .artdeco-entity-lockup__caption');
// —— Lógica —— //
const classifyCard = (el) => {
const locText = normalize(getLocationNode(el)?.textContent || '');
const allText = normalize(el.textContent || '');
// remoto se aparecer na área de localização ou como pista forte “(Remote)”
if (isRemoteText(locText) || hasParenRemote(allText)) return 'remote';
// não remoto se aparecer explícito
if (isNonRemoteExplicit(locText) || hasParenNonRemote(allText)) return 'other';
// fallback: tratar desconhecido como NÃO remoto (ocultar)
return 'other';
};
const applyFilter = () => {
ensureStyle();
getCards().forEach((el) => {
const kind = classifyCard(el);
el.classList.toggle(HIDE_CLASS, kind !== 'remote');
});
};
// Debounce com rAF
let rafId = null;
const scheduleApply = () => {
if (rafId) cancelAnimationFrame(rafId);
rafId = requestAnimationFrame(() => {
rafId = null;
applyFilter();
});
};
// —— Boot —— //
const boot = () => {
applyFilter();
// observar mudanças (SPA/scroll infinito)
const target = document.querySelector('main') || document.body || document.documentElement;
const mo = new MutationObserver(scheduleApply);
mo.observe(target, { childList: true, subtree: true });
// reaplicar por um período após o boot
const start = Date.now();
const iv = setInterval(() => {
applyFilter();
if (Date.now() - start > REAPPLY_WINDOW_MS) clearInterval(iv);
}, REAPPLY_INTERVAL_MS);
};
// —— Inicialização após window.load + delay —— //
const startAfterLoad = () => {
const kick = () => (document.body ? boot() : setTimeout(kick, 100));
setTimeout(kick, BOOT_DELAY_MS);
};
if (document.readyState === 'complete') {
startAfterLoad();
} else {
window.addEventListener('load', startAfterLoad, { once: true });
}
})(); // <-- IIFE fechada corretamente