Created
June 9, 2023 18:15
-
-
Save Erisa/728c389c05f421098a22d4581b4a37f8 to your computer and use it in GitHub Desktop.
xkcd feed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addEventListener("fetch", event => { | |
event.respondWith(handleRequest(event.request)) | |
}) | |
async function handleRequest(request) { | |
let url = 'https://xkcd.com/rss.xml' | |
let match = /(<img(?:[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\n\uD800-\uDFFF])*? alt="((?:[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\n\uD800-\uDFFF])*?)"(?:[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\n\uD800-\uDFFF])*?><\/description>)/ig | |
let replace = "$1<p></p></description><summary>$2</summary>" | |
var resp = await fetch(url) | |
var body = await resp.text() | |
newbody = body.replaceAll(match, replace) | |
return new Response(newbody, { | |
headers: { | |
"content-type": "application/xml" | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment