You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
8.7 KiB

/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
https://github.com/joethei/obisidian-link-favicon
*/
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = (target, module2, desc) => {
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
for (let key of __getOwnPropNames(module2))
if (!__hasOwnProp.call(target, key) && key !== "default")
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
}
return target;
};
var __toModule = (module2) => {
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
};
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// src/main.ts
__export(exports, {
default: () => FaviconPlugin
});
var import_obsidian3 = __toModule(require("obsidian"));
// src/settings.ts
var import_obsidian2 = __toModule(require("obsidian"));
// src/provider.ts
var import_obsidian = __toModule(require("obsidian"));
var providers = {
"google": { name: "Google", url: (domain) => Promise.resolve("https://www.google.com/s2/favicons?domain=" + domain) },
"duckduckgo": { name: "DuckDuckGo", url: (domain) => Promise.resolve("https://icons.duckduckgo.com/ip3/" + domain + ".ico") },
"iconhorse": { name: "Icon Horse", url: (domain) => Promise.resolve("https://icon.horse/icon/" + domain) },
"splitbee": { name: "Splitbee", url: (domain) => Promise.resolve("https://favicon.splitbee.io/?url=" + domain) },
"besticon": { name: "The Favicon Finder", url: (domain, settings) => {
const host = settings.provider === "besticon" ? settings.providerDomain : settings.fallbackProviderDomain;
return Promise.resolve(host + "/icon?url=" + domain + "&size=32..64..256");
} },
"favicongrabber": { name: "Favicon Grabber", url: (domain) => __async(void 0, null, function* () {
const icons = JSON.parse(yield (0, import_obsidian.request)({
method: "GET",
url: "https://favicongrabber.com/api/grab/" + domain
}));
if (icons.length === 0)
return Promise.resolve("http://invalid.stuff");
return Promise.resolve(icons.icons[0].src);
}) }
};
// src/settings.ts
var DEFAULT_SETTINGS = {
provider: "duckduckgo",
fallbackProvider: "google",
providerDomain: "",
fallbackProviderDomain: "",
ignored: ""
};
var FaviconSettings = class extends import_obsidian2.PluginSettingTab {
constructor(app, plugin) {
super(app, plugin);
this.plugin = plugin;
}
display() {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl("h2", { text: "Link Favicons" });
new import_obsidian2.Setting(containerEl).setName("Icon Provider").addDropdown((dropdown) => {
for (const id in providers) {
if (providers.hasOwnProperty(id)) {
dropdown.addOption(id, providers[id].name);
}
}
dropdown.setValue(this.plugin.settings.provider).onChange((value) => __async(this, null, function* () {
this.plugin.settings.provider = value;
yield this.plugin.saveSettings();
this.display();
}));
});
if (Array.of("besticon").includes(this.plugin.settings.provider)) {
new import_obsidian2.Setting(containerEl).setName("Provider Domain").setDesc("This Provider is be selfhosted, please specify your deployment url. Refer to the readme of the provider for deployment instructions.").addText((text) => text.setValue(this.plugin.settings.providerDomain).onChange((value) => __async(this, null, function* () {
this.plugin.settings.providerDomain = value;
yield this.plugin.saveSettings();
})));
}
new import_obsidian2.Setting(containerEl).setName("Fallback Icon Provider").addDropdown((dropdown) => {
for (const id in providers) {
if (providers.hasOwnProperty(id)) {
dropdown.addOption(id, providers[id].name);
}
}
dropdown.setValue(this.plugin.settings.fallbackProvider).onChange((value) => __async(this, null, function* () {
this.plugin.settings.fallbackProvider = value;
yield this.plugin.saveSettings();
this.display();
}));
});
if (Array.of("besticon").includes(this.plugin.settings.fallbackProvider)) {
new import_obsidian2.Setting(containerEl).setName("Fallback Provider Domain").setDesc("This Provider is be selfhosted, please specify your deployment url. Refer to the readme of the provider for deployment instructions.").addText((text) => text.setValue(this.plugin.settings.fallbackProviderDomain).onChange((value) => __async(this, null, function* () {
this.plugin.settings.fallbackProviderDomain = value;
yield this.plugin.saveSettings();
})));
}
new import_obsidian2.Setting(containerEl).setName("Ignored Domains").setDesc("Don't show an favicon for these domains(one per line)").addTextArea((text) => {
text.setValue(this.plugin.settings.ignored).onChange((value) => __async(this, null, function* () {
this.plugin.settings.ignored = value;
yield this.plugin.saveSettings();
}));
text.inputEl.setAttr("rows", 8);
});
}
};
// src/main.ts
var FaviconPlugin = class extends import_obsidian3.Plugin {
isDisabled(el) {
if (el.getAttribute("data-no-favicon"))
return true;
if (el.getAttribute("data-favicon"))
return true;
const style = getComputedStyle(el, ":before").getPropertyValue("background-url");
console.log(style);
}
onload() {
return __async(this, null, function* () {
console.log("enabling plugin: link favicons");
yield this.loadSettings();
this.addSettingTab(new FaviconSettings(this.app, this));
this.registerMarkdownPostProcessor((element, _) => __async(this, null, function* () {
const provider = providers[this.settings.provider];
const fallbackProvider = providers[this.settings.fallbackProvider];
if (!provider || !fallbackProvider) {
console.log("Link Favicons: misconfigured providers");
return;
}
const links = element.querySelectorAll("a.external-link:not([data-favicon])");
for (let index = 0; index < links.length; index++) {
const link = links.item(index);
if (!this.isDisabled(link)) {
link.dataset.favicon = "true";
try {
const domain = new URL(link.href);
if (!this.settings.ignored.split("\n").contains(domain.hostname)) {
const el = document.createElement("object");
el.addClass("link-favicon");
el.dataset.host = domain.hostname;
el.data = yield provider.url(domain.hostname, this.settings);
el.data.contains(".ico") ? el.type = "image/x-icon" : el.type = "image/png";
el.style.height = "0.8em";
el.style.display = "inline-block";
const img = el.createEl("img");
img.src = yield fallbackProvider.url(domain.hostname, this.settings);
img.addClass("link-favicon");
img.style.height = "0.8em";
img.style.display = "block";
link.prepend(el);
}
} catch (e) {
console.log("Link Favicons: invalid url: " + link.href);
}
}
}
}));
});
}
onunload() {
console.log("disabling plugin: link favicons");
}
loadSettings() {
return __async(this, null, function* () {
this.settings = Object.assign({}, DEFAULT_SETTINGS, yield this.loadData());
});
}
saveSettings() {
return __async(this, null, function* () {
yield this.saveData(this.settings);
});
}
};