Guard against duplicate applications + capture jobs on any website

Duplicate safeguard: before creating an application (manual add and
browser import) the server checks for an existing one for the same job —
matched on a normalised source URL (job-id params like Indeed's jk pin
the posting across paths/tracking) or an identical company + role
(case/umlaut/whitespace-insensitive). On a match it returns 409 with the
matches; the web form and the extension show the existing entry and
re-submit with force=true only if the user confirms. Not a hard block, so
legitimate re-applications stay possible.

Universal capture: the extension popup becomes an editable capture form
that works on any site. It extracts the active page on demand (schema.org
JobPosting JSON-LD -> OpenGraph/meta -> h1/title/selection -> canonical
URL), lets the user review/correct, and sends. The import route is now
source-agnostic and derives the application source (art) from the URL
instead of hardcoding Indeed; the Indeed on-page button remains as a fast
path. Adds scripting/activeTab permissions.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 18:32:17 +02:00
co-authored by Claude Opus 4.8
parent d8b552e57d
commit b1c92dd77b
7 changed files with 457 additions and 87 deletions
+179 -19
View File
@@ -1,41 +1,201 @@
const DEFAULT_TRACKER_URL = 'http://localhost:3000';
const input = document.getElementById('trackerUrl');
const statusEl = document.getElementById('status');
const $ = (id) => document.getElementById(id);
const statusEl = $('status');
function normalize(url) {
return (url || '').trim().replace(/\/+$/, '');
}
function setStatus(text, cls) {
statusEl.textContent = text;
function setStatus(html, cls) {
statusEl.innerHTML = html;
statusEl.className = cls || '';
}
// Load stored value
// ---- Settings (tracker URL) ------------------------------------------------
chrome.storage.sync.get({ trackerUrl: DEFAULT_TRACKER_URL }, (items) => {
input.value = items.trackerUrl || DEFAULT_TRACKER_URL;
$('trackerUrl').value = items.trackerUrl || DEFAULT_TRACKER_URL;
});
document.getElementById('saveBtn').addEventListener('click', () => {
const url = normalize(input.value) || DEFAULT_TRACKER_URL;
$('saveBtn').addEventListener('click', () => {
const url = normalize($('trackerUrl').value) || DEFAULT_TRACKER_URL;
chrome.storage.sync.set({ trackerUrl: url }, () => {
input.value = url;
setStatus('Gespeichert.', 'ok');
$('trackerUrl').value = url;
setStatus('Einstellungen gespeichert.', 'ok');
});
});
document.getElementById('testBtn').addEventListener('click', async () => {
const url = normalize(input.value) || DEFAULT_TRACKER_URL;
setStatus('Teste Verbindung…', '');
$('testBtn').addEventListener('click', async () => {
const url = normalize($('trackerUrl').value) || DEFAULT_TRACKER_URL;
setStatus('Teste Verbindung …', '');
try {
const res = await fetch(url + '/api/settings', { method: 'GET' });
if (res.ok) {
setStatus('Verbindung erfolgreich ✓', 'ok');
} else {
setStatus('Erreichbar, aber unerwartete Antwort (' + res.status + ').', 'err');
}
setStatus(res.ok ? 'Verbindung erfolgreich ✓' : 'Erreichbar, aber unerwartete Antwort (' + res.status + ').', res.ok ? 'ok' : 'err');
} catch (err) {
setStatus('Nicht erreichbar: ' + err.message, 'err');
}
});
// ---- Page extraction (injected into the active tab) ------------------------
// Runs in the page context. Best-effort job extraction from ANY site:
// schema.org JobPosting (JSON-LD) → OpenGraph/meta → <h1>/selection → canonical.
function extractJobFromPage() {
const txt = (s) => (s || '').replace(/\s+/g, ' ').trim();
const meta = (sel) => { const el = document.querySelector(sel); return el ? (el.getAttribute('content') || '') : ''; };
let jp = null;
document.querySelectorAll('script[type="application/ld+json"]').forEach((s) => {
if (jp) return;
let data; try { data = JSON.parse(s.textContent); } catch (e) { return; }
const arr = Array.isArray(data) ? data : (data['@graph'] ? data['@graph'] : [data]);
for (const node of arr) {
const t = node && node['@type'];
if (t === 'JobPosting' || (Array.isArray(t) && t.indexOf('JobPosting') !== -1)) { jp = node; break; }
}
});
const out = { firma: '', stelle: '', ort: '', gehalt: '', stellenbeschreibung: '', quelle_url: '' };
if (jp) {
out.stelle = txt(jp.title || '');
const org = jp.hiringOrganization;
if (org) out.firma = txt(typeof org === 'string' ? org : (org.name || ''));
const loc = Array.isArray(jp.jobLocation) ? jp.jobLocation[0] : jp.jobLocation;
if (loc && loc.address) {
const a = loc.address;
out.ort = txt(typeof a === 'string' ? a : [a.addressLocality, a.addressRegion, a.postalCode].filter(Boolean).join(', '));
}
const sal = jp.baseSalary;
if (sal && sal.value) {
const v = sal.value;
const amount = v.value || (v.minValue != null && v.maxValue != null ? v.minValue + '-' + v.maxValue : (v.minValue || v.maxValue || ''));
if (amount) out.gehalt = txt(String(amount) + ' ' + (sal.currency || '') + (v.unitText ? (' / ' + v.unitText) : ''));
}
if (jp.description) {
const tmp = document.createElement('div');
tmp.innerHTML = jp.description;
out.stellenbeschreibung = txt(tmp.innerText || tmp.textContent || '');
}
}
if (!out.stelle) {
const h1 = document.querySelector('h1');
out.stelle = txt(meta('meta[property="og:title"]') || (h1 ? h1.innerText : '') || document.title);
}
if (!out.firma) {
out.firma = txt(meta('meta[property="og:site_name"]') || meta('meta[name="author"]') || location.hostname.replace(/^www\./, ''));
}
// A non-trivial user text selection wins as the description (clear intent).
const sel = txt(window.getSelection ? String(window.getSelection()) : '');
if (sel && sel.length > 40) out.stellenbeschreibung = sel;
if (!out.stellenbeschreibung) out.stellenbeschreibung = txt(meta('meta[name="description"]') || meta('meta[property="og:description"]'));
const canon = document.querySelector('link[rel="canonical"]');
out.quelle_url = (canon && canon.href) || meta('meta[property="og:url"]') || location.href;
return out;
}
// Infer the "source" (art) select value from a URL host — mirrors the server.
function deriveArt(url) {
const host = (String(url || '').match(/^https?:\/\/([^/]+)/i) || [, ''])[1].toLowerCase();
if (!host) return 'Sonstiges';
if (host.indexOf('indeed') !== -1) return 'Indeed';
if (host.indexOf('stepstone') !== -1) return 'StepStone';
if (host.indexOf('arbeitsagentur') !== -1) return 'Arbeitsagentur';
if (/(linkedin|xing|monster|stellenanzeigen|kimeta|glassdoor|jobware|meinestadt|jobs\.|karriere\.)/.test(host)) return 'Online-Portal';
return 'Firmenwebsite';
}
function fillForm(data) {
data = data || {};
$('firma').value = data.firma || '';
$('stelle').value = data.stelle || '';
$('ort').value = data.ort || '';
$('gehalt').value = data.gehalt || '';
$('stellenbeschreibung').value = data.stellenbeschreibung || '';
$('quelle_url').value = data.quelle_url || '';
const art = deriveArt(data.quelle_url);
const sel = $('art');
for (const opt of sel.options) { if (opt.value === art) { sel.value = art; break; } }
}
async function scanActivePage() {
setStatus('Lese Seite aus …', '');
try {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
if (!tab || !tab.id) { setStatus('Keine aktive Seite gefunden.', 'err'); return; }
const results = await chrome.scripting.executeScript({ target: { tabId: tab.id }, func: extractJobFromPage });
const data = results && results[0] && results[0].result;
fillForm(data);
if (data && (data.stelle || data.firma)) setStatus('Ausgelesen - bitte prüfen und senden.', 'ok');
else setStatus('Konnte wenig auslesen - bitte manuell ergänzen.', '');
} catch (err) {
// chrome://, Web Store and a few CSP-locked pages can't be scripted.
setStatus('Diese Seite kann nicht automatisch ausgelesen werden - bitte manuell ausfüllen.', '');
}
}
// ---- Sending (via the background service worker) ---------------------------
function duplicateWarning(matches) {
const lines = (matches || []).slice(0, 5).map((m) => {
const parts = [m.firma, m.stelle].filter(Boolean).join(' — ');
const meta = [m.datum, m.status].filter(Boolean).join(', ');
return '• ' + parts + (meta ? ' (' + meta + ')' : '');
});
return 'Für diese Stelle scheint bereits eine Bewerbung zu existieren:\n\n' +
lines.join('\n') + '\n\nTrotzdem als weitere Bewerbung anlegen?';
}
function sendJob(payload) {
$('sendBtn').disabled = true;
setStatus('Wird gesendet …', '');
chrome.runtime.sendMessage({ type: 'IMPORT_JOB', payload: payload }, (resp) => {
if (chrome.runtime.lastError) {
$('sendBtn').disabled = false;
setStatus('Fehler: ' + chrome.runtime.lastError.message, 'err');
return;
}
if (resp && resp.duplicate) {
$('sendBtn').disabled = false;
if (confirm(duplicateWarning(resp.matches))) {
sendJob(Object.assign({}, payload, { force: true }));
} else {
setStatus('Abgebrochen (mögliches Duplikat).', '');
}
return;
}
if (!resp || !resp.ok) {
$('sendBtn').disabled = false;
setStatus((resp && resp.error) || 'Unbekannter Fehler.', 'err');
return;
}
const link = resp.openUrl ? ' <a href="' + resp.openUrl + '" target="_blank" rel="noopener">Entwurf öffnen</a>' : '';
setStatus('✓ ' + (resp.message || 'Als Entwurf angelegt.') + link, 'ok');
setTimeout(() => { $('sendBtn').disabled = false; }, 1500);
});
}
$('sendBtn').addEventListener('click', () => {
const payload = {
firma: $('firma').value.trim(),
stelle: $('stelle').value.trim(),
ort: $('ort').value.trim(),
gehalt: $('gehalt').value.trim(),
stellenbeschreibung: $('stellenbeschreibung').value.trim(),
quelle_url: $('quelle_url').value.trim(),
art: $('art').value,
};
if (!payload.firma || !payload.stelle) {
setStatus('Bitte mindestens Firma und Stelle angeben.', 'err');
return;
}
sendJob(payload);
});
$('rescanBtn').addEventListener('click', scanActivePage);
// Auto-extract as soon as the popup opens.
scanActivePage();