-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextmai-creator.py
More file actions
75 lines (65 loc) · 2.11 KB
/
extmai-creator.py
File metadata and controls
75 lines (65 loc) · 2.11 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# https://poe.com/s/etJ1yiSzy66HUJGw4tVC
# minor corrections applied
# manifest V3 compliance impossible unless userscript.js is the main script.
# currently userscript.js copies userscript functionality and loads script from external sources.
# this would involve author effort, or I need to copy the script from him to include here.
import os
import json
import shutil
import zipfile
from PIL import Image
# Create the extension directory
extension_dir = 'extension_creation'
os.makedirs(extension_dir, exist_ok=True)
# Copy the userscript.js file to the extension directory
shutil.copy('userscript.js', extension_dir)
# Scale and export the icons
icon_sizes = {
"16": (16, 16),
"32": (32, 32),
"48": (48, 48),
"128": (128, 128)
}
for size, dimensions in icon_sizes.items():
icon_path = 'apple-touch-icon.png'
icon = Image.open(icon_path)
icon = icon.resize(dimensions)
icon.save(os.path.join(extension_dir, f'icon{size}.png'))
# Create the manifest.json file
manifest_data = {
"name": "extmai tools",
"version": "2.0.2.0",
"manifest_version": 2,
"permissions": [
"activeTab"
],
"icons": {
"16": "icon16.png",
"32": "icon32.png",
"48": "icon48.png",
"128": "icon128.png"
},
"content_scripts": [
{
"matches": [
"https://maimaidx-eng.com/*", # "https://example.com/*"
"https://maimaidx.jp/*"
],
"js": [
"userscript.js"
]
}
]
}
manifest_path = os.path.join(extension_dir, 'manifest.json')
with open(manifest_path, 'w') as manifest_file:
json.dump(manifest_data, manifest_file, indent=2)
# Create a ZIP file of the extension directory
extension_zip = 'extension_creation.zip'
with zipfile.ZipFile(extension_zip, 'w') as zipf:
for root, dirs, files in os.walk(extension_dir):
for file in files:
file_path = os.path.join(root, file)
arcname = file_path.replace(extension_dir + os.sep, '')
zipf.write(file_path, arcname)
print(f"Extension packaged successfully as '{extension_zip}'.")