8 lines
7.1 KiB
JavaScript
Executable File
8 lines
7.1 KiB
JavaScript
Executable File
/*
|
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
|
if you want to view the source, please visit the github repository of this plugin
|
|
*/
|
|
|
|
var A=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var q=(a,c)=>{for(var t in c)A(a,t,{get:c[t],enumerable:!0})},H=(a,c,t,e)=>{if(c&&typeof c=="object"||typeof c=="function")for(let r of $(c))!J.call(a,r)&&r!==t&&A(a,r,{get:()=>c[r],enumerable:!(e=M(c,r))||e.enumerable});return a};var U=a=>H(A({},"__esModule",{value:!0}),a);var V={};q(V,{default:()=>E});module.exports=U(V);var I=require("obsidian");var N=async()=>{let a="immersiveTranslate",c=["fullLocalUserConfig","buildinConfig","localConfig"];Object.keys(window.localStorage).filter(n=>n.startsWith(a)||c.includes(n)).forEach(n=>{window.localStorage.removeItem(n)});let e="immersive-translate";await window.indexedDB.databases().then(n=>{var m;(m=n==null?void 0:n.filter(d=>{var h;return(h=d.name)==null?void 0:h.startsWith(e)}))==null||m.forEach(d=>{d.name&&window.indexedDB.deleteDatabase(d.name)})}).catch(()=>{});let r="mmersiveTranslate";Object.keys(window).filter(n=>n.indexOf(r)!==-1).forEach(n=>{typeof window[n]!="undefined"&&delete window[n]})},O=()=>{let a=new KeyboardEvent("keydown",{key:"a",keyCode:65,which:65,code:"KeyA",altKey:!0,bubbles:!0});document.dispatchEvent(a)},S=a=>Array.isArray(a)?`[${a.map(c=>`${JSON.stringify(c)}`)}]`:"[]";var l=require("obsidian");var T={pageRule:{selectors:[".markdown-reading-view *"],excludeSelectors:[".markdown-reading-view .cm-inline-code"]}},P={sdkType:"Lite",isShowDisclaimer:!0,partnerId:"obsidian-immersive-translate",mountPoint:{selector:"#immersiveTranslate-translation-button",action:"child"},disclaimerPoint:{selector:"#immersiveTranslate-disclaimer-wrapper",action:"child"}},D=class extends l.PluginSettingTab{constructor(t,e){super(t,e);this.plugin=e;this.component=new l.Component,this.compareKeys=["selectors","excludeSelectors","sdkType","isShowDisclaimer"];let r=Object.fromEntries(this.compareKeys.map(p=>[p,this.plugin.settings[p]]));this.tempSettings=r,this.relaunchRef=void 0}getCompareStr(t){let{selectors:e,excludeSelectors:r,isShowDisclaimer:p}=t;return JSON.stringify({selectors:e,excludeSelectors:r,isShowDisclaimer:p})}compareSetting(){this.getCompareStr(this.plugin.settings)!==this.getCompareStr(this.tempSettings)&&this.relaunchRef?this.relaunchRef.clear().setName("Relaunch").setDesc("settings is changed, it need to relaunch").addButton(t=>{t.onClick(async()=>{this.compareKeys.forEach(e=>{e in this.plugin.settings&&(this.plugin.settings[e]=this.tempSettings[e])}),await this.plugin.saveData(this.plugin.settings),window.location.reload()}),t.setButtonText("relaunch"),t.setClass("mod-cta")}):this.relaunchRef&&this.relaunchRef.clear().setName("").setDesc("")}display(){var g,i;let{containerEl:t}=this;this.component.load(),t.empty();let e=this.tempSettings,r=T.pageRule.selectors,p=S((g=this.plugin.settings)==null?void 0:g.selectors),n=(0,l.debounce)(async s=>{try{let o=JSON.parse(s);o.includes(r[0])||o.unshift(r[0]),e.selectors=o,this.compareSetting()}catch(o){}});new l.Setting(t).setName("Selectors").setDesc(`Array, default: ${S(r)}`).addTextArea(s=>s.setValue(p).onChange(n));let m=T.pageRule.excludeSelectors,d=S((i=this.plugin.settings)==null?void 0:i.excludeSelectors),h=(0,l.debounce)(async s=>{try{let o=JSON.parse(s);o.includes(m[0])||o.unshift(m[0]),e.excludeSelectors=o,this.compareSetting()}catch(o){}});new l.Setting(t).setName("ExcludeSelectors").setDesc(`Array, default: ${S(m)}`).addTextArea(s=>s.setValue(d).onChange(h)),new l.Setting(t).setName("SDK Type").setDesc("SDK Type").addDropdown(s=>{s.addOption("Lite","Lite"),s.setValue(this.plugin.settings.sdkType),s.onChange(o=>{e.sdkType=o,this.compareSetting()})}),new l.Setting(t).setName("Is Show Disclaimer").setDesc("Show Disclaimer").addToggle(s=>{s.setValue(this.plugin.settings.isShowDisclaimer),s.onChange(o=>{e.isShowDisclaimer=o,this.compareSetting()})}),this.relaunchRef=new l.Setting(t)}hide(){this.component.unload()}};var j="https://download.immersivetranslate.com/immersive-translate-sdk-latest.js",B="https://download.immersivetranslate.com/immersive-translate-sdk-lite-latest.js",E=class extends I.Plugin{async onload(){if(await this.loadSettings(),this.settingTab=new D(this.app,this),this.addSettingTab(this.settingTab),!window.immersiveTranslateConfig){let{disclaimerPoint:t,mountPoint:e,partnerId:r,isShowDisclaimer:p,sdkType:n,...m}=this.settings;window.immersiveTranslateConfig={partnerId:r,disclaimerPoint:t,mountPoint:e,pageRule:JSON.parse(JSON.stringify(m))};let d=n==="Lite",h=d?B:j,g=document.createElement("script");g.classList.add("imt-script"),g.async=!0,g.src=h,g.onload=()=>{setTimeout(()=>{var s;if(d){if(!document.querySelector("#immersiveTranslate-translation-button-wrapper")){let o=document.createElement("div");o.id="immersiveTranslate-translation-button";let u=document.createElement("div");u.id="immersiveTranslate-translation-button-wrapper",u.append(o);let x=document.createElement("div");x.id="immersiveTranslate-disclaimer-wrapper",x.style.display=p?"block":"none",u.append(x),document.body.append(u),this.$el=u;let w=0,y=0,b=!1,k=0,C=0,K=f=>{b=!0;let v=u.getBoundingClientRect();w=f.clientX-v.left,y=f.clientY-v.top,k=v.width,C=v.height,document.addEventListener("mousemove",L),document.addEventListener("mouseup",R)},L=f=>{b&&(u.style.left=`${f.clientX-w<0?0:f.clientX-w>window.innerWidth-k?window.innerWidth-k:f.clientX-w}px`,u.style.top=`${f.clientY-y<0?0:f.clientY-y>window.innerHeight-C?window.innerHeight-C:f.clientY-y}px`,u.style.right="unset",u.style.bottom="unset",u.style.position="fixed")},R=()=>{b=!1,document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",R)};u.addEventListener("mousedown",K),this.mouseDown=K,this.mouseMove=L,this.mouseUp=R}return}let i=(s=document.querySelector("#immersive-translate-popup"))==null?void 0:s.shadowRoot;if(i){let o=i.querySelector(".imt-fb-container>div");o&&(o.style.display="none")}},1e3)},document.body.append(g)}}async onunload(){var d,h,g;let t=document.querySelector("#immersive-translate-popup"),e=document.querySelector("html");((d=e==null?void 0:e.getAttribute)==null?void 0:d.call(e,"imt-state"))==="dual"&&O();let p=document.querySelector(".imt-script"),n=[...document.querySelectorAll('[data-id*="immersive-translate"]')],m=[];[t,p,n].filter(i=>!!i).forEach(i=>Array.isArray(i)?i.forEach(s=>s&&m.push(s)):i&&m.push(i)),m.forEach(i=>{var s;return(s=i==null?void 0:i.remove)==null?void 0:s.call(i)}),(h=document.querySelectorAll("[data-immersive-translate-walked]"))==null||h.forEach(i=>i.removeAttribute("data-immersive-translate-walked")),e==null||e.removeAttribute("imt-state"),e==null||e.removeAttribute("imt-trans-position"),this.$el&&(this.$el.removeEventListener("mousedown",this.mouseDown),document.removeEventListener("mousemove",this.mouseMove),document.removeEventListener("mouseup",this.mouseUp),this.$el.remove(),(g=window==null?void 0:window.destroyImmersiveTranslate)==null||g.call(window)),await N()}async loadSettings(){this.settings=Object.assign({},JSON.parse(JSON.stringify(T.pageRule)),JSON.parse(JSON.stringify(P)),await this.loadData())}};
|
|
|
|
/* nosourcemap */ |