-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_userscript
executable file
·42 lines (34 loc) · 1 KB
/
build_userscript
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
#!/usr/bin/env python3
import json
import re
with open('userscript.meta.js.tmpl') as f:
meta_src = f.read()
with open('userscript.js.tmpl') as f:
src = f.read()
# Version
with open('src/manifest.json') as f:
version = json.loads(f.read())['version']
meta_src = meta_src.replace('%%VERSION%%', version)
# JavaScript
lines = []
with open('src/bylines.js') as f:
for line in f.readlines():
lines.append('\t' + line)
src = src.replace('%%JS%%', ''.join(lines))
# CSS
lines = []
with open('src/style.css') as f:
block = ''
for line in f.readlines():
block += line.strip()
if re.match('}\s*\n', line):
lines.append("GM_addStyle('" + block + "');\n\t\t")
block = ''
continue
lines.append("GM_addStyle('" + block + "');\n\t\t")
src = src.replace('%%CSS%%', ''.join(lines))
# Write to disk
with open('userscript.meta.js', 'w') as f:
f.write(meta_src)
with open('userscript.js', 'w') as f:
f.write(meta_src + "\n\n" + src)