use redirect for bingAI

This commit is contained in:
James Feng Cao 2023-07-18 10:54:53 +08:00
parent a2c2729725
commit 33d2db03b7
9 changed files with 272 additions and 67 deletions

View File

@ -1,29 +1,119 @@
const SYDNEY_ORIGIN = 'https://sydney.bing.com';
const KEEP_REQ_HEADERS = [
'accept',
'accept-encoding',
'accept-language',
'connection',
'cookie',
'upgrade',
'user-agent',
'sec-websocket-extensions',
'sec-websocket-key',
'sec-websocket-version',
'x-request-id',
'content-length',
'content-type',
'access-control-request-headers',
'access-control-request-method',
];
const IP_RANGE = [
['3.2.50.0', '3.5.31.255'], //192,000
['3.12.0.0', '3.23.255.255'], //786,432
['3.30.0.0', '3.33.34.255'], //205,568
['3.40.0.0', '3.63.255.255'], //1,572,864
['3.80.0.0', '3.95.255.255'], //1,048,576
['3.100.0.0', '3.103.255.255'], //262,144
['3.116.0.0', '3.119.255.255'], //262,144
['3.128.0.0', '3.247.255.255'], //7,864,320
];
/**
* 随机整数 [min,max)
* @param {number} min
* @param {number} max
* @returns
*/
const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min)) + min;
/**
* ip int
* @param {string} ip
* @returns
*/
const ipToInt = (ip) => {
const ipArr = ip.split('.');
let result = 0;
result += +ipArr[0] << 24;
result += +ipArr[1] << 16;
result += +ipArr[2] << 8;
result += +ipArr[3];
return result;
};
/**
* int ip
* @param {number} intIP
* @returns
*/
const intToIp = (intIP) => {
return `${(intIP >> 24) & 255}.${(intIP >> 16) & 255}.${(intIP >> 8) & 255}.${intIP & 255}`;
};
const getRandomIP = () => {
const randIndex = getRandomInt(0, IP_RANGE.length);
const startIp = IP_RANGE[randIndex][0];
const endIp = IP_RANGE[randIndex][1];
const startIPInt = ipToInt(startIp);
const endIPInt = ipToInt(endIp);
const randomInt = getRandomInt(startIPInt, endIPInt);
const randomIP = intToIp(randomInt);
return randomIP;
};
export default {
async fetch(req, _env) {
let url = req.url;
let iSlash = url.indexOf('/',11);
let nUrl = "https://www.bing.com/"+url.substring(iSlash+1);
return goUrl(req, nUrl);
}
}
/**
* fetch
* @param {Request} request
* @param {*} env
* @param {*} ctx
* @returns
*/
async fetch(request, env, ctx) {
const currentUrl = new URL(request.url);
const targetUrl = new URL(SYDNEY_ORIGIN + currentUrl.pathname + currentUrl.search);
function goUrl(request, url) {
//构建 fetch 参数
let fp = {
method: request.method,
headers: {}
}
//保留头部信息
let reqHeaders = new Headers(request.headers);
let dropHeaders = ["cookie","user-agent","accept","accept-language"];
let he = reqHeaders.entries();
for (let h of he) {
let key = h[0],
value = h[1];
if (dropHeaders.includes(key)) {
fp.headers[key] = value;
const newHeaders = new Headers();
request.headers.forEach((value, key) => {
// console.log(`old : ${key} : ${value}`);
if (KEEP_REQ_HEADERS.includes(key)) {
newHeaders.set(key, value);
}
});
newHeaders.set('host', targetUrl.host);
newHeaders.set('origin', targetUrl.origin);
newHeaders.set('referer', 'https://www.bing.com/search?q=Bing+AI');
const randIP = getRandomIP();
// console.log('randIP : ', randIP);
newHeaders.set('X-Forwarded-For', randIP);
const oldUA = request.headers.get('user-agent');
const isMobile = oldUA.includes('Mobile') || oldUA.includes('Android');
if (isMobile) {
newHeaders.set(
'user-agent',
'Mozilla/5.0 (iPhone; CPU iPhone OS 15_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.7 Mobile/15E148 Safari/605.1.15 BingSapphire/1.0.410427012'
);
} else {
newHeaders.set('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35');
}
}
return fetch(url, fp);
}
// newHeaders.forEach((value, key) => console.log(`${key} : ${value}`));
const newReq = new Request(targetUrl, {
method: request.method,
headers: newHeaders,
body: request.body,
});
// console.log('request url : ', newReq.url);
const res = await fetch(newReq);
return res;
},
};

1
en/searchurl/cloudflare/node_modules/.mf/cf.json generated vendored Normal file
View File

@ -0,0 +1 @@
{"clientTcpRtt":172,"longitude":"120.60200","latitude":"31.30930","tlsCipher":"AEAD-AES256-GCM-SHA384","continent":"AS","asn":4134,"clientAcceptEncoding":"br, gzip, deflate","country":"CN","tlsClientAuth":{"certIssuerDNLegacy":"","certIssuerSKI":"","certSubjectDNRFC2253":"","certSubjectDNLegacy":"","certFingerprintSHA256":"","certNotBefore":"","certSKI":"","certSerial":"","certIssuerDN":"","certVerified":"NONE","certNotAfter":"","certSubjectDN":"","certPresented":"0","certRevoked":"0","certIssuerSerial":"","certIssuerDNRFC2253":"","certFingerprintSHA1":""},"tlsExportedAuthenticator":{"clientFinished":"b7f5ebe4898f01fbdbf9b0a444e1edc7956472268f27576d15fe6e048855ae5fe9f514231998caf937773f6a53901960","clientHandshake":"44f40162794883f93892c883c4121ca289621ad38b27615555cc0f471283da68ad39a438b0e956abc6613792f5fb81de","serverHandshake":"d3ec250200a505c5bc98a049d3f63720e3baea922338e6f94d61a28d9dfed9c1078dc8fa74e83f6719938122e6887a85","serverFinished":"710a654a0cfdd69ce712c7464801d1661f5b797ddd3cccf7f78f4abbd34564ebb7e9c00282fe7923875226284bde9b67"},"tlsVersion":"TLSv1.3","city":"Suzhou","timezone":"Asia/Shanghai","colo":"SJC","region":"Jiangsu","requestPriority":"","botManagement":{"corporateProxy":false,"verifiedBot":false,"ja3Hash":"0cce74b0d9b7f8528fb2181588d23793","staticResource":false,"detectionIds":{},"score":2},"clientTrustScore":2,"httpProtocol":"HTTP/1.1","regionCode":"JS","asOrganization":"China Telecom","edgeRequestKeepAliveStatus":1}

View File

@ -0,0 +1,134 @@
const SYDNEY_ORIGIN = 'https://sydney.bing.com';
const KEEP_REQ_HEADERS = [
'accept',
'accept-encoding',
'accept-language',
'connection',
'cookie',
'upgrade',
'user-agent',
'sec-websocket-extensions',
'sec-websocket-key',
'sec-websocket-version',
'x-request-id',
'content-length',
'content-type',
'access-control-request-headers',
'access-control-request-method',
];
const IP_RANGE = [
['3.2.50.0', '3.5.31.255'], //192,000
['3.12.0.0', '3.23.255.255'], //786,432
['3.30.0.0', '3.33.34.255'], //205,568
['3.40.0.0', '3.63.255.255'], //1,572,864
['3.80.0.0', '3.95.255.255'], //1,048,576
['3.100.0.0', '3.103.255.255'], //262,144
['3.116.0.0', '3.119.255.255'], //262,144
['3.128.0.0', '3.247.255.255'], //7,864,320
];
/**
* 随机整数 [min,max)
* @param {number} min
* @param {number} max
* @returns
*/
const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min)) + min;
/**
* ip int
* @param {string} ip
* @returns
*/
const ipToInt = (ip) => {
const ipArr = ip.split('.');
let result = 0;
result += +ipArr[0] << 24;
result += +ipArr[1] << 16;
result += +ipArr[2] << 8;
result += +ipArr[3];
return result;
};
/**
* int ip
* @param {number} intIP
* @returns
*/
const intToIp = (intIP) => {
return `${(intIP >> 24) & 255}.${(intIP >> 16) & 255}.${(intIP >> 8) & 255}.${intIP & 255}`;
};
const getRandomIP = () => {
const randIndex = getRandomInt(0, IP_RANGE.length);
const startIp = IP_RANGE[randIndex][0];
const endIp = IP_RANGE[randIndex][1];
const startIPInt = ipToInt(startIp);
const endIPInt = ipToInt(endIp);
const randomInt = getRandomInt(startIPInt, endIPInt);
const randomIP = intToIp(randomInt);
return randomIP;
};
async function goUrl(request, url) {
let fp = {
method: request.method
};
fp.headers = new Headers(request.headers);
for(var i = 2; i < arguments.length-1; i=i+2){
fp.headers[arguments[i]] = arguments[i+1];
}
return await fetch(url, fp);
}
export default {
/**
* fetch
* @param {Request} request
* @param {*} env
* @param {*} ctx
* @returns
*/
async fetch(request, env, ctx) {
const url = request.url;
let iSlash = url.indexOf('/',11);
let nUrl = url.substring(iSlash+1);
if(!nUrl.startsWith(SYDNEY_ORIGIN))
return await goUrl(request, nUrl);
const targetUrl = new URL(nUrl);
const newHeaders = new Headers();
request.headers.forEach((value, key) => {
// console.log(`old : ${key} : ${value}`);
if (KEEP_REQ_HEADERS.includes(key)) {
newHeaders.set(key, value);
}
});
newHeaders.set('host', targetUrl.host);
newHeaders.set('origin', targetUrl.origin);
newHeaders.set('referer', 'https://www.bing.com/search?q=Bing+AI');
const randIP = getRandomIP();
// console.log('randIP : ', randIP);
newHeaders.set('X-Forwarded-For', randIP);
const oldUA = request.headers.get('user-agent');
const isMobile = oldUA.includes('Mobile') || oldUA.includes('Android');
if (isMobile) {
newHeaders.set(
'user-agent',
'Mozilla/5.0 (iPhone; CPU iPhone OS 15_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.7 Mobile/15E148 Safari/605.1.15 BingSapphire/1.0.410427012'
);
} else {
newHeaders.set('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35');
}
// newHeaders.forEach((value, key) => console.log(`${key} : ${value}`));
const newReq = new Request(targetUrl, {
method: request.method,
headers: newHeaders,
body: request.body,
});
// console.log('request url : ', newReq.url);
const res = await fetch(newReq);
return res;
},
};

View File

@ -9,8 +9,11 @@ export default {
async function goUrl(request, url) {
let fp = {
method: request.method,
headers: request.headers
method: request.method
};
fp.headers = new Headers(request.headers);
for(var i = 2; i < arguments.length-1; i=i+2){
fp.headers[arguments[i]] = arguments[i+1];
}
return await fetch(url, fp);
}

View File

@ -56,19 +56,6 @@
hreflang="en"
href="/en/tags/"
/>
</url><url>
<loc>/en/</loc>
<lastmod>2023-06-26T08:17:34+08:00</lastmod>
<xhtml:link
rel="alternate"
hreflang="zh"
href="/zh/"
/>
<xhtml:link
rel="alternate"
hreflang="en"
href="/en/"
/>
</url><url>
<loc>/en/links/</loc>
<lastmod>2023-06-17T15:51:12+08:00</lastmod>

View File

@ -11,7 +11,7 @@
<sitemap>
<loc>zh/sitemap.xml</loc>
<lastmod>2023-07-05T09:05:41+08:00</lastmod>
<lastmod>2023-07-18T10:53:14+08:00</lastmod>
</sitemap>

View File

@ -108,9 +108,9 @@ c[cssFlag]: For example, &amp;quot;c12&amp;quot; will apply the third and fourth
<guid>/zh/tips/</guid>
<description>免魔法国内直接使用系列
newbing/chatgpt/必应写作/AI画图
使用重定向访问国外技术网址
google翻译
newbing/chatgpt/必应写作/AI画图
目录配置及使用外部文件管理器
超微浏览器可以将配置目录或子目录符号链接至任意外部公共目录。安装有定制termux的用户也可以使用移动设备自带或第三方文件管理器管理超微内部指定目录。具体配置可见Shell command mode。
准确显示PC网页:
@ -127,7 +127,9 @@ UA为非默认时点击PC按钮将恢复UA为默认同时触发不保存UA
在浏览器文件管理器中长按文件名,弹出菜单中选择分享,系统会优先弹出相应的文件编辑器。
配置文件列表中直接点击文件名即可编辑。
免魔法直接使用newbing/chatgpt/必应写作/AI画图 总要求:长按底部&amp;quot;PC&amp;quot;按钮选择user-agent为&amp;quot;edge&amp;quot;。用户需登录微软网站比如cn.bing.com帐号已经开通newbing。
方法1:
方法0:
使用重定向访问国外技术网址使用cloudflare workers 全局重定向代码。请帮助改良维护workers代码。
方法1(不再维护):
点击一键安装必应AI
或者分步安装:
安装界面html, bingChat &amp;amp; Write自带魔法直接界面
@ -137,10 +139,7 @@ Click to append to &amp;quot;hosts&amp;quot;, edit the last part as magic url do
点击界面入口
可配置魔法url, 上述hosts文件作相应修改。 详情
方法2: 可以采用超级书签/直接界面+脚本+hosts。
其中超级书签固定bingchat入口。
脚本重定向api至魔法师.
hosts防污染。
bingChat能够正常使用时保存为超级书签 (长按底部右箭头按钮),下次再次需要使用时恢复即可 (按设置按钮然后点击超级书签链接)。</description>
其中超级书签固定bingchat入口。</description>
</item>
<item>

View File

@ -3,7 +3,7 @@
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>/zh/_posts/</loc>
<lastmod>2023-06-17T07:56:09+08:00</lastmod>
<lastmod>2023-07-18T10:53:14+08:00</lastmod>
<xhtml:link
rel="alternate"
hreflang="en"
@ -27,19 +27,6 @@
hreflang="zh"
href="/zh/tags/"
/>
</url><url>
<loc>/zh/</loc>
<lastmod>2023-07-05T09:05:41+08:00</lastmod>
<xhtml:link
rel="alternate"
hreflang="en"
href="/en/"
/>
<xhtml:link
rel="alternate"
hreflang="zh"
href="/zh/"
/>
</url><url>
<loc>/zh/tags/%E5%9B%BD%E5%A4%96%E7%BD%91%E5%9D%80/</loc>
<lastmod>2023-06-17T07:56:09+08:00</lastmod>
@ -74,7 +61,7 @@
/>
</url><url>
<loc>/zh/tips/</loc>
<lastmod>2023-06-12T09:57:14+08:00</lastmod>
<lastmod>2023-07-18T10:53:14+08:00</lastmod>
<xhtml:link
rel="alternate"
hreflang="en"

View File

@ -47,9 +47,9 @@
</ul>
<p><strong>免魔法国内直接使用系列</strong><br>
<a href="#newbing">newbing/chatgpt/必应写作/AI画图</a><br>
<a href="../redirect/index.html">使用重定向访问国外技术网址</a><br>
<a href="../rjs/index.html">google翻译</a></p>
<a href="../rjs/index.html">google翻译</a><br>
<a href="#newbing">newbing/chatgpt/必应写作/AI画图</a></p>
<p><strong>目录配置及使用外部文件管理器</strong><br>
超微浏览器可以将配置目录或子目录符号链接至任意外部公共目录。安装有定制termux的用户也可以使用移动设备自带或第三方文件管理器管理超微内部指定目录。具体配置可见<a href="../../en/acmd/index.html">Shell command mode</a></p>
<p><strong>准确显示PC网页</strong>:<br>
@ -69,7 +69,11 @@ UA为非默认时点击PC按钮将恢复UA为默认同时触发不保存UA
<p>总要求:长按底部&quot;PC&quot;按钮选择user-agent为&quot;edge&quot;。用户需登录微软网站比如cn.bing.com帐号已经开通newbing。</p>
<ul>
<li>
<p>方法1:</p>
<p>方法0:<br>
<a href="../redirect/index.html">使用重定向访问国外技术网址</a>,使用<a href="../../en/searchurl/cloudflare/pbing.js">cloudflare workers 全局重定向代码</a>。请帮助改良维护workers代码。</p>
</li>
<li>
<p>方法1(不再维护):</p>
<ul>
<li>
<p>点击一键安装<a href="i:b1%0AInstall bing chat UI%0A%0Ai:0hsitecache/www.bing.com/ai.html:../../en/searchurl/bingAI/bing.html%0AInstall bing compose UI%0A%0Ai:0hsitecache/www.bing.com/write.html:../../en/searchurl/bingAI/write.html%0AInstall bing Draw UI%0A%0Ai:0hsitecache/www.bing.com/draw.html:../../en/searchurl/bingAI/draw.html%0AConfig hosts%0A空格后为魔法域名请按需修改%0Ai:0ghosts::www.bing.com;Access-Control-Allow-Origin;https://www.bing.com mybing.xn--xyza.top%0a%0Ai:52:https://www.bing.com/ai.html%0Ai:52:https://www.bing.com/write.html%0Ai:52:https://www.bing.com/draw.html">必应AI</a></p>
@ -98,8 +102,8 @@ UA为非默认时点击PC按钮将恢复UA为默认同时触发不保存UA
</ul>
</div>
<p>Last Modified: 12 June 2023<br>
adjust mirror order in README<br>
<p>Last Modified: 18 July 2023<br>
revert back redirect.js<br>
<pre></pre>
</p>
<script>