-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import re | ||
import time | ||
import pyperclip | ||
import pystray | ||
from pystray import Icon, Menu, MenuItem | ||
from PIL import Image | ||
import pystray._win32 | ||
import threading | ||
from notifypy import Notify | ||
|
||
def repl(match: re.Match): | ||
return "https://hichennyang.github.io/zotero-link/#{}".format(match.group()) | ||
|
||
def main(): | ||
notification = Notify( | ||
default_notification_application_name = "zotero-link", | ||
default_notification_icon = "Link2Zotero_2.png" | ||
) | ||
# pattern = r"zotero://\S*\)\)" | ||
pattern = r'(?<!#)(zotero://[^\s]+)' | ||
pre_past = "" | ||
|
||
while True: | ||
string = pyperclip.paste() | ||
if pre_past != string: | ||
if re.match(".*"+pattern, string): | ||
string = re.sub(pattern, repl, string) | ||
pyperclip.copy(string) | ||
notification.title = "" | ||
notification.message = "替换完毕" | ||
notification.send() | ||
|
||
pre_past = string | ||
time.sleep(0.5) | ||
|
||
def quit(icon: pystray._win32.Icon) -> None: | ||
icon.stop() | ||
|
||
def setup(icon: pystray._win32.Icon) -> None: | ||
icon.visible = True | ||
threading.Thread(target=main, daemon=True).start() | ||
|
||
if __name__ == "__main__": | ||
Icon( | ||
"zotero-link", | ||
icon = Image.open("Link2Zotero_2.png"), | ||
title = "zotero-link", | ||
menu = Menu( | ||
MenuItem("退出", quit) | ||
) | ||
).run(setup) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
|
||
|
||
## 介绍 | ||
|
||
|
||
|
||
## 手动编译方法 | ||
```bash | ||
cd path/to/Link2Zotero | ||
pyinstaller --onefile --icon=Link2Zotero_2.ico --noconsole .\CopyReplace\main.py | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters