-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (52 loc) · 1.13 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"net/http"
"net/url"
"runtime"
"time"
"github.com/atotto/clipboard"
"github.com/getlantern/systray"
"github.com/mattn/go-ieproxy"
)
var (
previousUrl string // Avoid parsing it over and over again
)
func main() {
go func() {
for x := range time.Tick(time.Second) {
clipped, err := clipboard.ReadAll()
if err == nil && clipped != previousUrl {
u, invalidUrl := url.Parse(clipped)
if invalidUrl == nil && u.Host != "" {
// valid URL
fmt.Printf("[%s] Processing URL: %s\n", x, clipped)
previousUrl = processUrlItem(clipped)
clipboard.WriteAll(previousUrl)
}
}
}
}()
systray.Run(onReady, onExit)
}
func onReady() {
if runtime.GOOS == "windows" {
// Windows won't let us have emojis. :-(
systray.SetIcon(TrayIcon)
} else {
systray.SetTitle("🧹")
}
systray.SetTooltip("I'm cleaning URLs in the clipboard")
mQuitOrig := systray.AddMenuItem("Quit", "Quit cleaning URLs")
go func() {
<-mQuitOrig.ClickedCh
systray.Quit()
}()
}
func init() {
http.DefaultTransport.(*http.Transport).Proxy = ieproxy.GetProxyFunc()
}
func onExit() {
// Cleanup
// tbd
}