mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
fix: fix 404 on everypage
This commit is contained in:
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">
|
||||
<h1>Page not found</h1>
|
||||
<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>
|
||||
`;
|
||||
|
||||
@@ -63,6 +65,23 @@ describe("errorPageKitten", () => {
|
||||
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 () => {
|
||||
document.title = "SEQTA Learn";
|
||||
document.body.innerHTML = '<div id="container"></div>';
|
||||
|
||||
@@ -16,12 +16,36 @@ const CARD_HTML = `<h1>404 Not Found</h1>
|
||||
</div>
|
||||
<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). */
|
||||
export function isSeqta404Page(): boolean {
|
||||
if (document.getElementById("container")) return false;
|
||||
const heading = document.querySelector(".message > h1");
|
||||
const text = heading?.textContent ?? document.title;
|
||||
return /not found/i.test(text) || /404/.test(document.title);
|
||||
const message = document.querySelector(".message");
|
||||
if (!message) return false;
|
||||
return isSeqtaRebranded404Message(message);
|
||||
}
|
||||
|
||||
export function mountErrorPageKitten(): () => void {
|
||||
|
||||
Reference in new issue
Block a user