Created
September 7, 2022 11:41
-
-
Save dwsmart/1f136ba9698ede0067237a0745dbd2a7 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* a cloudflare worker to remove the script tag they inject into the head if you have a cloudflare app installed. | |
* WARNING: some apps may not work if you remove this script tag!!! But things like logflare that add no js of | |
* their own should be fine. | |
*/ | |
addEventListener('fetch', event => { | |
const request = event.request | |
event.respondWith(handleRequest(request)) | |
}); | |
async function handleRequest(request) { | |
const url = new URL(request.url); | |
let oldResponse = await fetch(url.toString(), request) | |
let newResponse = new HTMLRewriter() | |
.on("script[src*='/cdn-cgi/apps/head/']", new removeScript()) | |
.transform(oldResponse) | |
return newResponse | |
} | |
class removeScript { | |
element(element) { | |
element.remove(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment