这个代码年久失修了,你试试看,可能要改一些地方
- // List of domains bind to your WorkersProxy.
- const domain_list = ['https://cdn.reverse-proxy.live/', 'https://ytb.yanyu.workers.dev/']
- // Website you intended to retrieve for users.
- const upstream = 'https://www.youtube.com/'
- // Website you intended to retrieve for users using mobile devices.
- const upstream_mobile = 'https://www.youtube.com/'
- // Countries and regions where you wish to suspend your service.
- const blocked_region = []
- // IP addresses which you wish to block from using your service.
- const blocked_ip_address = []
- addEventListener('fetch', event => {
- event.respondWith(fetchAndApply(event.request));
- })
- async function fetchAndApply(request) {
- const region = request.headers.get('cf-ipcountry').toUpperCase();
- const ip_address = request.headers.get('cf-connecting-ip');
- const user_agent = request.headers.get('user-agent');
- let response = null;
- let url = request.url;
- if (await device_status(user_agent)){
- upstream_domain = upstream
- } else {
- upstream_domain = upstream_mobile
- }
- for(let domain of domain_list) {
- url = url.replace(domain, upstream_domain)
- };
- if (blocked_region.includes(region)) {
- response = new Response('Access denied: WorkersProxy is not available in your region yet.', {
- status: 403
- });
- } else if(blocked_ip_address.includes(ip_address)){
- response = new Response('Access denied: Your IP address is blocked by WorkersProxy.', {
- status: 403
- });
- } else{
- let method = request.method;
- let headers = request.headers;
- response = fetch(url, {
- method: method,
- headers: headers
- })
- }
- return response;
- }
- async function device_status (userAgentInfo) {
- var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
- var flag = true;
- for (var v = 0; v < Agents.length; v++) {
- if (userAgentInfo.indexOf(Agents[v]) > 0) {
- flag = false;
- break;
- }
- }
- return flag;
- }
复制代码
|