Created
February 19, 2021 16:08
-
-
Save makeding/d5d4584af8092f0fb4fe18e257af08e4 to your computer and use it in GitHub Desktop.
b23 cloudflare worker
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
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