tinker-translate 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/preload/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const
|
|
2
|
-
\f\v`}for(var o=
|
|
1
|
+
"use strict";const B=require("electron"),z=require("https");function x(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var E={exports:{}},y={exports:{}},A={exports:{}};(function(n,t){t=function(e){return e===void 0},n.exports=t})(A,A.exports);var G=A.exports;(function(n,t){var e=G;t=function(r,o,a){if(e(o))return r;switch(a??3){case 1:return function(s){return r.call(o,s)};case 3:return function(s,u,i){return r.call(o,s,u,i)};case 4:return function(s,u,i,p){return r.call(o,s,u,i,p)}}return function(){return r.apply(o,arguments)}},n.exports=t})(y,y.exports);var H=y.exports,T={exports:{}},S={exports:{}},b={exports:{}};(function(n,t){var e=Object.prototype.toString;t=function(r){return e.call(r)},n.exports=t})(b,b.exports);var R=b.exports;(function(n,t){var e=R;t=function(r){return e(r)==="[object Number]"},n.exports=t})(S,S.exports);var J=S.exports,C={exports:{}};(function(n,t){var e=R;t=function(r){var o=e(r);return o==="[object Function]"||o==="[object GeneratorFunction]"||o==="[object AsyncFunction]"},n.exports=t})(C,C.exports);var K=C.exports;(function(n,t){var e=J,r=K,o=Math.pow(2,53)-1;t=function(a){if(!a)return!1;var s=a.length;return e(s)&&s>=0&&s<=o&&!r(a)},n.exports=t})(T,T.exports);var X=T.exports,k={exports:{}},L={exports:{}};(function(n,t){var e=Object.prototype.hasOwnProperty;t=function(r,o){return e.call(r,o)},n.exports=t})(L,L.exports);var W=L.exports;(function(n,t){var e=W;Object.keys?t=Object.keys:t=function(r){var o=[];for(var a in r)e(r,a)&&o.push(a);return o},n.exports=t})(k,k.exports);var V=k.exports;(function(n,t){var e=H,r=X,o=G,a=V;t=s(1),t.create=s;function s(u){return function(i,p,c,v){p=e(p,v);var l,h,w;if(r(i))for(h=i.length,l=u>0?0:h-1,o(c)&&(c=i[l],l+=u);l<h&&l>=0;l+=u)c=p(c,i[l],l,i);else{var m=a(i);for(h=m.length,l=u>0?0:h-1,o(c)&&(c=i[m[l]],l+=u);l<h&&l>=0;l+=u)w=m[l],c=p(c,i[w],w,i)}return c}}n.exports=t})(E,E.exports);var Q=E.exports;const Y=x(Q);var O={exports:{}},M={exports:{}},P={exports:{}};(function(n,t){var e=R;Array.isArray?t=Array.isArray:t=function(r){return e(r)==="[object Array]"},n.exports=t})(P,P.exports);var Z=P.exports;(function(n,t){var e=W,r=Z;t=function(s,u){if(r(s))return s;if(u&&e(u,s))return[s];var i=[];return s.replace(o,function(p,c,v,l){i.push(v?l.replace(a,"$1"):c||p)}),i};var o=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,a=/\\(\\)?/g;n.exports=t})(M,M.exports);var tt=M.exports;(function(n,t){var e=G,r=tt;t=function(o,a){a=r(a,o);var s;for(s=a.shift();!e(s);){if(o=o[s],o==null)return;s=a.shift()}return o},n.exports=t})(O,O.exports);var rt=O.exports;const d=x(rt);var U={exports:{}},$={exports:{}};(function(n,t){var e=/^\s+/;t=function(r,o){if(o==null)return r.trimLeft?r.trimLeft():r.replace(e,"");for(var a=0,s=r.length,u=o.length,i=!0,p,c;i&&a<s;)for(i=!1,p=-1,c=r.charAt(a);++p<u;)if(c===o[p]){i=!0,a++;break}return a>=s?"":r.substr(a,s)},n.exports=t})($,$.exports);var et=$.exports,I={exports:{}};(function(n,t){t=function(e,r){if(r==null){if(e.trimRight)return e.trimRight();r=` \r
|
|
2
|
+
\f\v`}for(var o=e.length-1,a=r.length,s=!0,u,i;s&&o>=0;)for(s=!1,u=-1,i=e.charAt(o);++u<a;)if(i===r[u]){s=!0,o--;break}return o>=0?e.substring(0,o+1):""},n.exports=t})(I,I.exports);var nt=I.exports;(function(n,t){var e=et,r=nt;t=function(o,a){return a==null&&o.trim?o.trim():e(r(o,a),a)},n.exports=t})(U,U.exports);var ot=U.exports;const D=x(ot);function g(n,t){return new Promise((e,r)=>{const o=z.request(n,a=>{let s="";a.on("data",u=>{s+=u}),a.on("end",()=>{e({statusCode:a.statusCode,data:s})})});o.on("error",r),t&&o.write(t),o.end()})}async function at(n,t,e){const o={hostname:"translate.google.com",port:443,path:`/translate_a/single?dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&${new URLSearchParams({client:"gtx",sl:t,tl:e,hl:e,ie:"UTF-8",oe:"UTF-8",otf:"1",ssel:"0",tsel:"0",kc:"7",q:n}).toString()}`,method:"GET",headers:{"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36"}},{statusCode:a,data:s}=await g(o);if(a!==200)throw new Error(`HTTP Error: ${a}`);const u=JSON.parse(s),i=d(u,"0"),p=Y(i??[],(c,v)=>c+(d(v,"0")??""),"");return{text:D(p)}}const j="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0",st="translator.5026";let f=null;async function it(){if(f&&Date.now()<f.expiresAt)return f;const{statusCode:n,data:t}=await g({hostname:"www.bing.com",port:443,path:"/translator",method:"GET",headers:{"User-Agent":j}});if(n!==200)throw new Error(`Failed to get token: ${n}`);const e=t.match(/IG:"([^"]+)"/),r=t.match(/params_AbusePreventionHelper\s*=\s*\[(\d+),\s*"([^"]+)",\s*(\d+)/);if(!e||!r)throw new Error("Failed to parse Bing auth");const o=Number(r[3]);return f={ig:e[1],key:r[1],token:r[2],expiresAt:Date.now()+Math.max(o-6e4,6e4)},f}async function ut(n,t,e){const r=await it(),o=new URLSearchParams({fromLang:t==="auto"?"auto-detect":t,to:e,text:n,token:r.token,key:r.key}).toString(),{statusCode:a,data:s}=await g({hostname:"www.bing.com",port:443,path:`/ttranslatev3?isVertical=1&IG=${r.ig}&IID=${st}`,method:"POST",headers:{"User-Agent":j,"Content-Type":"application/x-www-form-urlencoded","Content-Length":Buffer.byteLength(o),Origin:"https://www.bing.com",Referer:"https://www.bing.com/translator"}},o);if(a!==200)throw f=null,new Error(`HTTP Error: ${a}`);const u=JSON.parse(s),i=d(u,"[0].translations[0].text");if(!i)throw f=null,new Error("Invalid response format");return{text:D(i)}}var _={exports:{}};(function(n,t){t=function(e,r,o){r==null&&(r=e,e=0);var a=Math.random();return o||e%1||r%1?Math.min(e+a*(r-e+parseFloat("1e-"+((a+"").length-1))),r):e+Math.floor(a*(r-e+1))},n.exports=t})(_,_.exports);var ct=_.exports;const pt=x(ct);var F={exports:{}},N={exports:{}};(function(n,t){t=function(e){return e==null?"":e.toString()},n.exports=t})(N,N.exports);var lt=N.exports;(function(n,t){var e=lt;t=function(r){return e(r).toLocaleUpperCase()},n.exports=t})(F,F.exports);var ft=F.exports;const q=x(ft);function ht(n){return n.split("i").length-1}function vt(n){const t=Date.now();if(n!==0){const e=n+1;return t-t%e+e}return t}function dt(){return pt(1e5,199998)*1e3}async function xt(n,t,e){const r=dt(),o={jsonrpc:"2.0",method:"LMT_handle_texts",id:r,params:{splitting:"newlines",lang:{source_lang_user_selected:t!=="auto"?q(t.slice(0,2)):"auto",target_lang:q(e.slice(0,2))},texts:[{text:n,requestAlternatives:3}],timestamp:vt(ht(n))}};let a=JSON.stringify(o);(r+5)%29===0||(r+3)%13===0?a=a.replace('"method":"','"method" : "'):a=a.replace('"method":"','"method": "');const s={hostname:"www2.deepl.com",port:443,path:"/jsonrpc",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(a)}},{statusCode:u,data:i}=await g(s,a);if(u!==200)throw new Error(`HTTP Error: ${u}`);const p=JSON.parse(i),c=d(p,"result.texts[0].text");if(c)return{text:D(c)};throw new Error(d(p,"error.message")??"Invalid response format")}const gt={translate:async(n,t,e,r="google")=>r==="bing"?await ut(n,t,e):r==="deepl"?await xt(n,t,e):await at(n,t,e)};B.contextBridge.exposeInMainWorld("translate",gt);
|