-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathyaml_editor.py
More file actions
64 lines (56 loc) · 2.17 KB
/
yaml_editor.py
File metadata and controls
64 lines (56 loc) · 2.17 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
import os, re, sys
r = re.compile("<script defer>(.*?)</script>", re.DOTALL)
r_pomo = re.compile("\" *<script defer>(.*?)</script>", re.DOTALL, )
top = sys.argv[1]
for root, _, files in os.walk(top, topdown=True, onerror=None, followlinks=False):
for f in files:
if f == "task.yaml":
print(os.path.join(root, f))
with open(os.path.join(root, f), "r") as file:
str = file.read()
with open(os.path.join(root, f), "w") as file:
replaced = r.sub("""<script defer>
bodyHeight = 0;
function postSize() {
if (document.body.scrollHeight != bodyHeight) {
bodyHeight = document.body.scrollHeight;
window.parent.postMessage({height: document.body.scrollHeight}, "*");
}
};
var target = document.querySelector('body');
var observer = new MutationObserver(postSize);
var config = { attributes: true, subtree: true }
observer.observe(target, config);
$(document).ready(function(){
setTimeout(postSize, 0);
});
</script>""", str)
file.seek(0)
file.write(replaced)
elif f[-3:] == ".po":
print(os.path.join(root, f))
with open(os.path.join(root, f), "r") as file:
str = file.read()
with open(os.path.join(root, f), "w") as file:
replaced = r_pomo.sub("""" <script defer>\\\\n"
"\\\\n"
" bodyHeight = 0;\\\\n"
" function postSize() {\\\\n"
" if (document.body.scrollHeight != bodyHeight) {\\\\n"
" bodyHeight = document.body.scrollHeight;\\\\n"
" window.parent.postMessage({height: document.body.scrollHeight}, \\\\"*\\\\");\\\\n"
" }\\\\n"
" };\\\\n"
" var target = document.querySelector('body');\\\\n"
"\\\\n"
" var observer = new MutationObserver(postSize);\\\\n"
"\\\\n"
" var config = { attributes: true, subtree: true }\\\\n"
"\\\\n"
" observer.observe(target, config);\\\\n"
" $(document).ready(function(){\\\\n"
" setTimeout(postSize, 0);\\\\n"
" });\\\\n"
" </script>""", str)
file.seek(0)
file.write(replaced)