Skip to content

Instantly share code, notes, and snippets.

@makeding
Created Feb 19, 2021
Embed
What would you like to do?
b23 cloudflare worker
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Respond to the request
* @param {Request} request
*/
async function handleRequest(request) {
let url = request.url.substr(8)
console.log(url)
url = url.substr(url.indexOf('/') + 1).replace('https://b23.tv','').replace('b23.tv','').replaceAll('/','')
console.log('https://b23.tv/' + url)
let a = await fetch('https://b23.tv/' + url,{
redirect: 'manual'
})
console.log(a.headers.get('Location'))
try {
return new Response(a.headers.get('Location').split('?')[0], {status: 200})
}catch (error){
return new Response('https://www.bilibili.com', {status: 200})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment