aboutsummaryrefslogtreecommitdiff
path: root/mkconfig.py
blob: 47cc0eee4e4b803d56ec35a2f7227bac46811e5d (plain)
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
import json
import os
import glob
import zipfile

# handle settings
settings = {}
if os.path.isfile("settings.json"):
    with open("settings.json", 'r') as f:
        settings = json.load(f)

# get all userscripts
paths = glob.glob(os.path.join('.', '**', '*.js'), recursive=True)
paths = [ path.removesuffix(".js") for path in paths ]

# zipp
with zipfile.ZipFile("violentmonkey.zip", 'w', zipfile.ZIP_DEFLATED) as zipf:
    for path in paths:
        arcname = os.path.basename(path) + ".user.js"  # basename and add .user.js suffix
        path += ".js"
        zipf.write(path, arcname=arcname)
    zipf.writestr("violentmonkey", json.dumps({
        "scripts": { os.path.basename(path): {} for path in paths },
        "settings": settings,
    }))