Go-Proxy-BingAI

Go-Proxy-BingAI 登录脚本

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