Skip to content

Instantly share code, notes, and snippets.

@makeding
Created February 19, 2021 16:08
Show Gist options
  • Save makeding/d5d4584af8092f0fb4fe18e257af08e4 to your computer and use it in GitHub Desktop.
Save makeding/d5d4584af8092f0fb4fe18e257af08e4 to your computer and use it in GitHub Desktop.
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