tech-tips/.obsidian/plugins/oz-clear-unused-images/main.js

3 lines
22 KiB
JavaScript
Raw Normal View History

"use strict";var e=require("obsidian");function t(e,t,i,s){return new(i||(i=Promise))((function(n,a){function o(e){try{d(s.next(e))}catch(e){a(e)}}function l(e){try{d(s.throw(e))}catch(e){a(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,l)}d((s=s.apply(e,t||[])).next())}))}const i={deleteOption:".trash",logsModal:!0,excludedFolders:"",ribbonIcon:!1,excludeSubfolders:!1};class s extends e.PluginSettingTab{constructor(e,t){super(e,t),this.plugin=t}display(){let{containerEl:t}=this;t.empty(),t.createEl("h2",{text:"Clear Images Settings"}),new e.Setting(t).setName("Ribbon Icon").setDesc("Turn on if you want Ribbon Icon for clearing the images.").addToggle((e=>e.setValue(this.plugin.settings.ribbonIcon).onChange((e=>{this.plugin.settings.ribbonIcon=e,this.plugin.saveSettings(),this.plugin.refreshIconRibbon()})))),new e.Setting(t).setName("Delete Logs").setDesc("Turn off if you dont want to view the delete logs Modal to pop up after deletion is completed. It wont appear if no image is deleted").addToggle((e=>e.setValue(this.plugin.settings.logsModal).onChange((e=>{this.plugin.settings.logsModal=e,this.plugin.saveSettings()})))),new e.Setting(t).setName("Deleted Image Destination").setDesc("Select where you want images to be moved once they are deleted").addDropdown((e=>{e.addOption("permanent","Delete Permanently"),e.addOption(".trash","Move to Obsidian Trash"),e.addOption("system-trash","Move to System Trash"),e.setValue(this.plugin.settings.deleteOption),e.onChange((e=>{this.plugin.settings.deleteOption=e,this.plugin.saveSettings()}))})),new e.Setting(t).setName("Excluded Folder Full Paths").setDesc("Provide the FULL path of the folder names (Case Sensitive) divided by comma (,) to be excluded from clearing. \n\t\t\t\t\ti.e. For images under Personal/Files/Zodiac -> Personal/Files/Zodiac should be used for exclusion").addTextArea((e=>e.setValue(this.plugin.settings.excludedFolders).onChange((e=>{this.plugin.settings.excludedFolders=e,this.plugin.saveSettings()})))),new e.Setting(t).setName("Exclude Subfolders").setDesc("Turn on this option if you want to also exclude all subfolders of the folder paths provided above.").addToggle((e=>e.setValue(this.plugin.settings.excludeSubfolders).onChange((e=>{this.plugin.settings.excludeSubfolders=e,this.plugin.saveSettings()}))));const i=t.createDiv("coffee");i.addClass("oz-coffee-div");i.createEl("a",{href:"https://ko-fi.com/L3L356V6Q"}).createEl("img",{attr:{src:"https://cdn.ko-fi.com/cdn/kofi2.png?v=3"}}).height=45}}class n extends e.Modal{constructor(e,t){super(t),this.textToView=e}onOpen(){let{contentEl:e}=this,t=this;const i=e.createEl("div");i.addClass("unused-images-center-wrapper");i.createEl("h1",{text:"Clear Unused Images - Logs"}).addClass("modal-title");const s=e.createEl("div");s.addClass("unused-images-logs"),s.innerHTML=this.textToView;const n=e.createEl("div");n.addClass("unused-images-center-wrapper");const a=n.createEl("button",{text:"Close"});a.addClass("unused-images-button"),a.addEventListener("click",(()=>{t.close()}))}}const a=(e,i,s)=>t(void 0,void 0,void 0,(function*(){const t=[];void 0===s&&(s=yield i.vault.read(e));let n=s.match(/\[\[.*?\]\]/g);if(n){let s=/(?<=\[\[).*?(?=(\]|\|))/;for(let a of n){if(h(a)){let s=u(a),n=i.metadataCache.getFirstLinkpathDest(s,e.path);if(""!==s){let i={type:"wikiTransclusion",match:a,linkText:n?n.path:s,sourceFilePath:e.path};t.push(i);continue}}let n=a.match(s);if(n){if(n[0].startsWith("http"))continue;let s=i.metadataCache.getFirstLinkpathDest(n[0],e.path),o={type:"wiki",match:a,linkText:s?s.path:n[0],sourceFilePath:e.path};t.push(o)}}}let a=s.match(/\[(^$|.*?)\]\((.*?)\)/g);if(a){let s=/(?<=\().*(?=\))/;for(let n of a){if(c(n)){let s=u(n),a=i.metadataCache.getFirstLinkpathDest(s,e.path);if(""!==s){let i={type:"mdTransclusion",match:n,linkText:a?a.path:s,sourceFilePath:e.path};t.push(i);continue}}let a=n.match(s);if(a){if(a[0].startsWith("http"))continue;let s=i.metadataCache.getFirstLinkpathDest(a[0],e.path),o={type:"markdown",match:n,linkText:s?s.path:a[0],sourceFile
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZXMiOlsibm9kZV9tb2R1bGVzL3RzbGliL3RzbGliLmVzNi5qcyIsInNyYy9zZXR0aW5ncy50cyIsInNyYy9tb2RhbHMudHMiLCJzcmMvbGlua0RldGVjdG9yLnRzIiwic3JjL3V0aWwudHMiLCJzcmMvbWFpbi50cyJdLCJzb3VyY2VzQ29udGVudCI6bnVsbCwibmFtZXMiOlsiX19hd2FpdGVyIiwidGhpc0FyZyIsIl9hcmd1bWVudHMiLCJQIiwiZ2VuZXJhdG9yIiwiUHJvbWlzZSIsInJlc29sdmUiLCJyZWplY3QiLCJmdWxmaWxsZWQiLCJ2YWx1ZSIsInN0ZXAiLCJuZXh0IiwiZSIsInJlamVjdGVkIiwicmVzdWx0IiwiZG9uZSIsInRoZW4iLCJhcHBseSIsIkRFRkFVTFRfU0VUVElOR1MiLCJkZWxldGVPcHRpb24iLCJsb2dzTW9kYWwiLCJleGNsdWRlZEZvbGRlcnMiLCJyaWJib25JY29uIiwiZXhjbHVkZVN1YmZvbGRlcnMiLCJPemFuQ2xlYXJJbWFnZXNTZXR0aW5nc1RhYiIsIlBsdWdpblNldHRpbmdUYWIiLCJjb25zdHJ1Y3RvciIsImFwcCIsInBsdWdpbiIsInN1cGVyIiwidGhpcyIsImRpc3BsYXkiLCJjb250YWluZXJFbCIsImVtcHR5IiwiY3JlYXRlRWwiLCJ0ZXh0IiwiU2V0dGluZyIsInNldE5hbWUiLCJzZXREZXNjIiwiYWRkVG9nZ2xlIiwidG9nZ2xlIiwic2V0VmFsdWUiLCJzZXR0aW5ncyIsIm9uQ2hhbmdlIiwic2F2ZVNldHRpbmdzIiwicmVmcmVzaEljb25SaWJib24iLCJhZGREcm9wZG93biIsImRyb3Bkb3duIiwiYWRkT3B0aW9uIiwib3B0aW9uIiwiY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