Skip to content

Commit 1e66205

Browse files
authored
merge PR #121: index Edge browser bookmarks
2 parents 19aa9ca + 163bf64 commit 1e66205

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/Bookmarks.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ internal static List<Bookmark> LoadAllBookmarks()
2121

2222
var chromeBookmarks = new ChromeBookmarks();
2323
var mozBookmarks = new FirefoxBookmarks();
24+
var edgeBookmarks = new EdgeBookmarks();
2425

2526
//TODO: Let the user select which browser's bookmarks are displayed
2627
// Add Firefox bookmarks
@@ -29,6 +30,9 @@ internal static List<Bookmark> LoadAllBookmarks()
2930
// Add Chrome bookmarks
3031
chromeBookmarks.GetBookmarks().ForEach(x => allbookmarks.Add(x));
3132

33+
// Add Edge (Chromium) bookmarks
34+
edgeBookmarks.GetBookmarks().ForEach(x => allbookmarks.Add(x));
35+
3236
return allbookmarks.Distinct().ToList();
3337
}
3438
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text.RegularExpressions;
6+
7+
namespace Flow.Launcher.Plugin.BrowserBookmark
8+
{
9+
public class EdgeBookmarks
10+
{
11+
private List<Bookmark> bookmarks = new List<Bookmark>();
12+
13+
public List<Bookmark> GetBookmarks()
14+
{
15+
bookmarks.Clear();
16+
LoadEdgeBookmarks();
17+
18+
return bookmarks;
19+
}
20+
21+
private void ParseEdgeBookmarks(String path, string source)
22+
{
23+
if (!File.Exists(path)) return;
24+
25+
string all = File.ReadAllText(path);
26+
Regex nameRegex = new Regex("\"name\": \"(?<name>.*?)\"");
27+
MatchCollection nameCollection = nameRegex.Matches(all);
28+
Regex typeRegex = new Regex("\"type\": \"(?<type>.*?)\"");
29+
MatchCollection typeCollection = typeRegex.Matches(all);
30+
Regex urlRegex = new Regex("\"url\": \"(?<url>.*?)\"");
31+
MatchCollection urlCollection = urlRegex.Matches(all);
32+
33+
List<string> names = (from Match match in nameCollection select match.Groups["name"].Value).ToList();
34+
List<string> types = (from Match match in typeCollection select match.Groups["type"].Value).ToList();
35+
List<string> urls = (from Match match in urlCollection select match.Groups["url"].Value).ToList();
36+
37+
int urlIndex = 0;
38+
for (int i = 0; i < names.Count; i++)
39+
{
40+
string name = DecodeUnicode(names[i]);
41+
string type = types[i];
42+
if (type == "url")
43+
{
44+
string url = urls[urlIndex];
45+
urlIndex++;
46+
47+
if (url == null) continue;
48+
if (url.StartsWith("javascript:", StringComparison.OrdinalIgnoreCase)) continue;
49+
if (url.StartsWith("vbscript:", StringComparison.OrdinalIgnoreCase)) continue;
50+
51+
bookmarks.Add(new Bookmark()
52+
{
53+
Name = name,
54+
Url = url,
55+
Source = source
56+
});
57+
}
58+
}
59+
}
60+
61+
private void LoadEdgeBookmarks(string path, string name)
62+
{
63+
if (!Directory.Exists(path)) return;
64+
var paths = Directory.GetDirectories(path);
65+
66+
foreach (var profile in paths)
67+
{
68+
if (File.Exists(Path.Combine(profile, "Bookmarks")))
69+
ParseEdgeBookmarks(Path.Combine(profile, "Bookmarks"), name + (Path.GetFileName(profile) == "Default" ? "" : (" (" + Path.GetFileName(profile) + ")")));
70+
}
71+
}
72+
73+
private void LoadEdgeBookmarks()
74+
{
75+
String platformPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
76+
LoadEdgeBookmarks(Path.Combine(platformPath, @"Microsoft\Edge\User Data"), "Microsoft Edge");
77+
LoadEdgeBookmarks(Path.Combine(platformPath, @"Microsoft\Edge SxS\User Data"), "Microsoft Edge Canary");
78+
}
79+
80+
private String DecodeUnicode(String dataStr)
81+
{
82+
Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");
83+
return reg.Replace(dataStr, m => ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString());
84+
}
85+
}
86+
}

Plugins/Flow.Launcher.Plugin.BrowserBookmark/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Name": "Browser Bookmarks",
55
"Description": "Search your browser bookmarks",
66
"Author": "qianlifeng, Ioannis G.",
7-
"Version": "1.1",
7+
"Version": "1.2.0",
88
"Language": "csharp",
99
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
1010
"ExecuteFileName": "Flow.Launcher.Plugin.browserBookmark.dll",

0 commit comments

Comments
 (0)