Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 22x 22x 22x 22x 1x 1x 1x 1x 1x 1x 26x 26x 26x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 2x 4x 1x 1x 1x 1x 1x 4x 4x 4x 1x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 3x 1x 4x 1x 1x 1x 1x 457x 457x 457x 457x 1x 1x 456x 456x 456x 456x 456x 456x 456x 456x 457x 446x 446x 457x 1325x 11x 11x 11x 1325x 436x 436x 436x 457x 22x 22x 436x 436x 457x 2x 2x 457x 436x 436x 457x 457x 1x 403x 403x 403x 403x 403x 403x 403x 403x | const TRACKING_PARAMS = new Set([
"ref",
"refid",
"trk",
"trackingid",
"gh_src",
"lever-origin",
"src",
"source",
"mkt_tok",
"fbclid",
"gclid",
]);
function isTrackingParam(name: string): boolean {
const lower = name.toLowerCase();
return lower.startsWith("utm_") || TRACKING_PARAMS.has(lower);
}
interface BoardNormalizer {
matchesHost: (host: string) => boolean;
normalize: (url: URL) => string | null;
}
function hostSuffix(suffix: string): (host: string) => boolean {
return (host) => host === suffix || host.endsWith(`.${suffix}`);
}
/**
* The job selected in Google's SERP detail overlay is identified only by the
* URL fragment: modern UI packs a "docid=<id>" into the base64 `#sv=` blob,
* the classic jobs UI uses `#…&htidocid=<id>`. Without it every job opened
* from one results page would collapse onto the same canonical URL.
*/
function googleJobDocId(hash: string): string | null {
const hti = hash.match(/[#&]htidocid=([^&]+)/);
if (hti) return decodeURIComponent(hti[1]);
const sv = hash.match(/[#&]sv=([^&]+)/);
if (!sv) return null;
try {
const b64 = decodeURIComponent(sv[1]).replace(/-/g, "+").replace(/_/g, "/");
const padded = b64 + "=".repeat((4 - (b64.length % 4)) % 4);
const decoded = atob(padded);
const match = decoded.match(/docid=([A-Za-z0-9_-]+={0,2})/);
return match ? match[1] : null;
} catch {
return null;
}
}
// Table-driven per-board rules; a null result falls through to the generic path.
const BOARD_NORMALIZERS: BoardNormalizer[] = [
{
matchesHost: hostSuffix("linkedin.com"),
normalize: (url) => {
const match = url.pathname.match(/\/jobs\/view\/(\d+)/);
return match ? `https://www.linkedin.com/jobs/view/${match[1]}` : null;
},
},
{
matchesHost: hostSuffix("indeed.com"),
normalize: (url) => {
if (!url.pathname.startsWith("/viewjob")) return null;
const jk = url.searchParams.get("jk");
return jk ? `https://${url.host}/viewjob?jk=${jk}` : null;
},
},
{
matchesHost: (host) => /(^|\.)google\.[a-z]{2,3}(\.[a-z]{2})?$/.test(host),
normalize: (url) => {
if (url.pathname !== "/search") return null;
const docid = googleJobDocId(url.hash);
return docid
? `https://www.google.com/search?jobdocid=${encodeURIComponent(docid)}`
: null;
},
},
];
export function canonicalize(rawUrl: string): string {
let url: URL;
try {
url = new URL(rawUrl);
} catch {
return rawUrl;
}
// Opaque, non-navigable identities (paste:<sha256>, doc:<sha256>) are
// already canonical — they carry no tracking params or trailing slash to
// normalize. Treating them as an http(s) URL would corrupt them: an opaque
// URL's `host` is "", so reconstructing `${protocol}//${host}${pathname}`
// below turns "paste:<hex>" into "paste://<hex>", which no longer matches
// PASTE_CANONICAL_URL_RE and breaks the PUT-key/body agreement the backend
// checks (KeyMismatchError).
if (url.protocol !== "http:" && url.protocol !== "https:") return rawUrl;
// Normalizers run before the hash is dropped — Google's job id lives there.
for (const board of BOARD_NORMALIZERS) {
if (board.matchesHost(url.host)) {
const normalized = board.normalize(url);
if (normalized) return normalized;
}
}
url.hash = "";
for (const name of [...url.searchParams.keys()]) {
if (isTrackingParam(name)) url.searchParams.delete(name);
}
let pathname = url.pathname;
if (pathname.length > 1 && pathname.endsWith("/")) {
pathname = pathname.slice(0, -1);
}
if (pathname === "/") pathname = "";
const search = url.searchParams.toString();
return `${url.protocol}//${url.host}${pathname}${search ? `?${search}` : ""}`;
}
export async function canonicalKey(rawUrl: string): Promise<string> {
const canonical = canonicalize(rawUrl);
const bytes = new TextEncoder().encode(canonical);
const digest = await crypto.subtle.digest("SHA-256", bytes);
return [...new Uint8Array(digest)]
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
}
|