Script to set feed thumbnails to favicon

The URL is

The script has changed slightly:

function performSmartRule(records) {

  var app = Application("DEVONthink 3");
  app.includeStandardAdditions = true;
    
  var feedURL, URLmatch, httpPath, favIcon, favTry;
  records.forEach(f => {
	  feedURL = f.url();
	  app.logMessage("1: " + feedURL);
	  URLmatch = feedURL.match(/(https?|feed)(:\/\/[^/]+\/)/);
	  app.logMessage("match: " + URLmatch.length);
	  if (URLmatch[1] === "feed") {
	     httpPath = "http" + URLmatch[2];
	  } else { 
	     httpPath = URLmatch[1] + URLmatch[2];
      }
	  favIcon = httpPath + "favicon.ico";
	  
	  favTry = getIcon(app, httpPath);
	  if (!favTry) {
	    favTry = getIcon(app, httpPath.replace(/(feeds?|rss)\./,""));
	  }
	
	  app.logMessage("3: " + favIcon);
  	  favIcon = favTry ? favTry : favIcon;
	  f.thumbnail = favIcon;
	  app.logMessage("4: f.type - " + f.type());
	  if (f.type() === "feed") {
  	    f. children().forEach(c => {
	      c.thumbnail = favIcon;
		})
	  }
    })
  }

  function getIcon(app, url) {
 	 app.logMessage("getIcon " + url);
     let favIcon = null;
     const HTML = app.downloadMarkupFrom(url );
	 const embImages = app.getEmbeddedImagesOf(HTML, { baseURL: url});
	  favIcon = embImages.find(img => 
	    (img.match(/\.ico$/) || img.match(/\/favicon/) || img.match(/icon/,"g")));
      app.logMessage("found: " + favIcon);
      return favIcon;
  }


  var app = Application("DEVONthink 3");
  app.includeStandardAdditions = true 
/*  let dbName = "Feedly"; // NOTE: Adjust this to your database name 
  let db = app.databases.whose({name: dbName})[0].root();
  let feeds = app.search("kind:feed", {in: db});*/
  performSmartRule(app.selection());