Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
sideshowbarker committed Jun 16, 2022
1 parent 825dc5d commit d10b76f
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
94 changes: 94 additions & 0 deletions coi-serviceworker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*! coi-serviceworker v0.1.6 - Guido Zuidhof, licensed under MIT */
if (typeof window === 'undefined') {
self.addEventListener("install", () => self.skipWaiting());
self.addEventListener("activate", (event) => event.waitUntil(self.clients.claim()));

self.addEventListener("message", (ev) => {
if (ev.data && ev.data.type === "deregister") {
self.registration
.unregister()
.then(() => {
return self.clients.matchAll();
})
.then(clients => {
clients.forEach((client) => client.navigate(client.url));
});
}
});

self.addEventListener("fetch", function (event) {
if (event.request.cache === "only-if-cached" && event.request.mode !== "same-origin") {
return;
}

event.respondWith(
fetch(event.request)
.then((response) => {
if (response.status === 0) {
return response;
}

const newHeaders = new Headers(response.headers);
newHeaders.set("Cross-Origin-Embedder-Policy", "require-corp");
newHeaders.set("Cross-Origin-Opener-Policy", "same-origin");
newHeaders.set("Cross-Origin-Resource-Policy", "cross-origin");

return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: newHeaders,
});
})
.catch((e) => console.error(e))
);
});

} else {
(() => {
// You can customize the behavior of this script through a global `coi` variable.
const coi = {
shouldRegister: () => true,
shouldDeregister: () => false,
doReload: () => window.location.reload(),
quiet: false,
...window.coi
}

const n = navigator;
if (coi.shouldDeregister() && n.serviceWorker && n.serviceWorker.controller) {
n.serviceWorker.controller.postMessage({ type: "deregister" });
}

// If we're already coi: do nothing. Perhaps it's due to this script doing its job, or COOP/COEP are
// already set from the origin server. Also if the browser has no notion of crossOriginIsolated, just give up here.
if (window.crossOriginIsolated !== false || !coi.shouldRegister()) return;

if (!window.isSecureContext) {
!coi.quiet && console.log("COOP/COEP Service Worker not registered, a secure context is required.");
return;
}

// In some environments (e.g. Chrome incognito mode) this won't be available
if (n.serviceWorker) {
n.serviceWorker.register(window.document.currentScript.src).then(
(registration) => {
!coi.quiet && console.log("COOP/COEP Service Worker registered", registration.scope);

registration.addEventListener("updatefound", () => {
!coi.quiet && console.log("Reloading page to make use of updated COOP/COEP Service Worker.");
coi.doReload()
});

// If the registration is active, but it's not controlling the page
if (registration.active && !n.serviceWorker.controller) {
!coi.quiet && console.log("Reloading page to make use of COOP/COEP Service Worker.");
coi.doReload()
}
},
(err) => {
!coi.quiet && console.error("COOP/COEP Service Worker failed to register:", err);
}
);
}
})();
}
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html><html lang=en-US><head><meta charset=utf-8>
<title>The Nu Html Checker (v.Nu)</title>
<link href="site/icon.png" rel="icon">
<script src="coi-serviceworker.js"></script>
<style>
html {
background: #dde5d9 url("data:image/gif;base64,R0lGODlhBAAEAIAAANra2v///yH5BAAAAAAALAAAAAAEAAQAAAIFTGB4xlcAOw==") repeat 0 0;
Expand Down Expand Up @@ -136,7 +137,7 @@
</style>
</head>
<body>
<h1>The Nu Html Checker (v.Nu) <a href="https://matrix.to/#/#validator_validator:gitter.im" ><img src="https://img.shields.io/badge/[matrix]-chat%20%E2%86%92-brightgreen.svg" alt="Chat room"></a> <a href="https://github.com/validator/validator/releases/latest" ><img src="https://img.shields.io/badge/download-latest%20%E2%86%92-blue.svg" alt="Download latest"></a> </h1>
<h1>The Nu Html Checker (v.Nu) <a href="https://matrix.to/#/#validator_validator:gitter.im" ><img src="resources/matrix-chat.svg" alt="Chat room"></a> <a href="https://github.com/validator/validator/releases/latest" ><img src="resources/download-latest.svg" alt="Download latest"></a> </h1>

<p>
The Nu Html Checker (v.Nu) helps you <a href="https://validator.w3.org/nu/about.html#why-validate">catch unintended mistakes in your HTML, CSS, and SVG</a>. It enables you to <a href="https://validator.github.io/validator/#usage">batch-check documents from the command line</a> and from other scripts/apps, and to <a href="https://validator.github.io/validator/#standalone">deploy your own instance of the checker as a service</a> (like <a href="https://validator.w3.org/nu/">validator.w3.org/nu</a>).
Expand Down
1 change: 1 addition & 0 deletions resources/download-latest.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/matrix-chat.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d10b76f

Please sign in to comment.