|
@@ -2,6 +2,7 @@ using System.Collections;
|
|
using System.Diagnostics;
|
|
using System.Diagnostics;
|
|
using System.Resources;
|
|
using System.Resources;
|
|
using System.Text;
|
|
using System.Text;
|
|
|
|
+using System.Windows.Forms;
|
|
using Microsoft.Web.WebView2.Core;
|
|
using Microsoft.Web.WebView2.Core;
|
|
|
|
|
|
namespace EdgeVoyager
|
|
namespace EdgeVoyager
|
|
@@ -30,8 +31,6 @@ namespace EdgeVoyager
|
|
{
|
|
{
|
|
await webView21.EnsureCoreWebView2Async(null);
|
|
await webView21.EnsureCoreWebView2Async(null);
|
|
string resxFilePath = "favoritesMenuItem.resx";
|
|
string resxFilePath = "favoritesMenuItem.resx";
|
|
- string faviconUrl = await webView21.CoreWebView2.ExecuteScriptAsync("var link = document.querySelector('link[rel~=\"icon\"]') || document.querySelector('link[rel~=\"shortcut icon\"]');link ? link.href : '';");
|
|
|
|
- byte[] iconData = await DownloadFaviconAsync(faviconUrl);
|
|
|
|
using (ResXResourceReader reader = new ResXResourceReader(resxFilePath))
|
|
using (ResXResourceReader reader = new ResXResourceReader(resxFilePath))
|
|
{
|
|
{
|
|
foreach (DictionaryEntry entry in reader)
|
|
foreach (DictionaryEntry entry in reader)
|
|
@@ -44,22 +43,6 @@ namespace EdgeVoyager
|
|
Tag = resourceValue
|
|
Tag = resourceValue
|
|
};
|
|
};
|
|
menuItem.Click += MenuItem_Click;
|
|
menuItem.Click += MenuItem_Click;
|
|
- string iconResxFilePath = "favoritesMenuItemIcon.resx";
|
|
|
|
- using (ResXResourceReader iconReader = new ResXResourceReader(iconResxFilePath))
|
|
|
|
- {
|
|
|
|
- foreach (DictionaryEntry iconEntry in iconReader)
|
|
|
|
- {
|
|
|
|
- if (iconEntry.Key.ToString() == resourceName)
|
|
|
|
- {
|
|
|
|
- using (MemoryStream ms = new MemoryStream(iconData))
|
|
|
|
- {
|
|
|
|
- Image iconImage = Image.FromStream(ms);
|
|
|
|
- menuItem.Image = iconImage;
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
收藏夹AToolStripMenuItem.DropDownItems.Add(menuItem);
|
|
收藏夹AToolStripMenuItem.DropDownItems.Add(menuItem);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -783,8 +766,6 @@ background-position: right top;
|
|
private async void 添加到收藏夹ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
private async void 添加到收藏夹ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
{
|
|
string resxFilePath = "favoritesMenuItem.resx";
|
|
string resxFilePath = "favoritesMenuItem.resx";
|
|
- string faviconUrl = await webView21.CoreWebView2.ExecuteScriptAsync("var link = document.querySelector('link[rel~=\"icon\"]') || document.querySelector('link[rel~=\"shortcut icon\"]');link ? link.href : '';");
|
|
|
|
- byte[] iconData = await DownloadFaviconAsync(faviconUrl);
|
|
|
|
string title = await webView21.CoreWebView2.ExecuteScriptAsync("document.title;");
|
|
string title = await webView21.CoreWebView2.ExecuteScriptAsync("document.title;");
|
|
string pageTitle = title.Trim('"');
|
|
string pageTitle = title.Trim('"');
|
|
string pageUrl = webView21.CoreWebView2.Source.ToString();
|
|
string pageUrl = webView21.CoreWebView2.Source.ToString();
|
|
@@ -802,68 +783,54 @@ background-position: right top;
|
|
}
|
|
}
|
|
if (!titleExists)
|
|
if (!titleExists)
|
|
{
|
|
{
|
|
- using (ResXResourceWriter writer = new ResXResourceWriter(resxFilePath))
|
|
|
|
- {
|
|
|
|
- writer.AddResource(pageTitle, pageUrl);
|
|
|
|
- writer.Generate();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- using (ResXResourceReader reader = new ResXResourceReader(resxFilePath))
|
|
|
|
- {
|
|
|
|
|
|
+ ResXResourceReader reader = new ResXResourceReader(resxFilePath);
|
|
|
|
+ Hashtable resources = new Hashtable();
|
|
foreach (DictionaryEntry entry in reader)
|
|
foreach (DictionaryEntry entry in reader)
|
|
{
|
|
{
|
|
- if (entry.Key.ToString() == pageTitle)
|
|
|
|
- {
|
|
|
|
- titleExists = true;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+ resources.Add(entry.Key, entry.Value);
|
|
}
|
|
}
|
|
- }
|
|
|
|
- if (!titleExists)
|
|
|
|
- {
|
|
|
|
|
|
+ reader.Close();
|
|
|
|
+
|
|
|
|
+ // 添加新的资源项
|
|
|
|
+ resources.Add(pageTitle, pageUrl);
|
|
|
|
+
|
|
|
|
+ // 写入到资源文件
|
|
using (ResXResourceWriter writer = new ResXResourceWriter(resxFilePath))
|
|
using (ResXResourceWriter writer = new ResXResourceWriter(resxFilePath))
|
|
{
|
|
{
|
|
- writer.AddResource(pageTitle, iconData);
|
|
|
|
|
|
+ foreach (DictionaryEntry entry in resources)
|
|
|
|
+ {
|
|
|
|
+ writer.AddResource(entry.Key.ToString(), entry.Value);
|
|
|
|
+ }
|
|
writer.Generate();
|
|
writer.Generate();
|
|
}
|
|
}
|
|
- }
|
|
|
|
- ToolStripItem[] itemsToRemove = 收藏夹AToolStripMenuItem.DropDownItems.Cast<ToolStripItem>()
|
|
|
|
- .SkipWhile(item => item != 收藏夹AToolStripMenuItem.DropDownItems["toolStripSeparator1"])
|
|
|
|
- .ToArray();
|
|
|
|
-
|
|
|
|
- foreach (var item in itemsToRemove)
|
|
|
|
- {
|
|
|
|
- 收藏夹AToolStripMenuItem.DropDownItems.Remove(item);
|
|
|
|
- }
|
|
|
|
- using (ResXResourceReader reader = new ResXResourceReader(resxFilePath))
|
|
|
|
- {
|
|
|
|
- foreach (DictionaryEntry entry in reader)
|
|
|
|
|
|
+ for (int i = 0; i < 收藏夹AToolStripMenuItem.DropDownItems.Count; i++)
|
|
{
|
|
{
|
|
- string resourceName = entry.Key.ToString();
|
|
|
|
- string resourceValue = entry.Value.ToString();
|
|
|
|
- ToolStripMenuItem menuItem = new ToolStripMenuItem
|
|
|
|
|
|
+ // 如果找到了toolStripSeparator10
|
|
|
|
+ if (收藏夹AToolStripMenuItem.DropDownItems[i] is ToolStripSeparator &&
|
|
|
|
+ 收藏夹AToolStripMenuItem.DropDownItems[i].Name == "toolStripSeparator10")
|
|
{
|
|
{
|
|
- Text = resourceName,
|
|
|
|
- Tag = resourceValue
|
|
|
|
- };
|
|
|
|
- menuItem.Click += MenuItem_Click;
|
|
|
|
- string iconResxFilePath = "favoritesMenuItemIcon.resx";
|
|
|
|
- using (ResXResourceReader iconReader = new ResXResourceReader(iconResxFilePath))
|
|
|
|
- {
|
|
|
|
- foreach (DictionaryEntry iconEntry in iconReader)
|
|
|
|
|
|
+ // 从toolStripSeparator10下方开始,删除所有按钮
|
|
|
|
+ for (int j = 收藏夹AToolStripMenuItem.DropDownItems.Count - 1; j > i; j--)
|
|
{
|
|
{
|
|
- if (iconEntry.Key.ToString() == resourceName)
|
|
|
|
- {
|
|
|
|
- using (MemoryStream ms = new MemoryStream(iconData))
|
|
|
|
- {
|
|
|
|
- Image iconImage = Image.FromStream(ms);
|
|
|
|
- menuItem.Image = iconImage;
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+ 收藏夹AToolStripMenuItem.DropDownItems.RemoveAt(j);
|
|
}
|
|
}
|
|
|
|
+ break; // 找到并处理完毕后退出循环
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ using (ResXResourceReader reader1 = new ResXResourceReader(resxFilePath))
|
|
|
|
+ {
|
|
|
|
+ foreach (DictionaryEntry entry in reader1)
|
|
|
|
+ {
|
|
|
|
+ string resourceName = entry.Key.ToString();
|
|
|
|
+ string resourceValue = entry.Value.ToString();
|
|
|
|
+ ToolStripMenuItem menuItem = new ToolStripMenuItem
|
|
|
|
+ {
|
|
|
|
+ Text = resourceName,
|
|
|
|
+ Tag = resourceValue
|
|
|
|
+ };
|
|
|
|
+ menuItem.Click += MenuItem_Click;
|
|
|
|
+ 收藏夹AToolStripMenuItem.DropDownItems.Add(menuItem);
|
|
}
|
|
}
|
|
- 收藏夹AToolStripMenuItem.DropDownItems.Add(menuItem);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -892,24 +859,58 @@ background-position: right top;
|
|
{
|
|
{
|
|
Form2 form2 = new Form2();
|
|
Form2 form2 = new Form2();
|
|
form2.ShowDialog();
|
|
form2.ShowDialog();
|
|
|
|
+ string resxFilePath = "favoritesMenuItem.resx";
|
|
|
|
+ for (int i = 0; i < 收藏夹AToolStripMenuItem.DropDownItems.Count; i++)
|
|
|
|
+ {
|
|
|
|
+ // 如果找到了toolStripSeparator10
|
|
|
|
+ if (收藏夹AToolStripMenuItem.DropDownItems[i] is ToolStripSeparator &&
|
|
|
|
+ 收藏夹AToolStripMenuItem.DropDownItems[i].Name == "toolStripSeparator10")
|
|
|
|
+ {
|
|
|
|
+ // 从toolStripSeparator10下方开始,删除所有按钮
|
|
|
|
+ for (int j = 收藏夹AToolStripMenuItem.DropDownItems.Count - 1; j > i; j--)
|
|
|
|
+ {
|
|
|
|
+ 收藏夹AToolStripMenuItem.DropDownItems.RemoveAt(j);
|
|
|
|
+ }
|
|
|
|
+ break; // 找到并处理完毕后退出循环
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ using (ResXResourceReader reader1 = new ResXResourceReader(resxFilePath))
|
|
|
|
+ {
|
|
|
|
+ foreach (DictionaryEntry entry in reader1)
|
|
|
|
+ {
|
|
|
|
+ string resourceName = entry.Key.ToString();
|
|
|
|
+ string resourceValue = entry.Value.ToString();
|
|
|
|
+ ToolStripMenuItem menuItem = new ToolStripMenuItem
|
|
|
|
+ {
|
|
|
|
+ Text = resourceName,
|
|
|
|
+ Tag = resourceValue
|
|
|
|
+ };
|
|
|
|
+ menuItem.Click += MenuItem_Click;
|
|
|
|
+ 收藏夹AToolStripMenuItem.DropDownItems.Add(menuItem);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- private async void Form1_Enter(object sender, EventArgs e)
|
|
|
|
|
|
+ private void Form1_Activated(object sender, EventArgs e)
|
|
{
|
|
{
|
|
string resxFilePath = "favoritesMenuItem.resx";
|
|
string resxFilePath = "favoritesMenuItem.resx";
|
|
- string faviconUrl = await webView21.CoreWebView2.ExecuteScriptAsync("var link = document.querySelector('link[rel~=\"icon\"]') || document.querySelector('link[rel~=\"shortcut icon\"]');link ? link.href : '';");
|
|
|
|
- byte[] iconData = await DownloadFaviconAsync(faviconUrl);
|
|
|
|
- ToolStripItem[] itemsToRemove = 收藏夹AToolStripMenuItem.DropDownItems.Cast<ToolStripItem>()
|
|
|
|
- .SkipWhile(item => item != 收藏夹AToolStripMenuItem.DropDownItems["toolStripSeparator1"])
|
|
|
|
- .ToArray();
|
|
|
|
-
|
|
|
|
- foreach (var item in itemsToRemove)
|
|
|
|
|
|
+ for (int i = 0; i < 收藏夹AToolStripMenuItem.DropDownItems.Count; i++)
|
|
{
|
|
{
|
|
- 收藏夹AToolStripMenuItem.DropDownItems.Remove(item);
|
|
|
|
|
|
+ // 如果找到了toolStripSeparator10
|
|
|
|
+ if (收藏夹AToolStripMenuItem.DropDownItems[i] is ToolStripSeparator &&
|
|
|
|
+ 收藏夹AToolStripMenuItem.DropDownItems[i].Name == "toolStripSeparator10")
|
|
|
|
+ {
|
|
|
|
+ // 从toolStripSeparator10下方开始,删除所有按钮
|
|
|
|
+ for (int j = 收藏夹AToolStripMenuItem.DropDownItems.Count - 1; j > i; j--)
|
|
|
|
+ {
|
|
|
|
+ 收藏夹AToolStripMenuItem.DropDownItems.RemoveAt(j);
|
|
|
|
+ }
|
|
|
|
+ break; // 找到并处理完毕后退出循环
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- using (ResXResourceReader reader = new ResXResourceReader(resxFilePath))
|
|
|
|
|
|
+ using (ResXResourceReader reader1 = new ResXResourceReader(resxFilePath))
|
|
{
|
|
{
|
|
- foreach (DictionaryEntry entry in reader)
|
|
|
|
|
|
+ foreach (DictionaryEntry entry in reader1)
|
|
{
|
|
{
|
|
string resourceName = entry.Key.ToString();
|
|
string resourceName = entry.Key.ToString();
|
|
string resourceValue = entry.Value.ToString();
|
|
string resourceValue = entry.Value.ToString();
|
|
@@ -919,22 +920,6 @@ background-position: right top;
|
|
Tag = resourceValue
|
|
Tag = resourceValue
|
|
};
|
|
};
|
|
menuItem.Click += MenuItem_Click;
|
|
menuItem.Click += MenuItem_Click;
|
|
- string iconResxFilePath = "favoritesMenuItemIcon.resx";
|
|
|
|
- using (ResXResourceReader iconReader = new ResXResourceReader(iconResxFilePath))
|
|
|
|
- {
|
|
|
|
- foreach (DictionaryEntry iconEntry in iconReader)
|
|
|
|
- {
|
|
|
|
- if (iconEntry.Key.ToString() == resourceName)
|
|
|
|
- {
|
|
|
|
- using (MemoryStream ms = new MemoryStream(iconData))
|
|
|
|
- {
|
|
|
|
- Image iconImage = Image.FromStream(ms);
|
|
|
|
- menuItem.Image = iconImage;
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
收藏夹AToolStripMenuItem.DropDownItems.Add(menuItem);
|
|
收藏夹AToolStripMenuItem.DropDownItems.Add(menuItem);
|
|
}
|
|
}
|
|
}
|
|
}
|