Greasy Fork

Greasy Fork is available in English.

Direct Proxy Helper - 直接代理助手

直接使用 GM_xmlhttpRequest 实现代理请求,无需外部服务器,绕过 CORS 限制

作者
Usable5052
日安装量
0
总安装量
15
评分
0 0 0
版本
1.0.3
创建于
2025-10-12
更新于
2025-10-15
大小
19.8 KB
许可证
MIT
适用于
所有网站

========== 使用说明 ==========

这是一个完全独立的代理脚本,直接使用 GM_xmlhttpRequest 实现,无需任何外部服务器。

主要特性:
✅ 完全绕过 CORS 限制
✅ 可修改任意请求头
✅ 支持所有 HTTP 方法 (GET, POST, PUT, PATCH, DELETE)
✅ 支持多种响应类型 (text, json, blob, arraybuffer, document)
✅ Promise 和回调两种方式
✅ Fetch API 兼容接口
✅ 进度监控和超时控制
✅ 支持 JSONP 请求
✅ 支持匿名请求(不发送 cookies)

========== 使用示例 ==========

1. 基本 GET 请求:
ProxyHelper.get('https://api.example.com/users')
.then(response => {
console.log('数据:', response.data);
console.log('状态:', response.status);
console.log('响应头:', response.headers);
})
.catch(error => console.error('错误:', error));

2. POST 请求(自定义请求头):
ProxyHelper.post('https://api.example.com/users',
{ name: 'John', email: '[email protected]' },
{
headers: {
'Authorization': 'Bearer your-token-here',
'X-Custom-Header': 'custom-value',
'Content-Type': 'application/json'
}
}
).then(res => console.log(res.data));

3. 使用 Fetch 风格:
ProxyHelper.fetch('https://api.example.com/data', {
method: 'POST',
headers: {
'Authorization': 'Bearer token',
'Content-Type': 'application/json'
},
body: JSON.stringify({ key: 'value' })
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));

4. 完整配置的请求:
ProxyHelper.request({
url: 'https://api.example.com/data',
method: 'GET',
headers: {
'User-Agent': 'CustomAgent/1.0',
'Referer': 'https://example.com',
'Authorization': 'Bearer token'
},
responseType: 'json',
timeout: 10000,
anonymous: false, // 是否匿名(不发送 cookies)
onSuccess: (response) => {
console.log('成功:', response.data);
},
onError: (error) => {
console.error('失败:', error);
},
onProgress: (progress) => {
console.log('进度:', progress.percentage.toFixed(2) + '%');
}
});

5. 下载文件(Blob):
ProxyHelper.request({
url: 'https://example.com/file.pdf',
method: 'GET',
responseType: 'blob'
}).then(response => {
const blob = response.data;
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'file.pdf';
a.click();
URL.revokeObjectURL(url);
});

6. JSONP 请求:
ProxyHelper.jsonp('https://api.example.com/data', {
callbackParam: 'callback', // 回调参数名
timeout: 5000
}).then(response => {
console.log('JSONP 数据:', response.data);
});

7. 修改 Referer 和 Origin(绕过防盗链):
ProxyHelper.get('https://protected-api.example.com/image.jpg', {
headers: {
'Referer': 'https://allowed-domain.com/',
'Origin': 'https://allowed-domain.com'
},
responseType: 'blob'
}).then(response => {
const imgUrl = URL.createObjectURL(response.data);
document.querySelector('img').src = imgUrl;
});

8. 跨域 API 调用:
ProxyHelper.fetch('https://cors-blocked-api.com/endpoint', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your-api-key'
},
body: JSON.stringify({ query: 'data' })
})
.then(res => res.json())
.then(data => console.log(data));

========== 配置方法 ==========

// 启用/禁用调试日志
ProxyHelper.setDebug(false);

// 设置默认超时时间(毫秒)
ProxyHelper.setTimeout(60000);

========== 优势 ==========

相比普通的 fetch 或 XMLHttpRequest:
1. 完全绕过 CORS 限制
2. 可以修改任意请求头(包括 Referer、Origin、User-Agent 等)
3. 支持跨域访问任何网站
4. 不受同源策略限制

相比使用 Cloudflare Worker:
1. 无需部署外部服务器
2. 延迟更低(直接访问目标)
3. 无需维护成本
4. 完全免费