mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 20:27:36 +02:00
Add bookmarks support for Chromium / ChromeSxS and multiple profiles
This commit is contained in:
@@ -55,51 +55,68 @@ namespace Wox.Plugin.System
|
|||||||
{
|
{
|
||||||
bookmarks.Clear();
|
bookmarks.Clear();
|
||||||
LoadChromeBookmarks();
|
LoadChromeBookmarks();
|
||||||
|
|
||||||
bookmarks = bookmarks.Distinct().ToList();
|
bookmarks = bookmarks.Distinct().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ParseChromeBookmarks(String path, string source)
|
||||||
|
{
|
||||||
|
if (!File.Exists(path)) return;
|
||||||
|
|
||||||
|
string all = File.ReadAllText(path);
|
||||||
|
Regex nameRegex = new Regex("\"name\": \"(?<name>.*?)\"");
|
||||||
|
MatchCollection nameCollection = nameRegex.Matches(all);
|
||||||
|
Regex typeRegex = new Regex("\"type\": \"(?<type>.*?)\"");
|
||||||
|
MatchCollection typeCollection = typeRegex.Matches(all);
|
||||||
|
Regex urlRegex = new Regex("\"url\": \"(?<url>.*?)\"");
|
||||||
|
MatchCollection urlCollection = urlRegex.Matches(all);
|
||||||
|
|
||||||
|
List<string> names = (from Match match in nameCollection select match.Groups["name"].Value).ToList();
|
||||||
|
List<string> types = (from Match match in typeCollection select match.Groups["type"].Value).ToList();
|
||||||
|
List<string> urls = (from Match match in urlCollection select match.Groups["url"].Value).ToList();
|
||||||
|
|
||||||
|
int urlIndex = 0;
|
||||||
|
for (int i = 0; i < names.Count; i++)
|
||||||
|
{
|
||||||
|
string name = DecodeUnicode(names[i]);
|
||||||
|
string type = types[i];
|
||||||
|
if (type == "url")
|
||||||
|
{
|
||||||
|
string url = urls[urlIndex];
|
||||||
|
urlIndex++;
|
||||||
|
|
||||||
|
if (url == null) continue;
|
||||||
|
if (url.StartsWith("javascript:", StringComparison.OrdinalIgnoreCase)) continue;
|
||||||
|
if (url.StartsWith("vbscript:", StringComparison.OrdinalIgnoreCase)) continue;
|
||||||
|
|
||||||
|
bookmarks.Add(new Bookmark()
|
||||||
|
{
|
||||||
|
Name = name,
|
||||||
|
Url = url,
|
||||||
|
Source = source
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadChromeBookmarks(string path, string name)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(path)) return;
|
||||||
|
var paths = Directory.GetDirectories(path);
|
||||||
|
|
||||||
|
foreach (var profile in paths)
|
||||||
|
{
|
||||||
|
if (File.Exists(Path.Combine(profile, "Bookmarks")))
|
||||||
|
ParseChromeBookmarks(Path.Combine(profile, "Bookmarks"), name + (Path.GetFileName(profile) == "Default" ? "" : (" (" + Path.GetFileName(profile) + ")")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void LoadChromeBookmarks()
|
private void LoadChromeBookmarks()
|
||||||
{
|
{
|
||||||
String platformPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
String platformPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||||
string path = global::System.IO.Path.Combine(platformPath, @"Google\Chrome\User Data\Default\Bookmarks");
|
LoadChromeBookmarks(Path.Combine(platformPath, @"Google\Chrome\User Data"), "Google Chrome");
|
||||||
|
LoadChromeBookmarks(Path.Combine(platformPath, @"Google\Chrome SxS\User Data"), "Google Chrome Canary");
|
||||||
if (File.Exists(path))
|
LoadChromeBookmarks(Path.Combine(platformPath, @"Chromium\User Data"), "Chromium");
|
||||||
{
|
|
||||||
string all = File.ReadAllText(path);
|
|
||||||
Regex nameRegex = new Regex("\"name\": \"(?<name>.*?)\"");
|
|
||||||
MatchCollection nameCollection = nameRegex.Matches(all);
|
|
||||||
Regex typeRegex = new Regex("\"type\": \"(?<type>.*?)\"");
|
|
||||||
MatchCollection typeCollection = typeRegex.Matches(all);
|
|
||||||
Regex urlRegex = new Regex("\"url\": \"(?<url>.*?)\"");
|
|
||||||
MatchCollection urlCollection = urlRegex.Matches(all);
|
|
||||||
|
|
||||||
List<string> names = (from Match match in nameCollection select match.Groups["name"].Value).ToList();
|
|
||||||
List<string> types = (from Match match in typeCollection select match.Groups["type"].Value).ToList();
|
|
||||||
List<string> urls = (from Match match in urlCollection select match.Groups["url"].Value).ToList();
|
|
||||||
|
|
||||||
int urlIndex = 0;
|
|
||||||
for (int i = 0; i < names.Count; i++)
|
|
||||||
{
|
|
||||||
string name = DecodeUnicode(names[i]);
|
|
||||||
string type = types[i];
|
|
||||||
if (type == "url")
|
|
||||||
{
|
|
||||||
string url = urls[urlIndex];
|
|
||||||
urlIndex++;
|
|
||||||
|
|
||||||
if (url == null) continue;
|
|
||||||
if (url.StartsWith("javascript:", StringComparison.OrdinalIgnoreCase)) continue;
|
|
||||||
if (url.StartsWith("vbscript:", StringComparison.OrdinalIgnoreCase)) continue;
|
|
||||||
|
|
||||||
bookmarks.Add(new Bookmark()
|
|
||||||
{
|
|
||||||
Name = name,
|
|
||||||
Url = url,
|
|
||||||
Source = "Chrome"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String DecodeUnicode(String dataStr)
|
private String DecodeUnicode(String dataStr)
|
||||||
|
|||||||
Reference in New Issue
Block a user