|
1 | | -import { full } from 'acorn-walk'; |
2 | | -import { type Node as AcornNode, parse } from 'acorn'; |
3 | | - |
4 | | -import type { BuildingMarkerAdd } from 'typings/Ingame'; |
5 | 1 | import type { RedesignParser } from 'typings/modules/Redesign'; |
6 | 2 |
|
7 | | -type Building = BuildingMarkerAdd; |
| 3 | +interface Building { |
| 4 | + id: number; |
| 5 | + user_id: number; |
| 6 | + name: string; |
| 7 | + longitude: number; |
| 8 | + latitude: number; |
| 9 | + icon: string; |
| 10 | + icon_other: string; |
| 11 | + lbid: number; |
| 12 | + show_vehicles_at_startpage: boolean; |
| 13 | + level: number; |
| 14 | + personal_count: number; |
| 15 | + building_type: number; |
| 16 | + filter_id: string; |
| 17 | + detail_button: string; |
| 18 | +} |
8 | 19 |
|
9 | 20 | interface Award { |
10 | 21 | caption: string; |
@@ -35,26 +46,11 @@ export interface ProfileWindow { |
35 | 46 | alliance_ignored: boolean; |
36 | 47 | } |
37 | 48 |
|
38 | | -interface CallExpressionNode extends AcornNode { |
39 | | - expression: { |
40 | | - type: 'CallExpression'; |
41 | | - callee: AcornNode & { name: string }; |
42 | | - arguments: (AcornNode & { |
43 | | - properties: (AcornNode & { |
44 | | - key: { value: string }; |
45 | | - value: |
46 | | - | { |
47 | | - type: 'UnaryExpression'; |
48 | | - operator: string; |
49 | | - argument: AcornNode & { value: number }; |
50 | | - } |
51 | | - | { type: 'Literal'; value: number | string }; |
52 | | - })[]; |
53 | | - })[]; |
54 | | - }; |
55 | | -} |
56 | | - |
57 | | -export default <RedesignParser<ProfileWindow>>(({ LSSM, doc, href = '' }) => { |
| 49 | +export default <RedesignParser<ProfileWindow>>(async ({ |
| 50 | + LSSM, |
| 51 | + doc, |
| 52 | + href = '', |
| 53 | +}) => { |
58 | 54 | const id = parseInt( |
59 | 55 | new URL(href, window.location.origin).pathname.match( |
60 | 56 | /\d+(?=\/?$)/u |
@@ -124,45 +120,10 @@ export default <RedesignParser<ProfileWindow>>(({ LSSM, doc, href = '' }) => { |
124 | 120 | ?.textContent?.trim() ?? '', |
125 | 121 | })), |
126 | 122 | has_map: !!doc.querySelector<HTMLDivElement>('#profile_map'), |
127 | | - buildings: Array.from(doc.scripts) |
128 | | - .filter(script => |
129 | | - script.textContent?.includes('buildingMarkerAddSingle') |
130 | | - ) |
131 | | - .flatMap(script => { |
132 | | - const tree = parse(script.textContent ?? '', { |
133 | | - ecmaVersion: 'latest', |
134 | | - }); |
135 | | - |
136 | | - const markerNodes: CallExpressionNode[] = []; |
137 | | - full( |
138 | | - tree, |
139 | | - (node: AcornNode | CallExpressionNode) => |
140 | | - node.type === 'ExpressionStatement' && |
141 | | - 'expression' in node && |
142 | | - node.expression.type === 'CallExpression' && |
143 | | - node.expression.callee.type === 'Identifier' && |
144 | | - node.expression.callee.name === |
145 | | - 'buildingMarkerAddSingle' && |
146 | | - markerNodes.push(node) |
147 | | - ); |
148 | | - |
149 | | - return markerNodes.map( |
150 | | - node => |
151 | | - Object.fromEntries( |
152 | | - node.expression.arguments[0].properties.map( |
153 | | - prop => [ |
154 | | - prop.key.value, |
155 | | - prop.value.type === 'UnaryExpression' |
156 | | - ? parseFloat( |
157 | | - prop.value.operator + |
158 | | - prop.value.argument.value |
159 | | - ) |
160 | | - : prop.value.value, |
161 | | - ] |
162 | | - ) |
163 | | - ) as unknown as Building |
164 | | - ); |
165 | | - }), |
| 123 | + buildings: await fetch(`/building/buildings_json?user_to_load_id=${id}`) |
| 124 | + .then(res => res.json()) |
| 125 | + .then<Building[]>(p => p.buildings ?? []) |
| 126 | + .then(b => b.filter(({user_id}) => user_id === id)), |
166 | 127 | ignored: !!doc.querySelector<HTMLAnchorElement>( |
167 | 128 | 'a[href^="/ignoriert/entfernen/"]' |
168 | 129 | ), |
|
0 commit comments