/ *
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 _ _commonJS = ( cb , mod ) => function _ _require ( ) {
return mod || ( 0 , cb [ Object . keys ( cb ) [ 0 ] ] ) ( ( mod = { exports : { } } ) . exports , mod ) , mod . exports ;
} ;
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 ( ) ) ;
} ) ;
} ;
// node_modules/@aidenlx/obsidian-icon-shortcodes/lib/index.js
var require _lib = _ _commonJS ( {
"node_modules/@aidenlx/obsidian-icon-shortcodes/lib/index.js" ( exports ) {
var t = Object . create ;
var o = Object . defineProperty ;
var a = Object . getOwnPropertyDescriptor ;
var p = Object . getOwnPropertyNames ;
var d = Object . getPrototypeOf ;
var l = Object . prototype . hasOwnProperty ;
var r = ( n ) => o ( n , "__esModule" , { value : true } ) ;
var g = ( n , e ) => {
r ( n ) ;
for ( var i in e )
o ( n , i , { get : e [ i ] , enumerable : true } ) ;
} ;
var c = ( n , e , i ) => {
if ( e && typeof e == "object" || typeof e == "function" )
for ( let s of p ( e ) )
! l . call ( n , s ) && s !== "default" && o ( n , s , { get : ( ) => e [ s ] , enumerable : ! ( i = a ( e , s ) ) || i . enumerable } ) ;
return n ;
} ;
var u = ( n ) => c ( r ( o ( n != null ? t ( d ( n ) ) : { } , "default" , n && n . _ _esModule && "default" in n ? { get : ( ) => n . default , enumerable : true } : { value : n , enumerable : true } ) ) , n ) ;
g ( exports , { getApi : ( ) => P , isPluginEnabled : ( ) => f } ) ;
var b = u ( require ( "obsidian" ) ) ;
var P = ( n ) => {
var e ;
return n ? ( e = n . app . plugins . plugins [ "obsidian-icon-shortcodes" ] ) == null ? void 0 : e . api : window . IconSCAPIv0 ;
} ;
var f = ( n ) => n . app . plugins . enabledPlugins . has ( "obsidian-icon-shortcodes" ) ;
}
} ) ;
// src/main.ts
_ _export ( exports , {
default : ( ) => FaviconPlugin
} ) ;
var import _obsidian4 = _ _toModule ( require ( "obsidian" ) ) ;
// src/settings.ts
var import _obsidian3 = _ _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/OverwrittenIconModal.ts
var import _obsidian2 = _ _toModule ( require ( "obsidian" ) ) ;
var import _obsidian _icon _shortcodes = _ _toModule ( require _lib ( ) ) ;
var OverwrittenIconModal = class extends import _obsidian2 . Modal {
constructor ( plugin , map , name ) {
super ( plugin . app ) ;
this . name = "Domain" ;
this . plugin = plugin ;
if ( name ) {
this . name = name ;
}
if ( map ) {
this . domain = map . domain ;
this . icon = map . icon ;
}
}
displayPreview ( contentEl ) {
return _ _async ( this , null , function * ( ) {
if ( ( 0 , import _obsidian _icon _shortcodes . isPluginEnabled ) ( this . plugin ) && this . icon ) {
contentEl . empty ( ) ;
const iconPreview = contentEl . createDiv ( "preview" ) ;
iconPreview . addClass ( "link-favicon-preview" ) ;
const iconApi = ( 0 , import _obsidian _icon _shortcodes . getApi ) ( this . plugin ) ;
const icon = iconApi . getIcon ( this . icon , false ) ;
if ( icon !== null )
iconPreview . append ( icon ) ;
}
} ) ;
}
display ( ) {
return _ _async ( this , null , function * ( ) {
const { contentEl } = this ;
contentEl . empty ( ) ;
let previewEL ;
new import _obsidian2 . Setting ( contentEl ) . setName ( this . name ) . addText ( ( text ) => {
text . setValue ( this . domain ) . onChange ( ( value ) => {
this . domain = value ;
} ) ;
} ) ;
new import _obsidian2 . Setting ( contentEl ) . setName ( "Icon" ) . addText ( ( text ) => {
text . setValue ( this . icon ) . onChange ( ( value ) => {
this . icon = value ;
if ( previewEL ) {
this . displayPreview ( previewEL ) ;
}
} ) ;
} ) ;
previewEL = contentEl . createDiv ( "preview" ) ;
yield this . displayPreview ( previewEL ) ;
const footerEl = contentEl . createDiv ( ) ;
const footerButtons = new import _obsidian2 . Setting ( footerEl ) ;
footerButtons . addButton ( ( b ) => {
b . setTooltip ( "Save" ) . setIcon ( "checkmark" ) . onClick ( ( ) => _ _async ( this , null , function * ( ) {
this . saved = true ;
this . close ( ) ;
} ) ) ;
return b ;
} ) ;
footerButtons . addExtraButton ( ( b ) => {
b . setIcon ( "cross" ) . setTooltip ( "Cancel" ) . onClick ( ( ) => {
this . saved = false ;
this . close ( ) ;
} ) ;
return b ;
} ) ;
} ) ;
}
onOpen ( ) {
return _ _async ( this , null , function * ( ) {
yield this . display ( ) ;
} ) ;
}
} ;
// src/settings.ts
var import _obsidian _icon _shortcodes2 = _ _toModule ( require _lib ( ) ) ;
var DEFAULT _SETTINGS = {
provider : "duckduckgo" ,
fallbackProvider : "google" ,
providerDomain : "" ,
fallbackProviderDomain : "" ,
ignored : "" ,
overwritten : [ ] ,
protocol : [ ]
} ;
var FaviconSettings = class extends import _obsidian3 . PluginSettingTab {
constructor ( app , plugin ) {
super ( app , plugin ) ;
this . plugin = plugin ;
}
display ( ) {
const { containerEl } = this ;
containerEl . empty ( ) ;
containerEl . createEl ( "h2" , { text : "Link Favicons" } ) ;
new import _obsidian3 . 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 _obsidian3 . Setting ( containerEl ) . setName ( "Provider Domain" ) . setDesc ( "This Provider is 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 _obsidian3 . 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 _obsidian3 . 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 _obsidian3 . 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 ) ;
} ) ;
if ( ( 0 , import _obsidian _icon _shortcodes2 . isPluginEnabled ) ( this . plugin ) ) {
containerEl . createEl ( "h2" , { text : "Custom icons" } ) ;
containerEl . createEl ( "h3" , { text : "for Domains" } ) ;
new import _obsidian3 . Setting ( containerEl ) . setName ( "Add New" ) . setDesc ( "Add custom icon" ) . addButton ( ( button ) => {
return button . setTooltip ( "add custom icon" ) . setIcon ( "plus-with-circle" ) . onClick ( ( ) => _ _async ( this , null , function * ( ) {
const modal = new OverwrittenIconModal ( this . plugin ) ;
modal . onClose = ( ) => _ _async ( this , null , function * ( ) {
if ( modal . saved ) {
this . plugin . settings . overwritten . push ( {
domain : modal . domain ,
icon : modal . icon
} ) ;
yield this . plugin . saveSettings ( ) ;
this . display ( ) ;
}
} ) ;
modal . open ( ) ;
} ) ) ;
} ) ;
const overwrittenContainer = containerEl . createDiv ( "overwritten" ) ;
const overwrittenDiv = overwrittenContainer . createDiv ( "overwritten" ) ;
for ( const overwritten of this . plugin . settings . overwritten ) {
const setting = new import _obsidian3 . Setting ( overwrittenDiv ) ;
const iconAPI = ( 0 , import _obsidian _icon _shortcodes2 . getApi ) ( this . plugin ) ;
const desc = new DocumentFragment ( ) ;
desc . createEl ( "p" , { text : " " + overwritten . icon } ) . prepend ( iconAPI . getIcon ( overwritten . icon ) ) ;
setting . setName ( overwritten . domain ) . setDesc ( desc ) . addExtraButton ( ( b ) => {
b . setIcon ( "pencil" ) . setTooltip ( "Edit" ) . onClick ( ( ) => {
const modal = new OverwrittenIconModal ( this . plugin , overwritten ) ;
modal . onClose = ( ) => _ _async ( this , null , function * ( ) {
if ( modal . saved ) {
const setting2 = this . plugin . settings . overwritten . filter ( ( overwritten2 ) => {
return overwritten2 . domain !== modal . domain ;
} ) ;
setting2 . push ( { domain : modal . domain , icon : modal . icon } ) ;
this . plugin . settings . overwritten = setting2 ;
yield this . plugin . saveSettings ( ) ;
this . display ( ) ;
}
} ) ;
modal . open ( ) ;
} ) ;
} ) . addExtraButton ( ( b ) => {
b . setIcon ( "trash" ) . setTooltip ( "Delete" ) . onClick ( ( ) => _ _async ( this , null , function * ( ) {
this . display ( ) ;
} ) ) ;
} ) ;
}
containerEl . createEl ( "h3" , { text : "for URI Schemas" } ) ;
new import _obsidian3 . Setting ( containerEl ) . setName ( "Add New" ) . setDesc ( "Add custom icon" ) . addButton ( ( button ) => {
return button . setTooltip ( "add custom icon" ) . setIcon ( "plus-with-circle" ) . onClick ( ( ) => _ _async ( this , null , function * ( ) {
const modal = new OverwrittenIconModal ( this . plugin , null , "URI Schema" ) ;
modal . onClose = ( ) => _ _async ( this , null , function * ( ) {
if ( modal . saved ) {
this . plugin . settings . protocol . push ( {
domain : modal . domain ,
icon : modal . icon
} ) ;
yield this . plugin . saveSettings ( ) ;
this . display ( ) ;
}
} ) ;
modal . open ( ) ;
} ) ) ;
} ) ;
const protocolContainer = containerEl . createDiv ( "overwritten" ) ;
const voicesDiv = protocolContainer . createDiv ( "overwritten" ) ;
for ( const protocol of this . plugin . settings . protocol ) {
const setting = new import _obsidian3 . Setting ( voicesDiv ) ;
const iconAPI = ( 0 , import _obsidian _icon _shortcodes2 . getApi ) ( this . plugin ) ;
const desc = new DocumentFragment ( ) ;
desc . createEl ( "p" , { text : " " + protocol . icon } ) . prepend ( iconAPI . getIcon ( protocol . icon ) ) ;
setting . setName ( protocol . domain ) . setDesc ( desc ) . addExtraButton ( ( b ) => {
b . setIcon ( "pencil" ) . setTooltip ( "Edit" ) . onClick ( ( ) => {
const modal = new OverwrittenIconModal ( this . plugin , protocol , "URI Schema" ) ;
modal . onClose = ( ) => _ _async ( this , null , function * ( ) {
if ( modal . saved ) {
const setting2 = this . plugin . settings . protocol . filter ( ( overwritten ) => {
return overwritten . domain !== modal . domain ;
} ) ;
setting2 . push ( { domain : modal . domain , icon : modal . icon } ) ;
this . plugin . settings . protocol = setting2 ;
yield this . plugin . saveSettings ( ) ;
this . display ( ) ;
}
} ) ;
modal . open ( ) ;
} ) ;
} ) . addExtraButton ( ( b ) => {
b . setIcon ( "trash" ) . setTooltip ( "Delete" ) . onClick ( ( ) => _ _async ( this , null , function * ( ) {
this . plugin . settings . protocol = this . plugin . settings . protocol . filter ( ( overwritten ) => {
return overwritten . domain !== protocol . domain ;
} ) ;
yield this . plugin . saveSettings ( ) ;
this . display ( ) ;
} ) ) ;
} ) ;
}
}
}
} ;
// src/main.ts
var import _obsidian _icon _shortcodes3 = _ _toModule ( require _lib ( ) ) ;
var FaviconPlugin = class extends import _obsidian4 . Plugin {
isDisabled ( el ) {
if ( el . getAttribute ( "data-no-favicon" ) )
return true ;
if ( el . getAttribute ( "data-favicon" ) )
return true ;
}
displayCustomIcon ( icons , link , domain ) {
if ( icons . length > 0 ) {
const iconApi = ( 0 , import _obsidian _icon _shortcodes3 . getApi ) ( this ) ;
const icon = icons [ 0 ] . icon ;
const icon2 = iconApi . getIcon ( icon , false ) ;
if ( icon2 !== null ) {
if ( typeof icon2 !== "string" ) {
icon2 . addClass ( "link-favicon" ) ;
icon2 . dataset . host = domain ;
}
link . prepend ( icon2 ) ;
return true ;
}
}
return false ;
}
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 , ctx ) => _ _async ( this , null , function * ( ) {
if ( ctx . sourcePath . contains ( "no-favicon" ) ) {
return ;
}
const provider = providers [ this . settings . provider ] ;
const fallbackProvider = providers [ this . settings . fallbackProvider ] ;
if ( ! provider || ! fallbackProvider ) {
console . error ( "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 ( ! domain . protocol . contains ( "http" ) ) {
if ( ( 0 , import _obsidian _icon _shortcodes3 . isPluginEnabled ) ( this ) ) {
const icons = this . settings . protocol . filter ( ( overwritten ) => overwritten . domain === domain . protocol . replace ( /:/g , "" ) ) ;
if ( this . displayCustomIcon ( icons , link , domain . protocol ) )
continue ;
}
}
if ( this . settings . ignored . split ( "\n" ) . contains ( domain . hostname ) ) {
continue ;
}
if ( ( 0 , import _obsidian _icon _shortcodes3 . isPluginEnabled ) ( this ) ) {
const icons = this . settings . overwritten . filter ( ( overwritten ) => overwritten . domain === domain . hostname ) ;
if ( this . displayCustomIcon ( icons , link , domain . hostname ) )
continue ;
}
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 ) ;
} ) ;
}
} ;