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, }))