@@ -25,7 +25,7 @@ async function fetchAuthData(): Promise<Record<string, string>> {
2525 authData . ig = translatePage . match ( / I G : " ( .* ?) " / ) ?. [ 1 ] ?? '' ;
2626 authData . iid = translatePage . match ( / d a t a - i i d = " ( .* ?) " / ) ?. [ 1 ] ?? '' ;
2727 const abusePreventionHelper = JSON . parse (
28- translatePage . match ( / p a r a m s _ A b u s e P r e v e n t i o n H e l p e r = ( .* ?) ; / ) ?. [ 1 ]
28+ translatePage . match ( / p a r a m s _ A b u s e P r e v e n t i o n H e l p e r = ( .* ?) ; / ) ?. [ 1 ]
2929 ??
3030 '{}' ) ;
3131 authData . token = abusePreventionHelper [ 1 ] ;
@@ -39,12 +39,12 @@ async function fetchAuthData(): Promise<Record<string, string>> {
3939 * Obtain authentication data for the Bing Translate API from storage if it has
4040 * previously been stored, otherwise fetch authentication data and store it.
4141 */
42- async function getAuthData ( refresh = false ) : Promise < Record < string , string > > {
42+ async function getAuthData ( refresh = false ) : Promise < Record < string , string > > {
4343 const authDataStorageKey = 'bingTranslateAuthData' ;
4444 let authData = await getStoredData ( authDataStorageKey ) as
4545 Record < string , string > | undefined ;
4646 if ( ! authData || refresh ) {
47- authData = await fetchAuthData ( ) ;
47+ authData = await fetchAuthData ( ) ;
4848 await storeData ( authDataStorageKey , authData ) ;
4949 }
5050 return authData ;
@@ -70,20 +70,20 @@ async function requestTranslation(
7070 } ;
7171
7272 const response = await fetch (
73- `https://www.bing.com/ttranslatev3?isVertical=1&IG=${ authData . ig } ` +
73+ `https://www.bing.com/ttranslatev3?isVertical=1&IG=${ authData . ig } ` +
7474 `&IID=${ authData . iid } ` ,
75- {
76- method : 'POST' ,
77- headers : {
78- 'Content-Type' : 'application/x-www-form-urlencoded' ,
79- // The User-agent needs to be set for testing purposes in node, as
80- // Bing Translate appears to have introduced UA checks in Jan 2024.
81- // PS: These checks appear to have been removed again in Feb 2024.
82- // Anyway, it's safest to keep setting the UA for testing.
83- 'User-agent' : navigator . userAgent ,
84- } ,
85- body : new URLSearchParams ( payload ) ,
75+ {
76+ method : 'POST' ,
77+ headers : {
78+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
79+ // The User-agent needs to be set for testing purposes in node, as
80+ // Bing Translate appears to have introduced UA checks in Jan 2024.
81+ // PS: These checks appear to have been removed again in Feb 2024.
82+ // Anyway, it's safest to keep setting the UA for testing.
83+ 'User-agent' : navigator . userAgent ,
8684 } ,
85+ body : new URLSearchParams ( payload ) ,
86+ } ,
8787 ) ;
8888
8989 const responseData = await response . json ( ) ;
0 commit comments