${i}`,n*1e3);e&&(o.noticeEl.oncontextmenu=()=>{e()})}var E=(s,t=!0)=>{let n=s.createEl("div");n.style.float="right",t?(n.style.padding="15px",n.style.paddingLeft="15px",n.style.paddingRight="15px",n.style.marginLeft="15px"):(n.style.padding="10px",n.style.paddingLeft="15px",n.style.paddingRight="15px");let e=n.createDiv("coffee");e.addClass("ex-twitter-span"),e.style.paddingLeft="10px";let i=e.createDiv();i.innerText="Learn more about my work at:",e.appendChild(i);let o=e.createEl("a",{href:"https://tfthacker.com"});return o.innerText="https://tfthacker.com",n};var N=class extends x.Modal{constructor(t,n,e=!1,i=!1){super(t.app),this.plugin=t,this.betaPlugins=n,this.address="",this.openSettingsTabAfterwards=e,this.useFrozenVersion=i,this.enableAfterInstall=t.settings.enableAfterInstall,this.version=""}async submitForm(){if(this.address==="")return;let t=this.address.replace("https://github.com/","");if(t.endsWith(".git")&&(t=t.slice(0,-4)),Pt(this.plugin,t)){d(this.plugin,"This plugin is already in the list for beta testing",10);return}await this.betaPlugins.addPlugin(t,!1,!1,!1,this.version,!1,this.enableAfterInstall)&&this.close()}onOpen(){this.contentEl.createEl("h4",{text:"Github repository for beta plugin:"}),this.contentEl.createEl("form",{},t=>{t.addClass("brat-modal"),new x.Setting(t).addText(i=>{i.setPlaceholder("Repository (example: https://github.com/GitubUserName/repository-name)"),i.setValue(this.address),i.onChange(o=>{this.address=o.trim()}),i.inputEl.addEventListener("keydown",o=>{o.key==="Enter"&&this.address!==" "&&(this.useFrozenVersion&&this.version!==""||!this.useFrozenVersion)&&(o.preventDefault(),this.submitForm())}),i.inputEl.style.width="100%"}),this.useFrozenVersion&&new x.Setting(t).addText(i=>{i.setPlaceholder("Specify the release version tag (example: 1.0.0)"),i.onChange(o=>{this.version=o.trim()}),i.inputEl.style.width="100%"}),t.createDiv("modal-button-container",i=>{i.createEl("label",{cls:"mod-checkbox"},o=>{let a=o.createEl("input",{attr:{tabindex:-1},type:"checkbox"});a.checked=this.enableAfterInstall,a.addEventListener("click",()=>{this.enableAfterInstall=a.checked}),o.appendText("Enable after installing the plugin")}),i.createEl("button",{attr:{type:"button"},text:"Never mind"}).addEventListener("click",()=>{this.close()}),i.createEl("button",{attr:{type:"submit"},cls:"mod-cta",text:"Add Plugin"})});let n=t.createDiv();n.style.borderTop="1px solid #ccc",n.style.marginTop="30px";let e=n.createSpan();e.innerHTML="BRAT by <a href='https://bit.ly/o42-twitter'>TFTHacker</a>",e.style.fontStyle="italic",n.appendChild(e),E(n,!1),window.setTimeout(()=>{let i=t.querySelectorAll(".brat-modal .setting-item-info");for(let o of Array.from(i))o.remove()},50),t.addEventListener("submit",i=>{i.preventDefault(),this.address!==""&&(this.useFrozenVersion&&this.version!==""||!this.useFrozenVersion)&&this.submitForm()})})}onClose(){this.openSettingsTabAfterwards&&(this.plugin.app.setting.open(),this.plugin.app.setting.openTabById(this.plugin.APP_ID))}};var Ft=require("obsidian");async function Z(){try{let s=await(0,Ft.requestUrl)(`https://obsidian.md/?${Math.random()}`);return s.status>=200&&s.status<300}catch(s){return!1}}var R=class{constructor(t){this.plugin=t}displayAddNewPluginModal(t=!1,n=!1){new N(this.plugin,this,t,n).open()}async validateRepository(t,n=!1,e=!1){let o=await ft(t,!n,this.plugin.settings.debuggingMode,this.plugin.settings.personalAccessToken);return o?"id"in o?"version"in o?o:(e&&d(this.plugin,`${t}
ThepluginhasbeenregisteredwithBRAT.`;l||(f+=" You may still need to enable it the Community Plugin List."),await this.plugin.log(f,!0),d(this.plugin,f,g)}}else{let c=`${this.plugin.app.vault.configDir}/plugins/${r.id}/`,m="";try{m=await this.plugin.app.vault.adapter.read(`${c}manifest.json`)}catch(w){if(w.errno===-4058||w.errno===-2)return await this.addPlugin(t,!1,p,!1,o),!0;console.log("BRAT - Local Manifest Load",r.id,JSON.stringify(w,null,2))}if(o!==""||this.plugin.settings.pluginSubListFrozenVersion.map(w=>w.repo).includes(t))return d(this.plugin,`Theversionof${t}isfrozen,notupdating.`,3),!1;let f=await JSON.parse(m);if(f.version!==r.version){let w=await T();if(w===null)return!1;if(e){let h=`Thereisanupdateavailablefor${r.id}fromversion${f.version}to${r.version}.`;await this.plugin.log(`${h}[ReleaseInfo](https://github.com/${t}/releases/tag/${r.version})`,!0),d(this.plugin,h,30,()=>{r&&window.open(`https://github.com/${t}/releases/tag/${r.version}`)})}else{await this.writeReleaseFilesToPluginFolder(r.id,w),await this.plugin.app.plugins.loadManifests(),await this.reloadPlugin(r.id);let h=`${r.id}
Pluginhasbeenupdatedfromversion${f.version}to${r.version}.`;await this.plugin.log(`${h}[ReleaseInfo](https://github.com/${t}/releases/tag/${r.version})`,!0),d(this.plugin,h,30,()=>{r&&window.open(`https://github.com/${t}/releases/tag/${r.version}`)})}}else i&&d(this.plugin,`No update available for ${t}`,3)}return!0}async reloadPlugin(t){let{plugins:n}=this.plugin.app;try{await n.disablePlugin(t),await n.enablePlugin(t)}catch(e){this.plugin.settings.debuggingMode&&console.log("reload plugin",e)}}async updatePlugin(t,n=!1,e=!1,i=!1){let o=await this.addPlugin(t,!0,n,e,"",i);return!o&&!n&&d(this.plugin,`${t}
Updateofpluginfailed.`),o}async checkForPluginUpdatesAndInstallUpdates(t=!1,n=!1){if(!await Z()){console.log("BRAT: No internet detected.");return}let e,i="Checking for plugin updates STARTED";await this.plugin.log(i,!0),t&&this.plugin.settings.notificationsEnabled&&(e=new F.Notice(`BRAT
${i}`,3e4));let o=new Set(this.plugin.settings.pluginSubListFrozenVersion.map(l=>l.repo));for(let l of this.plugin.settings.pluginList)o.has(l)||await this.updatePlugin(l,n);let a="Checking for plugin updates COMPLETED";await this.plugin.log(a,!0),t&&(e&&e.hide(),d(this.plugin,a,10))}deletePlugin(t){let n=`Removed${t}fromBRATpluginlist`;this.plugin.log(n,!0),this.plugin.settings.pluginList=this.plugin.settings.pluginList.filter(e=>e!==t),this.plugin.settings.pluginSubListFrozenVersion=this.plugin.settings.pluginSubListFrozenVersion.filter(e=>e.repo!==t),this.plugin.saveSettings()}getEnabledDisabledPlugins(t){let n=this.plugin.app.plugins,e=Object.values(n.manifests),i=Object.values(n.plugins).map(o=>o.manifest);return t?e.filter(o=>i.find(a=>o.id===a.id)):e.filter(o=>!i.find(a=>o.id===a.id))}};var k=require("obsidian");var O=async(s,t,n)=>{let e=await I(t,!0,s.settings.debuggingMode);if(e||(e=await I(t,!1,s.settings.debuggingMode)),!e)return d(s,"There is no theme.css or theme-beta.css file in the root path of this repository, so there is no theme to install."),!1;let i=await wt(t,s.settings.debuggingMode);if(!i)return d(s,"There is no manifest.json file in the root path of this repository, so theme cannot be installed."),!1;let o=await JSON.parse(i),a=(0,k.normalizePath)(oe(s)+o.name),{adapter:l}=s.app.vault;await l.exists(a)||await l.mkdir(a),await l.write((0,k.normalizePath)(`${a}/theme.css`),e),await l.write((0,k.normalizePath)(`${a}/manifest.json`),i),At(s,t,M(e));let g="";return n?(vt(s,t,e),g=`${o.name}themeinstalledfrom${t}.`,setTimeout(()=>{s.app.customCss.setTheme(o.name)},500)):g=`${o.name}themeupdatedfrom${t}.`,s.log(`${g}[ThemeInfo](https://github.com/${t})`,!1),d(s,g,20,()=>{window.open(`https://github.com/${t}`)}),!0},B=async(s,t)=>{if(!await Z()){console.log("BRAT: No internet detected.");return}let n,e="Checking for beta theme updates STARTED";await s.log(e,!0),t&&s.settings.notificationsEnabled&&(n=new k.Notice(`BRAT
${e}`,3e4));for(let o of s.settings.themesList){let a=await $(o.repo,!0,s.settings.debuggingMode);a==="0"&&(a=await $(o.repo,!1,s.settings.debuggingMode)),console.log("BRAT: lastUpdateOnline",a),a!==o.lastUpdate&&await O(s,o.repo,!1)}let i="Checking for beta theme updates COMPLETED";(async()=>await s.log(i,!0))(),t&&(s.settings.notificationsEnabled&&n&&n.hide(),d(s,i))},X=(s,t)=>{s.settings.themesList=s.settings.themesList.filter(e=>e.repo!==t),s.saveSettings();let n=`Removed${t}fromBRATthemeslistandwillnolongerbeupdated.However,thethemefilesstillexistinthevault.Toremovethem,gointoSettings>Appearanceandremovethetheme.`;s.log(n,!0),d(s,n)},oe=s=>`${(0,k.normalizePath)(`${s.app.vault.configDir}/themes`)}/`;var tt=require("obsidian");var S=class extends tt.Modal{constructor(t,n=!1){super(t.app),this.plugin=t,this.address="",this.openSettingsTabAfterwards=n}async submitForm(){if(this.address==="")return;let t=this.address.replace("https://github.com/","");if(Ct(this.plugin,t)){d(this.plugin,"This theme is already in the list for beta testing",10);return}await O(this.plugin,t,!0)&&this.close()}onOpen(){this.contentEl.createEl("h4",{text:"Github repository for beta theme:"}),this.contentEl.createEl("form",{},t=>{t.addClass("brat-modal"),new tt.Setting(t).addText(i=>{i.setPlaceholder("Repository (example: https://github.com/GitubUserName/repository-name"),i.setValue(this.address),i.onChange(o=>{this.address=o.trim()}),i.inputEl.addEventListener("keydown",o=>{o.key==="Enter"&&this.address!==" "&&(o.preventDefault(),this.submitForm())}),i.inputEl.style.width="100%",window.setTimeout(()=>{let o=document.querySelector(".setting-item-info");o&&o.remove(),i.inputEl.focus()},10)}),t.createDiv("modal-button-container",i=>{i.createEl("button",{attr:{type:"button"},text:"Never mind"}).addEventListener("click",()=>{this.close()}),i.createEl("button",{attr:{type:"submit"},cls:"mod-cta",text:"Add Theme"})});let n=t.createDiv();n.style.borderTop="1px solid #ccc",n.style.marginTop="30px";let e=n.createSpan();e.innerHTML="BRAT by <a href='https://bit.ly/o42-twitter'>TFTHacker</a>",e.style.fontStyle="italic",n.appendChild(e),E(n,!1),window.setTimeout(()=>{let i=t.querySelectorAll(".brat-modal .setting-item-info");for(let o of Array.from(i))o.remove()},50),t.addEventListener("submit",i=>{i.preventDefault(),this.address!==""&&this.submitForm()})})}onClose(){this.openSettingsTabAfterwards&&(this.plugin.app.setting.openTab(),this.plugin.app.setting.openTabById(this.plugin.APP_ID))}};var St=require("obsidian"),C=class extends St.FuzzySuggestModal{constructor(n){super(n.app);this.data=[];this.scope.register(["Shift"],"Enter",e=>{this.enterTrigger(e)}),this.scope.register(["Ctrl"],"Enter",e=>{this.enterTrigger(e)})}setSuggesterData(n){this.data=n}display(n){this.callbackFunction=n,this.open()}getItems(){return this.data}getItemText(n){return n.display}onChooseItem(){}renderSuggestion(n,e){e.createEl("div",{text:n.item.display})}enterTrigger(n){var o;let e=(o=document.querySelector(".suggestion-item.is-selected div"))==null?void 0:o.textContent,i=this.data.find(a=>a.display===e);i&&(this.invokeCallback(i,n),this.close())}onChooseSuggestion(n,e){this.invokeCallback(n.item,e)}invokeCallback(n,e){typeof this.callbackFunction=="function"&&this.callbackFunction(n,e)}};var U=class{constructor(t){this.bratCommands=[{id:"AddBetaPlugin",icon:"BratIcon",name:"Plugins: Add a beta plugin for testing",showInRibbon:!0,callback:()=>{this.plugin.betaPlugins.displayAddNewPluginModal(!1,!1)}},{id:"AddBetaPluginWithFrozenVersion",icon:"BratIcon",name:"Plugins: Add a beta plugin with frozen version based on a release tag",showInRibbon:!0,callback:()=>{this.plugin.betaPlugins.displayAddNewPluginModal(!1,!0)}},{id:"checkForUpdatesAndUpdate",icon:"BratIcon",name:"Plugins: Check for updates to all beta plugins and UPDATE",showInRibbon:!0,callback:async()=>{await this.plugin.betaPlugins.checkForPluginUpdatesAndInstallUpdates(!0,!1)}},{id:"checkForUpdatesAndDontUpdate",icon:"BratIcon",name:"Plugins: Only check for updates to beta plugins, but do
${o}`,3),this.plugin.betaPlugins.updatePlugin(i.info,!1,!0)})}},{id:"reinstallOnePlugin",icon:"BratIcon",name:"Plugins: Choose a single plugin to reinstall",showInRibbon:!0,callback:()=>{let t=new Set(this.plugin.settings.pluginSubListFrozenVersion.map(i=>i.repo)),n=Object.values(this.plugin.settings.pluginList).filter(i=>!t.has(i)).map(i=>({display:i,info:i})),e=new C(this.plugin);e.setSuggesterData(n),e.display(i=>{let o=`Reinstalling${i.info}`;d(this.plugin,`
${o}`,3),this.plugin.log(o,!0),this.plugin.betaPlugins.updatePlugin(i.info,!1,!1,!0)})}},{id:"restartPlugin",icon:"BratIcon",name:"Plugins: Restart a plugin that is already installed",showInRibbon:!0,callback:()=>{let t=Object.values(this.plugin.app.plugins.manifests).map(e=>({display:e.id,info:e.id})),n=new C(this.plugin);n.setSuggesterData(t),n.display(e=>{d(this.plugin,`${e.info}
Pluginreloading.....`,5),this.plugin.betaPlugins.reloadPlugin(e.info)})}},{id:"disablePlugin",icon:"BratIcon",name:"Plugins: Disable a plugin - toggle it off",showInRibbon:!0,callback:()=>{let t=this.plugin.betaPlugins.getEnabledDisabledPlugins(!0).map(e=>({display:`${e.name}(${e.id})`,info:e.id})),n=new C(this.plugin);n.setSuggesterData(t),n.display(e=>{this.plugin.log(`${e.display}plugindisabled`,!1),this.plugin.settings.debuggingMode&&console.log(e.info),this.plugin.app.plugins.disablePluginAndSave(e.info)})}},{id:"enablePlugin",icon:"BratIcon",name:"Plugins: Enable a plugin - toggle it on",showInRibbon:!0,callback:()=>{let t=this.plugin.betaPlugins.getEnabledDisabledPlugins(!1).map(e=>({display:`${e.name}(${e.id})`,info:e.id})),n=new C(this.plugin);n.setSuggesterData(t),n.display(e=>{this.plugin.log(`${e.display}pluginenabled`,!1),this.plugin.app.plugins.enablePluginAndSave(e.info)})}},{id:"openGitHubZRepository",icon:"BratIcon",name:"Plugins: Open the GitHub repository for a plugin",showInRibbon:!0,callback:async()=>{let t=await ht(this.plugin.settings.debuggingMode);if(t){let n=Object.values(t).map(o=>({display:`Plugin:${o.name}(${o.repo})`,info:o.repo})),e=Object.values(this.plugin.settings.pluginList).map(o=>({display:`BRAT:${o}`,info:o}));for(let o of n)e.push(o);let i=new C(this.plugin);i.setSuggesterData(e),i.display(o=>{o.info&&window.open(`https://github.com/${o.info}`)})}}},{id:"openGitHubRepoTheme",icon:"BratIcon",name:"Themes: Open the GitHub repository for a theme (appearance)",showInRibbon:!0,callback:async()=>{let t=await bt(this.plugin.settings.debuggingMode);if(t){let n=Object.values(t).map(i=>({display:`Theme: ${i.name} (${i.repo})`,info:i.repo})),e=new C(this.plugin);e.setSuggesterData(n),e.display(i=>{i.info&&window.open(`https://github.com/${i.info}`)})}}},{id:"opentPluginSettings",icon:"BratIcon",name:"Plugins: Open Plugin Settings Tab",showInRibbon:!0,callback:()=>{let t=this.plugin.app.setting,n=Object.values(t.pluginTabs).map(o=>({display:`Plugin: ${o.name}`,info:o.id})),e=new C(this.plugin),i=Object.values(t.settingTabs).map(o=>({display:`Core: ${o.name}`,info:o.id}));for(let o of n)i.push(o);e.setSuggesterData(i),e.display(o=>{t.open(),t.openTabById(o.info)})}},{id:"GrabBetaTheme",icon:"BratIcon",name:"Themes: Grab a beta theme for testing from a Github repository",showInRibbon:!0,callback:()=>{new S(this.plugin).open()}},{id:"updateBetaThemes",icon:"BratIcon",name:"Themes: Update beta themes",showInRibbon:!0,callback:async()=>{await B(this.plugin,!0)}},{id:"allCommands",icon:"BratIcon",name:"All Commands list",showInRibbon:!1,callback:()=>{this.ribbonDisplayCommands()}}];this.plugin=t;for(let n of this.bratCommands)this.plugin.addCommand({id:n.id,name:n.name,icon:n.icon,callback:()=>{n.callback()}})}ribbonDisplayCommands(){let t=[];for(let a of this.bratCommands)a.showInRibbon&&t.push({display:a.name,info:a.callback});let n=new C(this.plugin),e=this.plugin.app.setting,i=Object.values(e.settingTabs).map(a=>({display:`Core: ${a.name}`,info:()=>{e.open(),e.openTabById(a.id)}})),o=Object.values(e.pluginTabs).map(a=>({display:`Plugin: ${a.name}`,info:()=>{e.open(),e.openTabById(a.id)}}));t.push({display:"---- Core Plugin Settings ----",info:()=>{this.ribbonDisplayCommands()}});for(let a of i)t.push(a);t.push({display:"---- Plugin Settings ----",info:()=>{this.ribbonDisplayCommands()}});for(let a of o)t.push(a);n.setSuggesterData(t),n.display(a=>{typeof a.info=="function"&&a.info()})}};var y=require("obsidian");var at=(s,t)=>{let n=new DocumentFragment,e=document.createElement("a");if(e.textContent=s,e.href=`https://github.com/${s}`,n.appendChild(e),t){let i=document.createTextNode(t);n.appendChild(i)}return n},et=class extends y.PluginSettingTab{constructor(t,n){super(t,n),this.plugin=n}display(){let{containerEl:t}=this;t.empty(),new y.Setting(t).setName("Auto-enable plugins after installation").setDesc('If enabled beta plugins will be automatically enabled after installtion by default. Note: you can toggle this on and off for each plugin in the "Add Plugin" form.').addToggle(e=>{
`," ")}
`,g=s.app.vault.getAbstractFileByPath(e);g?await s.app.vault.append(g,l):g=await s.app.vault.create(e,l)}}var nt=class extends jt.Plugin{constructor(){super(...arguments);this.APP_NAME="BRAT";this.APP_ID="obsidian42-brat";this.settings=ot;this.betaPlugins=new R(this);this.commands=new U(this);this.bratApi=new z(this);this.obsidianProtocolHandler=n=>{if(!n.plugin&&!n.theme){d(this,"Could not locate the repository from the URL.",10);return}for(let e of["plugin","theme"])if(n[e]){let i=e==="plugin"?new N(this,this.betaPlugins):new S(this);i.address=n[e],i.open();return}}}onload(){console.log(`loading${this.APP_NAME}`),this.loadSettings().then(()=>{this.app.workspace.onLayoutReady(()=>{this.addSettingTab(new et(this.app,this)),kt(),this.showRibbonButton(),this.registerObsidianProtocolHandler("brat",this.obsidianProtocolHandler),this.settings.updateAtStartup&&setTimeout(()=>{this.betaPlugins.checkForPluginUpdatesAndInstallUpdates(!1)},6e4),this.settings.updateThemesAtStartup&&setTimeout(()=>{B(this,!1)},12e4),setTimeout(()=>{window.bratAPI=this.bratApi},500)})}).catch(n=>{console.error("Failed to load settings:",n)})}showRibbonButton(){this.addRibbonIcon("BratIcon","BRAT",()=>{this.commands.ribbonDisplayCommands()})}async log(n,e=!1){await Yt(this,n,e)}onunload(){console.log(`unloading${this.APP_NAME}`)}async loadSettings(){this.settings=Object.assign({},ot,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}};