// ==UserScript== // @name Job tracker capture // @namespace https://www.adam-french.co.uk/ // @version 2.2.0 // @description Add the job posting you are looking at to the tracker at /jobs/. // @match *://*/* // @noframes // @run-at document-idle // @grant GM_xmlhttpRequest // @grant GM_getValue // @grant GM_setValue // @grant GM_registerMenuCommand // @connect priv.adam-french.co.uk // @connect www.adam-french.co.uk // @connect adam-french.co.uk // @connect localhost // @downloadURL https://priv.adam-french.co.uk/jobs/job-capture.user.js // @updateURL https://priv.adam-french.co.uk/jobs/job-capture.user.js // ==/UserScript== /* * Browser half of the job tracker's capture feature. The server half is * internal/handlers/handle_job_capture.go in the job-tracker repo (three * token-guarded REST routes) and internal/claude/posting.go (the Claude call * that reads the page). * * INSTALL: open /jobs/ and press "Install capture script", or visit * /jobs/job-capture.user.js directly — Violentmonkey offers to install any URL * ending in .user.js. It lives in web/public/ so the tracker serves it, and the * @updateURL above lets Violentmonkey pick up new versions by itself. That * only happens when @version changes, so BUMP @version WITH EVERY EDIT. * * CONFIGURE: Violentmonkey menu -> "Configure job capture". It asks for the * API base (default below; http://localhost/jobs/api for the dev stack) and * the token, which is generated on the tracker's Settings page (/jobs/settings) * and shown there once. Both are kept in Violentmonkey's own storage. THE TOKEN MUST NEVER BE WRITTEN INTO THIS FILE: * it is served publicly. * * WHAT RUNS WHERE: the script matches every site so that the menu command * "Capture this job" works on any company's careers page, but on a page that * is not a known job site it does nothing at all until that command is used — * no button, no request. On the known sites (JOB_SITES) it shows a button and * asks the tracker whether the posting is already there. * * Requests go through GM_xmlhttpRequest, which is exempt from CORS (the site * sends no CORS headers), with `anonymous` set so no cookies travel: the * bearer token is the only credential. */ (function () { "use strict"; const DEFAULT_BASE = "https://priv.adam-french.co.uk/jobs/api"; // Hosts where the button appears unprompted. Add an ATS here when one turns // up; nothing else needs to change, because the fields are read by Claude // from the page text rather than by per-site selectors. const JOB_SITES = [ /(^|\.)linkedin\.com$/, /(^|\.)greenhouse\.io$/, /(^|\.)lever\.co$/, /(^|\.)ashbyhq\.com$/, /(^|\.)myworkdayjobs\.com$/, /(^|\.)workable\.com$/, /(^|\.)smartrecruiters\.com$/, /(^|\.)teamtailor\.com$/, /(^|\.)bamboohr\.com$/, /(^|\.)recruitee\.com$/, /(^|\.)breezy\.hr$/, /(^|\.)icims\.com$/, /(^|\.)jobvite\.com$/, /(^|\.)indeed\.com$/, /(^|\.)welcometothejungle\.com$/, ]; // Where a posting's text usually lives, most specific first. This is a hint, // not a parser: it only narrows what is sent so that a search page's list of // other jobs does not drown out the open one. If nothing matches, the whole // body is sent and Claude copes. const CONTENT_SELECTORS = [ ".jobs-search__job-details--container", // LinkedIn, search/collections pane ".jobs-details", ".job-view-layout", "main", '[role="main"]', "article", ]; // Mirrors maxPageRunes in handle_job_capture.go, which cuts again anyway. const MAX_TEXT = 40000; const STATUS_LABELS = { saved: "Saved", applied: "Applied", screening: "Screening", assessment: "Assessment", interviewing: "Interviewing", offer: "Offer", rejected: "Rejected", withdrawn: "Withdrawn", }; function onJobSite() { const host = location.hostname.toLowerCase(); if (!JOB_SITES.some((re) => re.test(host))) return false; // LinkedIn is mostly not job pages. if (/(^|\.)linkedin\.com$/.test(host)) return location.pathname.startsWith("/jobs"); return true; } function pageText() { for (const selector of CONTENT_SELECTORS) { const el = document.querySelector(selector); const text = el?.innerText?.trim() ?? ""; // A near-empty match is a layout shell, not the posting. if (text.length > 200) return text.slice(0, MAX_TEXT); } return (document.body.innerText ?? "").trim().slice(0, MAX_TEXT); } // --- configuration ------------------------------------------------------- // Before 2.0.0 the tracker lived inside the site's backend, at /api // with routes under /jobs/capture. It is now its own app at /jobs/api // with routes under /capture, so a base saved by an older version is moved // across rather than left pointing at routes that no longer exist. // From 2.2.0 the tracker is on its own host, priv., so a saved // www/apex base is moved there too (www now only 301s, which drops a POST). function migrateBase(base) { return base .replace(/\/api$/, "/jobs/api") .replace(/\/jobs\/jobs\/api$/, "/jobs/api") .replace(/^https:\/\/(www\.)?adam-french\.co\.uk\/jobs\/api$/, DEFAULT_BASE); } const config = { get base() { return migrateBase((GM_getValue("base", "") || DEFAULT_BASE).replace(/\/+$/, "")); }, get token() { return GM_getValue("token", ""); }, }; function configure() { const base = prompt( "Job tracker API base (no trailing slash)", config.base, ); if (base === null) return false; const token = prompt( "Capture token (generate one on the tracker's Settings page)", config.token, ); if (token === null) return false; GM_setValue("base", base.trim()); GM_setValue("token", token.trim()); return true; } // --- API ----------------------------------------------------------------- function api(method, path, body) { return new Promise((resolve, reject) => { GM_xmlhttpRequest({ method, url: config.base + path, headers: { Authorization: `Bearer ${config.token}`, "Content-Type": "application/json", }, data: body ? JSON.stringify(body) : undefined, anonymous: true, // Above the server's own two-minute wait on Claude, so its error // arrives rather than this one. timeout: 130000, onload(res) { let json = null; try { json = JSON.parse(res.responseText); } catch { // Not JSON: an nginx error page. The status says enough. } if (res.status >= 200 && res.status < 300) return resolve(json); const hint = res.status === 401 ? "token rejected — use Configure job capture" : (json?.error ?? `HTTP ${res.status}`); reject(new Error(hint)); }, onerror: () => reject(new Error(`cannot reach ${config.base}`)), ontimeout: () => reject(new Error("timed out")), }); }); } // --- UI ------------------------------------------------------------------ // Everything lives in a closed shadow root so the host page's CSS cannot // restyle it and its scripts cannot read the fields. Nodes are built with // createElement throughout: some of these sites enforce Trusted Types, under // which innerHTML throws. const CSS = ` :host { all: initial; } * { box-sizing: border-box; font-family: system-ui, sans-serif; } .fab { position: fixed; right: 16px; bottom: 16px; z-index: 2147483647; padding: 8px 14px; border: 1px solid #1f2937; border-radius: 999px; background: #fdfcf8; color: #1f2937; font-size: 13px; font-weight: 600; cursor: pointer; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25); } .fab.tracked { background: #1f2937; color: #fdfcf8; } .panel { position: fixed; right: 16px; bottom: 60px; z-index: 2147483647; width: 340px; max-width: calc(100vw - 32px); max-height: calc(100vh - 80px); overflow: auto; padding: 12px; border: 1px solid #1f2937; border-radius: 8px; background: #fdfcf8; color: #1f2937; font-size: 13px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3); display: flex; flex-direction: column; gap: 8px; } .panel[hidden] { display: none; } h2 { margin: 0; font-size: 14px; } label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: #6b7280; } input, textarea, select { padding: 5px 7px; border: 1px solid #d1d5db; border-radius: 4px; background: #fff; color: #111827; font-size: 13px; width: 100%; } textarea { resize: vertical; min-height: 44px; } .description { min-height: 120px; font-size: 11px; } summary { cursor: pointer; font-size: 11px; color: #6b7280; } .row { display: flex; gap: 8px; align-items: center; } .row > button { flex: 1; } button.action { padding: 6px 10px; border: 1px solid #1f2937; border-radius: 4px; background: #fff; color: #1f2937; font-size: 13px; cursor: pointer; } button.primary { background: #1f2937; color: #fdfcf8; } button:disabled { opacity: 0.5; cursor: default; } .message { min-height: 16px; font-size: 12px; color: #6b7280; } .message.error { color: #b91c1c; } `; function h(tag, props = {}, ...children) { const el = document.createElement(tag); for (const [key, value] of Object.entries(props)) { if (key === "class") el.className = value; else if (key.startsWith("on")) el.addEventListener(key.slice(2), value); else el[key] = value; } el.append(...children); return el; } let ui = null; function buildUi() { if (ui) return ui; const host = document.createElement("div"); const root = host.attachShadow({ mode: "closed" }); // A constructed stylesheet is not subject to the page's style-src CSP, // which would otherwise drop an injected