Skip to content

Instantly share code, notes, and snippets.

@Nooshu
Nooshu / worker-css.js
Created Mar 15, 2021
Changing the font family of the BBC News website using a cloudflare worker.
View worker-css.js
const site = 'www.bbc.co.uk';
const subdomain1 = 'm.files.bbci.co.uk';
addEventListener('fetch', event => {
const request = event.request
event.respondWith(handleRequest(request))
});
async function handleRequest(request) {
const url = new URL(request.url);
@Nooshu
Nooshu / worker-css.js
Created Mar 11, 2021
Changing the font family of the BBC News website using a cloudflare worker.
View worker-css.js
// what are the domains we are wanting to modify
const site = 'www.bbc.co.uk';
const subdomain1 = 'm.files.bbci.co.uk';
// do this on a fetch
addEventListener('fetch', event => {
const request = event.request
event.respondWith(handleRequest(request))
});
@Nooshu
Nooshu / worker-remove-resource-hints.js
Created Mar 2, 2021
Simple example of how to remove resource hints from the HTML in the `<head>`
View worker-remove-resource-hints.js
// set the site we are modifying
const site = 'www.example.com';
// do this on a fetch
addEventListener('fetch', event => {
const request = event.request
const url = new URL(request.url)
event.respondWith(handleRequest(request))
});
@Nooshu
Nooshu / worker-remove-header.js
Created Mar 2, 2021
Simple example of using a CF Worker to remove a resource hint header.
View worker-remove-header.js
// set the site we are modifying
const site = 'www.example.com';
// do this on a fetch
addEventListener('fetch', event => {
const request = event.request
const url = new URL(request.url)
event.respondWith(handleRequest(request))
});
@Nooshu
Nooshu / worker-head-body-scripts.js
Created Mar 2, 2021
Easily adding multiple scripts to the head and body of a HTML page.
View worker-head-body-scripts.js
// set the site we are modifying
const site = 'www.example.com';
// do this on a fetch
addEventListener('fetch', event => {
const request = event.request
const url = new URL(request.url)
event.respondWith(handleRequest(request))
});
@Nooshu
Nooshu / worker-defer-async.js
Created Mar 2, 2021
Using a CF Worker to add `async` or `defer` to a script tag in the page
View worker-defer-async.js
// set the site we are modifying
const site = 'www.example.com';
// do this on a fetch
addEventListener('fetch', event => {
const request = event.request
const url = new URL(request.url)
event.respondWith(handleRequest(request))
});
@Nooshu
Nooshu / worker-inline-scripts.js
Created Mar 2, 2021
Use a CF Worker to add an inline script to the page
View worker-inline-scripts.js
// set the site we are modifying
const site = 'www.example.com';
// do this on a fetch
addEventListener('fetch', event => {
const request = event.request
const url = new URL(request.url)
event.respondWith(handleRequest(request))
});
@Nooshu
Nooshu / worker-inline-css.js
Created Mar 1, 2021
Use a CF worker to add inline CSS to the head.
View worker-inline-css.js
// set the site we are modifying
const site = 'www.example.com';
// do this on a fetch
addEventListener('fetch', event => {
const request = event.request
const url = new URL(request.url)
event.respondWith(handleRequest(request))
});
@Nooshu
Nooshu / worker-remove-elements.js
Created Mar 1, 2021
Get a CF Worker to remove selected elements from a pages HTML
View worker-remove-elements.js
// set the site we are modifying
const site = 'www.example.com';
// do this on a fetch
addEventListener('fetch', event => {
const request = event.request
const url = new URL(request.url)
event.respondWith(handleRequest(request))
});
@Nooshu
Nooshu / worker-modify-css-js.js
Created Mar 1, 2021
Make a CF worker modify a CSS file and / or a JavaScript file on the fly.
View worker-modify-css-js.js
// set the site we are modifying
const site = 'www.example.com';
// do this on a fetch
addEventListener('fetch', event => {
const request = event.request
const url = new URL(request.url)
event.respondWith(handleRequest(request))
});