fix: fix 404 on everypage

This commit is contained in:
AdenMGB committed 2026-09-29 08:56:40 +09:30
1 parent d4cd2affe2
commit ef781a78ff
2 files changed
+46 -3

No files matched your search

@@ -24,6 +24,8 @@ const REBRANDED_404_BODY = `
<div class="message"> <div class="message">
<h1>Page not found</h1> <h1>Page not found</h1>
<p>We can't find the page you're looking for.</p> <p>We can't find the page you're looking for.</p>
<p>It may have been moved, deleted or the link might be out of date.</p>
<p>Ref: 404</p>
</div> </div>
`; `;
@@ -63,6 +65,23 @@ describe("errorPageKitten", () => {
expect(isSeqta404Page()).toBe(false); expect(isSeqta404Page()).toBe(false);
}); });
it("does not detect generic 404 pages on other sites", () => {
document.title = "404 - Not Found";
document.body.innerHTML = `
<div class="message">
<h1>Page not found</h1>
<p>Sorry, this page does not exist.</p>
</div>
`;
expect(isSeqta404Page()).toBe(false);
});
it("does not treat a 404 title alone as SEQTA", () => {
document.title = "Error 404";
document.body.innerHTML = "<p>Not found</p>";
expect(isSeqta404Page()).toBe(false);
});
it("plugin run is a no-op outside a 404 page", async () => { it("plugin run is a no-op outside a 404 page", async () => {
document.title = "SEQTA Learn"; document.title = "SEQTA Learn";
document.body.innerHTML = '<div id="container"></div>'; document.body.innerHTML = '<div id="container"></div>';
+27 -3
View File
@@ -16,12 +16,36 @@ const CARD_HTML = `<h1>404 Not Found</h1>
</div> </div>
<a href="http://www.seqta.com.au">SEQTA</a>`; <a href="http://www.seqta.com.au">SEQTA</a>`;
function normalizePageText(text: string): string {
return text
.replace(/[\u2018\u2019]/g, "'")
.replace(/\s+/g, " ")
.trim();
}
/** Fingerprints SEQTA's rebranded standalone 404 — not generic site 404s. */
function isSeqtaRebranded404Message(message: Element): boolean {
const heading = message.querySelector("h1");
if (normalizePageText(heading?.textContent ?? "").toLowerCase() !== "page not found") {
return false;
}
const body = normalizePageText(message.textContent ?? "");
return (
body.includes("We can't find the page you're looking for") &&
body.includes(
"It may have been moved, deleted or the link might be out of date.",
) &&
body.includes("Ref: 404")
);
}
/** Standalone SEQTA 404 document — not the SPA (#container). */ /** Standalone SEQTA 404 document — not the SPA (#container). */
export function isSeqta404Page(): boolean { export function isSeqta404Page(): boolean {
if (document.getElementById("container")) return false; if (document.getElementById("container")) return false;
const heading = document.querySelector(".message > h1"); const message = document.querySelector(".message");
const text = heading?.textContent ?? document.title; if (!message) return false;
return /not found/i.test(text) || /404/.test(document.title); return isSeqtaRebranded404Message(message);
} }
export function mountErrorPageKitten(): () => void { export function mountErrorPageKitten(): () => void {