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 | class RoadbookUpdater { |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | #travelNotesHtmlElement; |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | #showTravelNotes; |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | #showRouteNotes; |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | #showManeuversNotes; |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | #showSmallNotes; |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | #showProfiles; |
74 | |
75 | |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | #toggleNotes ( selector, show ) { |
82 | document.querySelectorAll ( selector ).forEach ( |
83 | note => { |
84 | if ( show ) { |
85 | note.classList.remove ( 'TravelNotes-Hidden' ); |
86 | } |
87 | else { |
88 | note.classList.add ( 'TravelNotes-Hidden' ); |
89 | } |
90 | } |
91 | ); |
92 | } |
93 | |
94 | |
95 | |
96 | |
97 | |
98 | |
99 | #toggleProfiles ( show ) { |
100 | document.querySelectorAll ( '.TravelNotes-Roadbook-RouteProfile' ).forEach ( |
101 | profile => { |
102 | if ( show ) { |
103 | profile.classList.remove ( 'TravelNotes-Hidden' ); |
104 | } |
105 | else { |
106 | profile.classList.add ( 'TravelNotes-Hidden' ); |
107 | } |
108 | } |
109 | ); |
110 | } |
111 | |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | #toggleSmallNotes ( small ) { |
118 | if ( small ) { |
119 | this.#travelNotesHtmlElement.classList.add ( 'TravelNotes-SmallNotes' ); |
120 | this.#travelNotesHtmlElement.classList.remove ( 'TravelNotes-BigNotes' ); |
121 | } |
122 | else { |
123 | this.#travelNotesHtmlElement.classList.add ( 'TravelNotes-BigNotes' ); |
124 | this.#travelNotesHtmlElement.classList.remove ( 'TravelNotes-SmallNotes' ); |
125 | } |
126 | document.querySelectorAll ( |
127 | '.TravelNotes-Roadbook-Travel-Notes-IconCell, .TravelNotes-Roadbook-Route-ManeuversAndNotes-IconCell' |
128 | ).forEach ( |
129 | icon => { |
130 | icon.style.width = small ? '6cm' : icon.dataset.tanWidth; |
131 | icon.style.height = small ? '6cm' : icon.dataset.tanHeight; |
132 | } |
133 | ); |
134 | } |
135 | |
136 | |
137 | |
138 | |
139 | |
140 | constructor ( ) { |
141 | Object.freeze ( this ); |
142 | this.#travelNotesHtmlElement = document.getElementById ( 'TravelNotes' ); |
143 | this.#showTravelNotes = true; |
144 | this.#showRouteNotes = true; |
145 | this.#showManeuversNotes = false; |
146 | this.#showSmallNotes = false; |
147 | this.#showProfiles = true; |
148 | } |
149 | |
150 | |
151 | |
152 | |
153 | |
154 | |
155 | get showTravelNotes ( ) { return this.#showTravelNotes; } |
156 | set showTravelNotes ( show ) { |
157 | this.#showTravelNotes = show; |
158 | this.#toggleNotes ( '.TravelNotes-Roadbook-Travel-Notes-Row', show ); |
159 | } |
160 | |
161 | |
162 | |
163 | |
164 | |
165 | |
166 | get showRouteNotes ( ) { return this.#showRouteNotes; } |
167 | set showRouteNotes ( show ) { |
168 | this.#showRouteNotes = show; |
169 | this.#toggleNotes ( '.TravelNotes-Roadbook-Route-Notes-Row', show ); |
170 | } |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | |
177 | get showManeuversNotes ( ) { return this.#showManeuversNotes; } |
178 | set showManeuversNotes ( show ) { |
179 | this.#showManeuversNotes = show; |
180 | this.#toggleNotes ( '.TravelNotes-Roadbook-Route-Maneuvers-Row', show ); |
181 | } |
182 | |
183 | |
184 | |
185 | |
186 | |
187 | |
188 | get showSmallNotes ( ) { return this.#showSmallNotes; } |
189 | set showSmallNotes ( small ) { |
190 | this.#showSmallNotes = small; |
191 | this.#toggleSmallNotes ( small ); |
192 | } |
193 | |
194 | |
195 | |
196 | |
197 | |
198 | |
199 | get showProfiles ( ) { return this.#showProfiles; } |
200 | set showProfiles ( show ) { |
201 | this.#showProfiles = show; |
202 | this.#toggleProfiles ( show ); |
203 | } |
204 | |
205 | |
206 | |
207 | |
208 | |
209 | updateNotesAndProfiles ( ) { |
210 | this.showTravelNotes = this.#showTravelNotes; |
211 | this.showRouteNotes = this.#showRouteNotes; |
212 | this.showManeuversNotes = this.#showManeuversNotes; |
213 | this.showSmallNotes = this.#showSmallNotes; |
214 | |
215 | this.showProfiles = this.#showProfiles; |
216 | } |
217 | |
218 | |
219 | |
220 | |
221 | |
222 | |
223 | updateRoadbook ( pageContent ) { |
224 | this.#travelNotesHtmlElement.innerHTML = pageContent; |
225 | const headerName = document.querySelector ( '.TravelNotes-Roadbook-Travel-Header-Name' ); |
226 | if ( headerName ) { |
227 | document.title = |
228 | '' === headerName.textContent ? 'roadbook' : headerName.textContent + ' - roadbook'; |
229 | } |
230 | |
231 | |
232 | document.querySelectorAll ( |
233 | '.TravelNotes-Roadbook-Travel-Notes-IconCell, .TravelNotes-Roadbook-Route-ManeuversAndNotes-IconCell' |
234 | ).forEach ( |
235 | icon => { |
236 | icon.style.width = icon.dataset.tanWidth; |
237 | icon.style.height = icon.dataset.tanHeight; |
238 | } |
239 | ); |
240 | |
241 | this.updateNotesAndProfiles ( ); |
242 | } |
243 | |
244 | } |
245 | |
246 | |
247 | |
248 | |
249 | |
250 | |
251 | |
252 | |
253 | const theRoadbookUpdater = new RoadbookUpdater ( ); |
254 | |
255 | export default theRoadbookUpdater; |
256 | |
257 | |
258 | |