Skip to content

Commit

Permalink
copy bookmark
Browse files Browse the repository at this point in the history
  • Loading branch information
moqsien committed May 4, 2023
1 parent 46cd730 commit 61e1c9e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type Browser interface {
Name() string
// Customize items to save.
OnlyToSave(toSave []item.Item)
// Copy bookmarks
CopyBookmark() (string, error)
// BrowsingData returns all browsing data in the browser.
BrowsingData(isFullExport bool) (*browingdata.Data, error)
}
Expand Down
32 changes: 32 additions & 0 deletions browser/chromium/chromium.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"github.com/moqsien/hackbrowser/utils/typeutil"
)

const (
chromium = "chromium"
)

type Chromium struct {
name string
storage string
Expand Down Expand Up @@ -87,6 +91,34 @@ func (c *Chromium) BrowsingData(isFullExport bool) (*browingdata.Data, error) {
return data, nil
}

func (c *Chromium) CopyBookmark() (browserType string, err error) {
browserType = chromium
for i, path := range c.itemPaths {
filename := i.String()
if filename != item.TempChromiumBookmark {
continue
}
switch {
case fileutil.IsDirExists(path):
if i == item.ChromiumLocalStorage {
err = fileutil.CopyDir(path, filename, "lock")
}
if i == item.ChromiumSessionStorage {
err = fileutil.CopyDir(path, filename, "lock")
}
if i == item.ChromiumExtension {
err = fileutil.CopyDirHasSuffix(path, filename, "manifest.json")
}
default:
err = fileutil.CopyFile(path, filename)
}
if err != nil {
return
}
}
return
}

func (c *Chromium) copyItemToLocal() error {
for i, path := range c.itemPaths {
filename := i.String()
Expand Down
18 changes: 18 additions & 0 deletions browser/firefox/firefox.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ func (f *Firefox) Name() string {
return f.name
}

const (
firefox = "firefox"
)

func (f *Firefox) CopyBookmark() (browserType string, err error) {
browserType = firefox
for i, path := range f.itemPaths {
filename := i.String()
if filename != item.TempFirefoxBookmark {
continue
}
if err = fileutil.CopyFile(path, filename); err != nil {
return
}
}
return
}

func (f *Firefox) OnlyToSave(toSave []item.Item) {
newItems := []item.Item{}
for _, itm := range f.items {
Expand Down

0 comments on commit 61e1c9e

Please sign in to comment.