Go-Proxy-BingAI

Go-Proxy-BingAI 登录脚本

当前为 2024-02-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Go-Proxy-BingAI
  3. // @namespace https://github.com/Harry-zklcdc/go-proxy-bingai
  4. // @description Go-Proxy-BingAI 登录脚本
  5. // @author Harry-zklcdc
  6. // @match *://*.bing.com/*
  7. // @icon https://raw.githubusercontent.com/Harry-zklcdc/go-proxy-bingai/master/frontend/public/img/logo.svg
  8. // @homepage https://github.com/Harry-zklcdc/go-proxy-bingai
  9. // @version 1.0.0
  10. // @grant none
  11. // @license AGPLv3
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. window.addEventListener('message', async function (e) {
  18. const d = e.data;
  19. console.log(d);
  20. const IG = d.IG, T = d.T;
  21. if ((IG != "" && IG != null && IG != undefined) && (T != "" && T != null && T != undefined)) {
  22. const S = base58Decode(_GU.ST);
  23. let tmpA = [];
  24. for (let i = 0; i < _GU.SP.length; i++) {
  25. tmpA.push(S[_GU.SP[i]]);
  26. }
  27. const e = base58Decode(tmpA.join(''));
  28. const token = await aesDecrypt(T, IG);
  29. if (e == token) {
  30. console.log(window.parent);
  31. if (window.parent != undefined && window.parent != null) {
  32. window.parent.postMessage({'cookies': document.cookie}, '*')
  33. }
  34. }
  35. }
  36. })
  37. })();
  38.  
  39. function base58Encode(buffer) {
  40. const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
  41. const BASE = BigInt(58)
  42.  
  43. const encoder = new TextEncoder();
  44. const bytes = typeof buffer === 'string' ? new Uint8Array(encoder.encode(buffer)) : buffer
  45. if (bytes.length === 0) return ''
  46.  
  47. let i, j
  48. let digits = [BigInt(0)]
  49. for (i = 0; i < bytes.length; i++) {
  50. for (j = 0; j < digits.length; j++) digits[j] *= BigInt(256)
  51. digits[0] += BigInt(bytes[i])
  52.  
  53. let carry = BigInt(0)
  54. for (j = 0; j < digits.length; ++j) {
  55. digits[j] += carry
  56.  
  57. carry = digits[j] / BASE
  58. digits[j] %= BASE
  59. }
  60.  
  61. while (carry > 0) {
  62. digits.push(carry % BASE)
  63.  
  64. carry /= BASE
  65. }
  66. }
  67.  
  68. for (i = 0; bytes[i] === 0 && i < bytes.length - 1; i++) digits.push(BigInt(0))
  69.  
  70. return digits.reverse().map(d => ALPHABET[Number(d)]).join('')
  71. }
  72.  
  73. function base58Decode(s) {
  74. const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
  75. const ALPHABET_MAP = {}
  76. for (let i = 0; i < ALPHABET.length; i++) {
  77. ALPHABET_MAP[ALPHABET.charAt(i)] = BigInt(i)
  78. }
  79. const BASE = BigInt(58)
  80.  
  81. if (s.length === 0) return ''
  82.  
  83. let i, j
  84. let bytes = [BigInt(0)]
  85. for (i = 0; i < s.length; i++) {
  86. const c = s[i]
  87. if (!(c in ALPHABET_MAP)) throw new Error('Non-base58 character')
  88.  
  89. for (j = 0; j < bytes.length; j++) bytes[j] *= BASE
  90. bytes[0] += ALPHABET_MAP[c]
  91.  
  92. let carry = BigInt(0)
  93. for (j = 0; j < bytes.length; ++j) {
  94. bytes[j] += carry
  95.  
  96. carry = bytes[j] >> BigInt(8)
  97. bytes[j] &= BigInt(0xff)
  98. }
  99.  
  100. while (carry > 0) {
  101. bytes.push(carry & BigInt(0xff))
  102.  
  103. carry >>= BigInt(8)
  104. }
  105. }
  106.  
  107. for (i = 0; s[i] === '1' && i < s.length - 1; i++) bytes.push(BigInt(0))
  108.  
  109. return bytes.reverse().map(b => String.fromCharCode(Number(b))).join('')
  110. }
  111.  
  112. async function aesEncrypt(e, t) {
  113. const c = new TextEncoder();
  114. const mb = c.encode(e), kb = c.encode(t);
  115. const iv = window.crypto.getRandomValues(new Uint8Array(16));
  116.  
  117. const ck = await window.crypto.subtle.importKey(
  118. "raw",
  119. kb,
  120. { name: "AES-CBC", length: 256 },
  121. false,
  122. ["encrypt"]
  123. );
  124. const ed = await window.crypto.subtle.encrypt(
  125. { name: "AES-CBC", iv: iv },
  126. ck,
  127. mb
  128. )
  129.  
  130. const r = new Uint8Array(iv.byteLength + ed.byteLength);
  131. r.set(new Uint8Array(iv), 0);
  132. r.set(new Uint8Array(ed), iv.byteLength);
  133. return btoa(String.fromCharCode.apply(null, r));
  134. }
  135.  
  136. async function aesDecrypt(e, t) {
  137. const c = new TextEncoder();
  138. const kb = Uint8Array.from(c.encode(t));
  139. const cb = Uint8Array.from(atob(e), c => c.charCodeAt(0));
  140.  
  141. const iv = cb.slice(0, 16);
  142. const ct = cb.slice(16);
  143.  
  144. const key = await window.crypto.subtle.importKey(
  145. "raw",
  146. kb,
  147. { name: "AES-CBC", length: 256 },
  148. false,
  149. ["decrypt"]
  150. );
  151.  
  152. const dd = await window.crypto.subtle.decrypt(
  153. { name: "AES-CBC", iv: iv },
  154. key,
  155. ct
  156. );
  157.  
  158. const d = new TextDecoder();
  159. return d.decode(dd);
  160. }
  161.  
  162. const _GU = {
  163. TP: 'L2yDt6NHpVg74zXbiBVawp2LXBqjJe69YXaqikLo6FSPRXTBSUtR6ThZ41EAwzei6dMFnTLBw6ngU32nwwgiSsRc1yemqufobYSrv96ii7qArPE9nssRwizpWUHDtJr8vSzmbjS',
  164. TC: 'EQWVgx176AeS3PtMCwMpt8iG89A6uTZfqKzBsQKhA9PjXcoJBEEX9pgNmgx1stfRCh6Q4gdGgNX23KfMJ2ZBLtUbnCQXWMPAHVCNkNCxehuyHwD2uk1PWHzkFCqqYVowZQxxjxfEUFwXwucCz47doC51LdpGDQrh28xq1MZy1qXb1XeNuvJ2U1duHGi1Bqg3GJ8oXqZpqKvrWYm7dDPbjgkEeywZJw59CwMAQFmdy7GBFDP9KkqChGM2sKTW2p3RVdauSZe6tvU2evCDC56idpu4JRwaFstSjnuxaoTcxXJDcBv1AXPSZSH3zEUSbeJbTB59mnDx1jd4nsEcM4smZPnMt6x4dG7atwfFuHvjwCTCeEg5jsMJSL5bP1K2tE1pVFC7XBTo4KNpJy5dUkHrHLk8GRdixUPSQczHh9Ex7sHKN7LZK72ZN8MDg2j1iooeqAGSNEQL3QYJj6gsoPTXzVaCo1yehRjD3v9JP98U7Dye77YhhdiDSYDAMrCdpfpmFugMnpbc8FuWVvDuJsSrpGdYZe6Sdg8vwTezayJ9SBdBXdgSuksSGfgU',
  165. ST: '5n9nA7VpTUm7sxT4EN6jpH9WitUG3hCGM6su8X3riDwbXrPcRP6VR4mh4WumPerkSPpakrQYdRdXHwfBrpTZa',
  166. SP: [ 59, 5, 51, 2, 24, 23, 5, 35, 14, 40, 26, 33, 58, 26, 9, 15, 61, 31, 53, 55, 47, 26, 40, 12, 22, 13, 10, 44, 17, 59, 31, 45, 34, 1, 26, 9, 43, 44 ]
  167. }