Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented placeholder {URL:SCM} for the Google custom provider #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion YAFD/FaviconDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private void BgWorker_DoWork(object sender, DoWorkEventArgs e)
if (nameProperty != null)
{
// Since the URL was valid, we just force a valid scheme prefix to be able to get the Host
var host = fd.GetValidHost(url);
var host = fd.GetValidUri(url);
nameProperty.SetValue(icons[i], "yafd-" + host);
}

Expand Down
11 changes: 7 additions & 4 deletions YAFD/FaviconDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ public byte[] GetIcon(string url)
public byte[] GetIconCustomProvider(string url)
{
// Get the hostname from the requested URL
var hostname = GetValidHost(url);
var baseUri = GetValidUri(url);
string hostname = baseUri.Host;
string scheme = baseUri.Scheme;

// Custom provider settings
var providerURL = YetAnotherFaviconDownloaderExt.Config.GetCustomDownloadProvider();
Expand All @@ -218,6 +220,7 @@ public byte[] GetIconCustomProvider(string url)
// https://keepass.info/help/base/placeholders.html

// Maybe in the future we can give full/proper support, well, not today, for now it's enough
providerURL = Regex.Replace(providerURL, "{URL:SCM}", scheme, RegexOptions.IgnoreCase);
providerURL = Regex.Replace(providerURL, "{URL:HOST}", hostname, RegexOptions.IgnoreCase);
providerURL = Regex.Replace(providerURL, "{YAFD:ICON_SIZE}", iconSize, RegexOptions.IgnoreCase);

Expand Down Expand Up @@ -253,7 +256,7 @@ public byte[] GetIconCustomProvider(string url)
throw new FaviconDownloaderException(FaviconDownloaderExceptionStatus.NotFound);
}

public string GetValidHost(string url)
public Uri GetValidUri(string url)
{
if (!httpSchema.IsMatch(url))
{
Expand All @@ -264,11 +267,11 @@ public string GetValidHost(string url)
Uri result;
if (Uri.TryCreate(url, UriKind.Absolute, out result))
{
return result.Host;
return result;
}

// we shouldn't see this case
return "";
return new Uri("about:blank");
}

protected override WebRequest GetWebRequest(Uri address)
Expand Down
2 changes: 1 addition & 1 deletion YAFD/ProviderList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static ProviderList()
providers.Add(new Provider("None (Default)", null));
providers.Add(new Provider("DuckDuckGo", "https://icons.duckduckgo.com/ip3/{URL:HOST}.ico"));
providers.Add(new Provider("Favicon Kit", "https://api.faviconkit.com/{URL:HOST}/{YAFD:ICON_SIZE}"));
providers.Add(new Provider("Google", "https://www.google.com/s2/favicons?domain={URL:HOST}&sz={YAFD:ICON_SIZE}"));
providers.Add(new Provider("Google", "https://www.google.com/s2/favicons?domain={URL:SCM}://{URL:HOST}&sz={YAFD:ICON_SIZE}"));
providers.Add(new Provider("Yandex", "https://favicon.yandex.net/favicon/{URL:HOST}"));
providers.Add(customProvider);
}
Expand Down