@@ -13,25 +13,18 @@ function formatPostString(postData) {
1313 return body ;
1414}
1515
16- async function sendRequest ( postData , urlMethod , dlSession , printResult ) {
17- const urlFull = `${ baseURL } /jsonrpc?client=chrome-extension,1.28.0&method= ${ encodeURIComponent ( urlMethod ) } ` ;
16+ async function sendRequest ( postData , urlMethod , dlSession , tagHandling , printResult ) {
17+ const urlFull = `${ baseURL } /jsonrpc?` ;
1818
1919 const headers = {
2020 'Content-Type' : 'application/json' ,
21- "User-Agent" : "DeepLBrowserExtension/1.28.0 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" ,
22- "Accept" : "*/*" ,
23- "Accept-Language" : "en-US,en;q=0.9,zh-CN;q=0.8,zh-TW;q=0.7,zh-HK;q=0.6,zh;q=0.5" ,
24- "Authorization" : "None" ,
25- "Cache-Control" : "no-cache" ,
26- "DNT" : "1" ,
27- "Origin" : "chrome-extension://cofdbpoegempjloogbagkncekinflcnj" ,
28- "Pragma" : "no-cache" ,
29- "Priority" : "u=1, i" ,
30- "Referer" : "https://www.deepl.com/" ,
31- "Sec-Fetch-Dest" : "empty" ,
32- "Sec-Fetch-Mode" : "cors" ,
33- "Sec-Fetch-Site" : "none" ,
34- "Sec-GPC" : "1" ,
21+ 'User-Agent' : 'DeepLBrowserExtension/1.28.0 Mozilla/5.0' ,
22+ Accept : '*/*' ,
23+ 'Accept-Language' : 'en-US,en;q=0.9' ,
24+ Origin : 'https://www.deepl.com' ,
25+ Referer : 'https://www.deepl.com/' ,
26+ Pragma : 'no-cache' ,
27+ 'Cache-Control' : 'no-cache' ,
3528 ...( dlSession && { 'Cookie' : `dl_session=${ dlSession } ` } )
3629 } ;
3730 postData = formatPostString ( postData ) ;
@@ -157,7 +150,7 @@ async function translate(text, sourceLang, targetLang, dlSession, tagHandling, p
157150 let alternatives = [ ] , translatedText = '' ;
158151
159152 // 获取备选翻译
160- if ( response . result . translations . length > 0 ) {
153+ if ( response . result . translations != '' && response . result . translations . length > 0 ) {
161154 response . result . translations [ 0 ] . beams . forEach ( beam => {
162155 alternatives . push ( beam . sentences [ 0 ] . text ) ;
163156 } ) ;
@@ -171,14 +164,15 @@ async function translate(text, sourceLang, targetLang, dlSession, tagHandling, p
171164 }
172165
173166 const ret = {
174- code : postData . status ,
167+ code : postData . status || 200 ,
175168 id : postData . id ,
176169 method : "Free" ,
177170 data : translatedText ,
178- alternatives : alternatives ,
179171 source_lang : sourceLang . toUpperCase ( ) ,
180- target_lang : targetLang . toUpperCase ( )
172+ target_lang : targetLang . toUpperCase ( ) ,
173+ alternatives : alternatives
181174 }
175+ if ( printResult ) console . log ( response ) ;
182176 if ( printResult ) console . log ( ret ) ;
183177 return ret ;
184178 } catch ( err ) {
0 commit comments