Skip to content

Instantly share code, notes, and snippets.

@RangerMauve
Last active October 26, 2018 20:12
Show Gist options
  • Save RangerMauve/8178c58245d6c9a05003c34fe3ecbbc1 to your computer and use it in GitHub Desktop.
Save RangerMauve/8178c58245d6c9a05003c34fe3ecbbc1 to your computer and use it in GitHub Desktop.
Patch `window.fetch` to support dat:// URLs
window._fetch = fetch
window.fetch = async function(url) {
if(url.startsWith("dat://")) {
const parsed = new URL(url)
const archive = await DatArchive.load(`dat://${parsed.hostname}`)
return {
text: async () => {
return archive.readFile(parsed.path, "utf8")
}
}
} else {
return _fetch(url)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment