File size: 5,617 Bytes
55dde61
 
88e2635
55dde61
 
 
88e2635
 
55dde61
 
 
 
 
88e2635
55dde61
 
 
 
 
 
 
 
 
b9765d4
aae1813
bb5a8f2
 
55dde61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88e2635
 
 
 
55dde61
88e2635
 
 
 
 
 
 
 
deeaaf5
66f1e0a
deeaaf5
66f1e0a
deeaaf5
66f1e0a
88e2635
66f1e0a
3f3e003
66f1e0a
c88d075
3f3e003
1c84b65
c88d075
3f3e003
 
596b7fa
01ffaf5
296fec1
f6e3f77
 
 
ed54484
6871913
 
1a42e08
 
d2c14f0
6871913
fee2d82
c88d075
 
82d05b1
 
 
 
 
88e2635
b7e80c8
 
 
a5e4f97
03786d2
a16601a
c6599c9
a16601a
b7e80c8
a5e4f97
b7e80c8
 
 
 
66f1e0a
 
 
 
c88d075
55dde61
 
 
 
 
 
88e2635
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const puppeteer = require('puppeteer');
const express = require('express');
const cors = require('cors'); // 引入 cors 中间件
const app = express();
const port = 7860;

app.use(cors()); // 使用 cors 中间件

function convertEscapedUrlToStandard(escapedUrl) {
  // 使用正则表达式替换所有的转义反斜杠
  const standardUrl = escapedUrl.replace(/\\\//g, '/');
  return standardUrl;
}

function extractStringAfterRp(url) {
  // 分割URL并找到 'rp/' 后面的部分
  const parts = url.split('rp/');
  if (parts.length > 1) {
    return parts[1]; // 返回 'rp/' 后面的字符串
  }
  return '未找到 "rp/" 后的字符串';
}

app.get('/*', async (req, res) => {
  const referer = req.headers.referer || "https://r.bing.com";
  const url = new URL(referer);
  const rehost = url.hostname;
  // 启动浏览器
  const browser = await puppeteer.launch({
    executablePath: '/usr/bin/google-chrome-stable', // 根据您的实际路径进行修改
    // 其他选项...
  });

  const page = await browser.newPage();
  
  // 导航到网页
  await page.goto('https://www.bing.com/search?q=Microsoft+Copilot&FORM=hpcodx&showconv=1&showconv=1');
  
  // 等待页面源码中出现 'CodexBundle' 字符串,最长等待时间为30秒
  await page.waitForFunction(() => {
    return document.documentElement.innerHTML.includes('CodexBundle');
  }, { timeout: 30000 }); // 设置超时时间为30秒
  
  // 执行页面脚本来查找特定的字符串
  const result = await page.evaluate(() => {
    const regex = /CodexBundle:cib-bundle.*?\.js/;
    const htmlContent = document.documentElement.innerHTML;
    const matchcib = htmlContent.match(regex);
    if (matchcib) {
      const cibname = matchcib[0];
      // 使用正则表达式提取所有的JS文件URL
      const allregex = /\/([a-zA-Z0-9_-]+\.br\.js)'/g;
      const matches = htmlContent.match(allregex);
    
      let scripts = '';
      if (matches) {
        matches.forEach(match => {
          const scriptUrl = match.replace(/'/g, "");
          scripts += `<script src="https://r.bing.com/rp${scriptUrl}"></script>\n`;
        });
      }
      return { scripts, cibname, htmlContent }; 
    } 
    return { scripts: '没有找到匹配的字符串', cibname, htmlContent }; 
  }); 

  console.log(result.cibname); // 在此处输出 htmlContent 

  // 判断访问路径
  if (req.path === '/html') {
    res.set('Content-Type', 'text/html');
    res.send(result.htmlContent); // 发送 htmlContent 的纯文本响应
  } else if (req.path === '/core') {
    // 先找到包含前后字符的字符串
    const coreContent = result.htmlContent.match(/\(function\(n,t\)\{onload=function\(\)\{_G\.BPT=new.*?\/\/\]\]/s);
    if (coreContent) {
      // 删除掉不需要的部分
      let extractedString = coreContent[0];
      extractedString = extractedString.replace('[CDATA[', '').replace('//]]', '').replace('https:\/\/r.bing.com', '');
      extractedString = extractedString.replace(/\\\/rp\\\//g, `https://${rehost}/rp/`); // 使用模板字符串
      extractedString = extractedString.replace(/https:\\\/\\\/r\.bing\.com/g, ''); // 删除 https:\/\/r.bing.com 字符串
      extractedString = extractedString.replace(/\\\/rs\\\/6r\\\/x2\\\/nj\\\//g, `https://r.bing.com/rs/6r/x2/nj/`);
      extractedString = extractedString.replace(/\\\/rs\\\/6r\\\/sQ\\\/jnc,nj\\\//g, `https://r.bing.com/rs/6r/sQ/jnc,nj/`);
      extractedString = extractedString.replace(/\\\/rs\\\/6r\\\/kQ\\\/jnc,nj\\\//g, `https://r.bing.com/rs/6r/kQ/jnc,nj/`);
    //  extractedString = extractedString.replace(/\}\);;/g, `},{ 'A:rms:answers:Web:SydneyWelcomeScreen':'https://${rehost}/rp/J1Qt_5kw_tmsXwaKeAFz2xPNi4s.br.js' });;`); // 使用模板字符串
    
      extractedString = extractedString.replace(/,\{\'A:.{1,2}\':.{1,2}\}/g, '');
    //  extractedString = extractedString.replace(/\{\'A:rms:answers:Web:FreeSydneyHelper/g, '//{\'A:rms:answers:Web:FreeSydneyHelper');
      extractedString = extractedString.replace(/\{\'A:rms:answers:Web:SydneyFSCHelper/g, '//{\'A:rms:answers:Web:SydneyFSCHelper');
      extractedString = extractedString.replace(/\'\},/g, '\'},\n');
       
      
      res.set('Content-Type', 'text/plain');
      res.send(extractedString); // 发送提取后的字符串
    
    } else {
      res.set('Content-Type', 'text/plain');
      res.send('没有找到Core匹配的字符串');
    }
  } else if (req.path === '/importmap') {
    // 提取以 <script type="importmap" nonce=""> 开始,以 </script> 结尾的字符串
    const importmapContent = result.htmlContent.match(/<script type="importmap" nonce="">.*?<\/script>/s);
    if (importmapContent) {
      let pextractedString = importmapContent[0];
      pextractedString = pextractedString.replace('<script type="importmap" nonce="">', '').replace('<\/script>', '');
      //pextractedString = pextractedString.replace(/https:\/\/r\.bing\.com/g, 'https://cfby.nbing.eu.org'); // 删除 https://r.bing.com
     // pextractedString = pextractedString.replace(/https:\/\/r\.bing\.com/g, ''); // 删除 https://r.bing.com
      
      res.set('Content-Type', 'text/plain');
      res.send(pextractedString); // 发送提取后的字符串
    } else {
      res.set('Content-Type', 'text/plain');
      res.send('没有找到map匹配的字符串');
    }
  } else {
    res.set('Content-Type', 'text/plain');
    res.send(result.scripts); // 发送 scripts 的纯文本响应
  }
  
  // 关闭浏览器
  await browser.close();
});

app.listen(port, () => {
  console.log(`Server running at http://localhost:${port}`);
});