The main idea is to use a userscript to send data to a WebSocket server (written in Python) hosted on the local machine.
- Scrape content from a page and send it to the WebSocket server to be stored in a
.txt
file - Compare dates found in an HTML table with data from an SQL database
- Update elements dynamically
Recommended: ViolentMonkey
- Firefox: ViolentMonkey for Firefox
- Chrome: ViolentMonkey for Chrome
Other Managers: TamperMonkey, Greasemonkey
To simplify message handling, Python uses Pydantic to define JSON formats and dispatch actions correctly.
A general wrapper model is defined in the code as follows:
class MessageModel(BaseModel):
content: TextModel | SaveToFileModel | ButtonModel
date: str
class SaveToFileModel(BaseModel):
filename: str
content: str
To activate the "save to file" function, send a message in this format:
{
"content": {
"filename": "mytext.txt",
"content" : "file content"
},
"date" : "YYYY-MM-DDTHH:mm:ssZ"
}
You can use your favorite editor to modify your userscript.
Guide: https://violentmonkey.github.io/posts/how-to-edit-scripts-with-your-favorite-editor/
- Create a local HTTP server and access your
websocket.user.js
script via the browser:
python -m http.server 8080
- Open the browser at:
http://localhost:8080/websocket.user.js
-
Use
Ctrl+Enter
to start or stop tracking changes to the file. -
Edit
websocket.user.js
using your preferred IDE.
Python: websockets
https://websockets.readthedocs.io/en/stable/
Javascript: websockets API
https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API
This project is in the worldwide public domain.
This project is in the public domain and copyright and related rights in the work worldwide are waived through the CC0 1.0 Universal public domain dedication.
All contributions to this project will be released under the CC0 dedication. By submitting a pull request, you are agreeing to comply with this waiver of copyright interest.