Skip to content

Commit 14713ee

Browse files
committed
fix
1 parent f2ba65d commit 14713ee

2 files changed

Lines changed: 43 additions & 16 deletions

File tree

generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@
7272
meta_data = search_js(parsed_script_list, ";window.__META_DATA__=")[0].after
7373
meta_output = json.loads(json_parser(meta_data))
7474

75-
script_load_data = search_js_reg(parsed_script_list, "Promise.all")[0].after
75+
script_load_data = search_js_reg(parsed_script_list, "ondemand.s")[0].parent
7676
script_load_json = json.loads(json_parser(script_load_data))
7777

7878

79-
script_key_data = search_js_reg(parsed_script_list, "a.js")[1].before
79+
script_key_data = script_load_data.parent.children[script_load_data.key + 2]
8080
script_key_json = json.loads(json_parser(script_key_data))
8181

8282
script_load_output = {}

lib/js_parser/js_parser.py

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def parser(self, init=True):
1919
value = ""
2020
output.children.append(self.parser(init=False))
2121
output.children[-1].parent = output
22-
output.children[-1].before = output.children[-2]
22+
output.children[-1].key = len(output.children) - 1
2323
elif char == "}":
2424
if value != "":
2525
output.children.append(value)
@@ -38,8 +38,26 @@ class JsData:
3838
def __init__(self):
3939
self.children: list = []
4040
self.parent: JsData = None
41-
self.after = None
42-
self.before = None
41+
self.key = None
42+
43+
44+
@property
45+
def before(self):
46+
if self.parent is None:
47+
return None
48+
if self.key > 0:
49+
return self.parent.children[self.key - 1]
50+
return None
51+
52+
@property
53+
def after(self):
54+
if self.parent is None:
55+
return None
56+
if self.key < len(self.parent.children) - 1:
57+
return self.parent.children[self.key + 1]
58+
return None
59+
60+
4361

4462
def __repr__(self):
4563
return json.dumps(self.to_list())
@@ -58,10 +76,25 @@ class JsSearchData:
5876
def __init__(self):
5977
self.children: list = []
6078
self.parent: JsData = None
61-
self.after = None
62-
self.before = None
6379
self.data = None
64-
80+
self.key = None
81+
82+
@property
83+
def before(self):
84+
if self.parent is None:
85+
return None
86+
if self.key > 0:
87+
return self.parent.children[self.key - 1]
88+
return None
89+
90+
@property
91+
def after(self):
92+
if self.parent is None:
93+
return None
94+
if self.key < len(self.parent.children) - 1:
95+
return self.parent.children[self.key + 1]
96+
return None
97+
6598
def __repr__(self):
6699
return json.dumps(self.children)
67100

@@ -86,11 +119,8 @@ def search_js(text: JsData, search: str) -> list[JsSearchData]:
86119
output.append(JsSearchData())
87120
output[-1].children = text.children
88121
output[-1].parent = text
89-
if len(text.children) > key + 1:
90-
output[-1].after = text.children[key + 1]
91-
if len(text.children) > 0:
92-
output[-1].before = text.children[key - 1]
93122
output[-1].data = search
123+
output[-1].key = key
94124
break
95125
return output
96126

@@ -108,11 +138,8 @@ def search_js_reg(text: JsData, search: str) -> list[JsSearchData]:
108138
output.append(JsSearchData())
109139
output[-1].children = text.children[key]
110140
output[-1].parent = text
111-
if len(text.children) > key + 1:
112-
output[-1].after = text.children[key + 1]
113-
if len(text.children) > 0:
114-
output[-1].before = text.children[key - 1]
115141
output[-1].data = find
142+
output[-1].key = key
116143
break
117144
return output
118145

0 commit comments

Comments
 (0)