diff --git a/src/index.js b/src/index.js index d8778fa..cdd4476 100644 --- a/src/index.js +++ b/src/index.js @@ -7,8 +7,8 @@ const lang = require('./lang') const TRANSLATE_API_ROOT = 'https://{s}bing.com' const TRANSLATE_WEBSITE = TRANSLATE_API_ROOT + '/translator' -const TRANSLATE_API = TRANSLATE_API_ROOT + '/ttranslatev3' -const TRANSLATE_SPELL_CHECK_API = TRANSLATE_API_ROOT + '/tspellcheckv3' +const TRANSLATE_API = TRANSLATE_API_ROOT + '/ttranslatev3?isVertical=1' +const TRANSLATE_SPELL_CHECK_API = TRANSLATE_API_ROOT + '/tspellcheckv3?isVertical=1' const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.5195.127 Safari/537.36' @@ -48,9 +48,6 @@ async function fetchGlobalConfig(userAgent, proxyAgents) { let token let key let tokenExpiryInterval - let isVertical - let frontDoorBotClassification - let isSignedInOrCorporateUser let cookie try { const { body, headers, request: { redirects } } = await got(replaceSubdomain(TRANSLATE_WEBSITE, subdomain), { @@ -69,8 +66,8 @@ async function fetchGlobalConfig(userAgent, proxyAgents) { IID = body.match(/data-iid="([^"]+)"/)[1] // required - ;[key, token, tokenExpiryInterval, isVertical, frontDoorBotClassification, isSignedInOrCorporateUser] = JSON.parse( - body.match(/params_RichTranslateHelper\s?=\s?([^\]]+\])/)[1] + ;[key, token, tokenExpiryInterval] = JSON.parse( + body.match(/params_AbusePreventionHelper\s?=\s?([^\]]+\])/)[1] ) } catch (e) { console.error('failed to fetch global config', e) @@ -84,9 +81,6 @@ async function fetchGlobalConfig(userAgent, proxyAgents) { token, tokenTs: key, tokenExpiryInterval, - isVertical, - frontDoorBotClassification, - isSignedInOrCorporateUser, cookie, // PENDING: reset count if count value is large? count: 0 @@ -94,11 +88,10 @@ async function fetchGlobalConfig(userAgent, proxyAgents) { } function makeRequestURL(isSpellCheck) { - const { IG, IID, subdomain, isVertical } = globalConfig + const { IG, IID, subdomain } = globalConfig return replaceSubdomain(isSpellCheck ? TRANSLATE_SPELL_CHECK_API : TRANSLATE_API, subdomain) - + '?isVertical=' + +isVertical + (IG && IG.length ? '&IG=' + IG : '') - + (IID && IID.length ? '&IID=' + IID + '.' + (globalConfig.count++) : '') + + (IID && IID.length ? '&IID=' + IID + '.' + (++globalConfig.count) : '') } function makeRequestBody(isSpellCheck, text, fromLang, toLang) { diff --git a/test/index.js b/test/index.js index d578d83..ec04bb8 100644 --- a/test/index.js +++ b/test/index.js @@ -46,7 +46,7 @@ translate('gradent', null, 'en', true) .catch(onErr) // correct short text to `this text is very long` -translate('this text is very lang', null, 'en', true) +translate('this text is vry lang', null, 'en', true) .then(printCorrectRes) .catch(onErr) @@ -61,12 +61,6 @@ translate('this text is very long this text is very long this text is very long .catch(onErr) // max text len -> return `undefined` for exceeding max length -translate((() => { - let text = '' - while (text.length < 1001) { - text += ~~(Math.random() * 10) + '' - } - return text -})(), null, 'en') +translate(new Array(1001).fill('0').join(''), null, 'en') .then(printRes) .catch(e => onErr(e, true))