single-file-core 1.1.76 → 1.1.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +0 -0
- package/LICENSE +0 -0
- package/core/constants.js +13 -0
- package/core/helper.js +604 -596
- package/core/index.js +2234 -2231
- package/core/infobar.js +276 -272
- package/core/util.js +408 -407
- package/modules/css-fonts-alt-minifier.js +342 -342
- package/modules/css-fonts-minifier.js +376 -376
- package/modules/css-matched-rules.js +0 -0
- package/modules/css-medias-alt-minifier.js +90 -90
- package/modules/css-rules-minifier.js +0 -0
- package/modules/html-images-alt-minifier.js +0 -0
- package/modules/html-minifier.js +0 -0
- package/modules/html-serializer.js +0 -0
- package/modules/index.js +0 -0
- package/modules/template-formatter.js +0 -0
- package/package.json +18 -18
- package/processors/frame-tree/content/content-frame-tree.js +426 -424
- package/processors/hooks/content/content-hooks-frames-web.js +0 -0
- package/processors/hooks/content/content-hooks-frames.js +0 -0
- package/processors/index.js +0 -0
- package/processors/lazy/content/content-lazy-loader.js +233 -233
- package/single-file-bootstrap.js +55 -55
- package/single-file-editor-helper.js +49 -49
- package/single-file-frames.js +0 -0
- package/single-file-hooks-frames.js +0 -0
- package/single-file-infobar.js +62 -62
- package/single-file.js +101 -101
- package/vendor/css-font-property-parser.js +0 -0
- package/vendor/css-media-query-parser.js +0 -0
- package/vendor/css-minifier.js +0 -0
- package/vendor/css-tree.js +0 -0
- package/vendor/css-unescape.js +0 -0
- package/vendor/html-srcset-parser.js +0 -0
- package/vendor/index.js +0 -0
- package/vendor/mime-type-parser.js +0 -0
package/core/infobar.js
CHANGED
|
@@ -1,273 +1,277 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2010-2022 Gildas Lormeau
|
|
3
|
-
* contact : gildas.lormeau <at> gmail.com
|
|
4
|
-
*
|
|
5
|
-
* This file is part of SingleFile.
|
|
6
|
-
*
|
|
7
|
-
* The code in this file is free software: you can redistribute it and/or
|
|
8
|
-
* modify it under the terms of the GNU Affero General Public License
|
|
9
|
-
* (GNU AGPL) as published by the Free Software Foundation, either version 3
|
|
10
|
-
* of the License, or (at your option) any later version.
|
|
11
|
-
*
|
|
12
|
-
* The code in this file is distributed in the hope that it will be useful,
|
|
13
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
|
|
15
|
-
* General Public License for more details.
|
|
16
|
-
*
|
|
17
|
-
* As additional permission under GNU AGPL version 3 section 7, you may
|
|
18
|
-
* distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
|
|
19
|
-
* AGPL normally required by section 4, provided you include this license
|
|
20
|
-
* notice and a URL through which recipients can access the Corresponding
|
|
21
|
-
* Source.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/* global getComputedStyle, XPathResult, Node */
|
|
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
|
-
.infobar
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
.infobar {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
.infobar:focus-within {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
.infobar-content
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
.infobar .infobar-icon {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
background-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
infobarElement.
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
closeButtonElement
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
linkElement
|
|
195
|
-
linkElement.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
scriptElement
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2010-2022 Gildas Lormeau
|
|
3
|
+
* contact : gildas.lormeau <at> gmail.com
|
|
4
|
+
*
|
|
5
|
+
* This file is part of SingleFile.
|
|
6
|
+
*
|
|
7
|
+
* The code in this file is free software: you can redistribute it and/or
|
|
8
|
+
* modify it under the terms of the GNU Affero General Public License
|
|
9
|
+
* (GNU AGPL) as published by the Free Software Foundation, either version 3
|
|
10
|
+
* of the License, or (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* The code in this file is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
|
|
15
|
+
* General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* As additional permission under GNU AGPL version 3 section 7, you may
|
|
18
|
+
* distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
|
|
19
|
+
* AGPL normally required by section 4, provided you include this license
|
|
20
|
+
* notice and a URL through which recipients can access the Corresponding
|
|
21
|
+
* Source.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/* global getComputedStyle, XPathResult, Node */
|
|
25
|
+
|
|
26
|
+
import {
|
|
27
|
+
SINGLE_FILE_SIGNATURE,
|
|
28
|
+
} from "./constants.js";
|
|
29
|
+
|
|
30
|
+
const INFOBAR_TAGNAME = "single-file-infobar";
|
|
31
|
+
const INFOBAR_STYLES = `
|
|
32
|
+
.infobar,
|
|
33
|
+
.infobar .infobar-icon,
|
|
34
|
+
.infobar .infobar-link-icon {
|
|
35
|
+
min-inline-size: 28px;
|
|
36
|
+
min-block-size: 28px;
|
|
37
|
+
box-sizing: border-box;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.infobar,
|
|
41
|
+
.infobar .infobar-close-icon,
|
|
42
|
+
.infobar .infobar-link-icon {
|
|
43
|
+
opacity: 0.7;
|
|
44
|
+
transition: opacity 250ms;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.infobar:hover,
|
|
48
|
+
.infobar .infobar-close-icon:hover,
|
|
49
|
+
.infobar .infobar-link-icon:hover {
|
|
50
|
+
opacity: 1;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.infobar,
|
|
54
|
+
.infobar-content {
|
|
55
|
+
display: flex;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.infobar {
|
|
59
|
+
position: fixed;
|
|
60
|
+
top: 16px;
|
|
61
|
+
right: 16px;
|
|
62
|
+
margin-inline-start: 16px;
|
|
63
|
+
margin-block-end: 16px;
|
|
64
|
+
color: #2d2d2d;
|
|
65
|
+
background-color: #737373;
|
|
66
|
+
border: 2px solid;
|
|
67
|
+
border-color: #eee;
|
|
68
|
+
border-radius: 16px;
|
|
69
|
+
z-index: 2147483647;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.infobar:valid, .infobar:not(:focus-within) .infobar-content {
|
|
73
|
+
display: none;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.infobar:focus-within {
|
|
77
|
+
background-color: #f9f9f9;
|
|
78
|
+
border-color: #878787;
|
|
79
|
+
border-radius: 8px;
|
|
80
|
+
opacity: 1;
|
|
81
|
+
transition-property: opacity, background-color, border-color, border-radius,
|
|
82
|
+
color;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.infobar-content {
|
|
86
|
+
align-items: center;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.infobar-content span {
|
|
90
|
+
font-family: Arial, Helvetica, sans-serif;
|
|
91
|
+
font-size: 14px;
|
|
92
|
+
line-height: 18px;
|
|
93
|
+
word-break: break-word;
|
|
94
|
+
white-space: pre-wrap;
|
|
95
|
+
margin-inline: 4px;
|
|
96
|
+
margin-block: 4px;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.infobar .infobar-icon,
|
|
100
|
+
.infobar .infobar-close-icon,
|
|
101
|
+
.infobar .infobar-link-icon {
|
|
102
|
+
cursor: pointer;
|
|
103
|
+
background-position: center;
|
|
104
|
+
background-repeat: no-repeat;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.infobar .infobar-close-icon,
|
|
108
|
+
.infobar .infobar-link-icon {
|
|
109
|
+
align-self: flex-start;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.infobar .infobar-icon {
|
|
113
|
+
position: absolute;
|
|
114
|
+
min-inline-size: 24px;
|
|
115
|
+
min-block-size: 24px;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.infobar:focus-within .infobar-icon {
|
|
119
|
+
z-index: -1;
|
|
120
|
+
background-image: none;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.infobar .infobar-close-icon {
|
|
124
|
+
min-inline-size: 22px;
|
|
125
|
+
min-block-size: 22px;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.infobar .infobar-icon {
|
|
129
|
+
background-color: transparent;
|
|
130
|
+
background-size: 70%;
|
|
131
|
+
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAABhmlDQ1BJQ0MgcHJvZmlsZQAAKJF9kj1Iw0AYht+mSkUrDnYQcchQnSyIijqWKhbBQmkrtOpgcukfNGlIUlwcBdeCgz+LVQcXZ10dXAVB8AfEydFJ0UVK/C4ptIjx4LiH9+59+e67A4RGhalm1wSgapaRisfEbG5VDLyiDwEAvZiVmKkn0osZeI6ve/j4ehfhWd7n/hz9St5kgE8kjjLdsIg3iGc2LZ3zPnGIlSSF+Jx43KACiR+5Lrv8xrnosMAzQ0YmNU8cIhaLHSx3MCsZKvE0cVhRNcoXsi4rnLc4q5Uaa9XJbxjMaytprtMcQRxLSCAJETJqKKMCCxFaNVJMpGg/5uEfdvxJcsnkKoORYwFVqJAcP/gb/O6tWZiadJOCMaD7xbY/RoHALtCs2/b3sW03TwD/M3Cltf3VBjD3SXq9rYWPgIFt4OK6rcl7wOUOMPSkS4bkSH6aQqEAvJ/RM+WAwVv6EGtu31r7OH0AMtSr5Rvg4BAYK1L2use9ezr79u+ZVv9+AFlNcp0UUpiqAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5AsHADIRLMaOHwAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAPUExURQAAAIqKioyNjY2OjvDw8L2y1DEAAAABdFJOUwBA5thmAAAAAWJLR0QB/wIt3gAAAGNJREFUSMdjYCAJsLi4OBCQx6/CBQwIGIDPCBcXAkYQUsACU+AwlBVQHg6Eg5pgZBGOboIJZugDFwRwoJECJCUOhJI1wZwzqmBUwagCuipgIqTABG9h7YIKaKGAURAFEF/6AQAO4HqSoDP8bgAAAABJRU5ErkJggg==);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.infobar .infobar-link-icon {
|
|
135
|
+
background-size: 60%;
|
|
136
|
+
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAgMAAADXB5lNAAABhmlDQ1BJQ0MgcHJvZmlsZQAAKJF9kj1Iw0AYht+mSkUrDnYQcchQnSyIijqWKhbBQmkrtOpgcukfNGlIUlwcBdeCgz+LVQcXZ10dXAVB8AfEydFJ0UVK/C4ptIjx4LiH9+59+e67A4RGhalm1wSgapaRisfEbG5VDLyiDwEAvZiVmKkn0osZeI6ve/j4ehfhWd7n/hz9St5kgE8kjjLdsIg3iGc2LZ3zPnGIlSSF+Jx43KACiR+5Lrv8xrnosMAzQ0YmNU8cIhaLHSx3MCsZKvE0cVhRNcoXsi4rnLc4q5Uaa9XJbxjMaytprtMcQRxLSCAJETJqKKMCCxFaNVJMpGg/5uEfdvxJcsnkKoORYwFVqJAcP/gb/O6tWZiadJOCMaD7xbY/RoHALtCs2/b3sW03TwD/M3Cltf3VBjD3SXq9rYWPgIFt4OK6rcl7wOUOMPSkS4bkSH6aQqEAvJ/RM+WAwVv6EGtu31r7OH0AMtSr5Rvg4BAYK1L2use9ezr79u+ZVv9+AFlNcp0UUpiqAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5AsHAB8H+DhhoQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAJUExURQAAAICHi4qKioTuJAkAAAABdFJOUwBA5thmAAAAAWJLR0QCZgt8ZAAAAJJJREFUOI3t070NRCEMA2CnYAOyDyPwpHj/Va7hJ3FzV7zy3ET5JIwoAF6Jk4wzAJAkzxAYG9YRTgB+24wBgKmfrGAKTcEfAY4KRlRoIeBTgKOCERVaCPgU4Khge2GqKOBTgKOCERVaAEC/4PNcnyoSWHpjqkhwKxbcig0Q6AorXYF/+A6eIYD1lVbwG/jdA6/kA2THRAURVubcAAAAAElFTkSuQmCC);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.infobar .infobar-close-icon {
|
|
140
|
+
appearance: none;
|
|
141
|
+
background-size: 80%;
|
|
142
|
+
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAgMAAADXB5lNAAABhmlDQ1BJQ0MgcHJvZmlsZQAAKJF9kj1Iw0AYht+mSkUrDnYQcchQnSyIijqWKhbBQmkrtOpgcukfNGlIUlwcBdeCgz+LVQcXZ10dXAVB8AfEydFJ0UVK/C4ptIjx4LiH9+59+e67A4RGhalm1wSgapaRisfEbG5VDLyiDwEAvZiVmKkn0osZeI6ve/j4ehfhWd7n/hz9St5kgE8kjjLdsIg3iGc2LZ3zPnGIlSSF+Jx43KACiR+5Lrv8xrnosMAzQ0YmNU8cIhaLHSx3MCsZKvE0cVhRNcoXsi4rnLc4q5Uaa9XJbxjMaytprtMcQRxLSCAJETJqKKMCCxFaNVJMpGg/5uEfdvxJcsnkKoORYwFVqJAcP/gb/O6tWZiadJOCMaD7xbY/RoHALtCs2/b3sW03TwD/M3Cltf3VBjD3SXq9rYWPgIFt4OK6rcl7wOUOMPSkS4bkSH6aQqEAvJ/RM+WAwVv6EGtu31r7OH0AMtSr5Rvg4BAYK1L2use9ezr79u+ZVv9+AFlNcp0UUpiqAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5AsHAB8VC4EQ6QAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAJUExURQAAAICHi4qKioTuJAkAAAABdFJOUwBA5thmAAAAAWJLR0QCZgt8ZAAAAJtJREFUOI3NkrsBgCAMRLFwBPdxBArcfxXFkO8rbKWAAJfHJ9faf9vuYX/749T5NmShm3bEwbe2SxeuM4+2oxDL1cDoKtVUjRy+tH78Cv2CS+wIiQNC1AEhk4AQeUTMWUJMfUJMSEJMSEY8kIx4IONroaYAimNxsXp1PA7PxwfVL8QnowwoVC0lig07wDDVUjAdbAnjwtow/z/bDW7eI4M2KruJAAAAAElFTkSuQmCC);
|
|
143
|
+
}
|
|
144
|
+
`;
|
|
145
|
+
|
|
146
|
+
export { displayIcon, appendInfobar, refreshInfobarInfo, extractInfobarData, INFOBAR_TAGNAME };
|
|
147
|
+
|
|
148
|
+
function appendInfobar(doc, options, useShadowRoot) {
|
|
149
|
+
if (!doc.querySelector(INFOBAR_TAGNAME)) {
|
|
150
|
+
let infoData;
|
|
151
|
+
if (options.infobarContent) {
|
|
152
|
+
infoData = options.infobarContent.replace(/\\n/g, "\n").replace(/\\t/g, "\t");
|
|
153
|
+
} else if (options.saveDate) {
|
|
154
|
+
infoData = options.saveDate;
|
|
155
|
+
}
|
|
156
|
+
infoData = infoData || "No info";
|
|
157
|
+
const infobarElement = createElement(doc, INFOBAR_TAGNAME, doc.body);
|
|
158
|
+
let infobarContainer;
|
|
159
|
+
if (useShadowRoot) {
|
|
160
|
+
infobarContainer = infobarElement.attachShadow({ mode: "open" });
|
|
161
|
+
} else {
|
|
162
|
+
const shadowRootTemplate = doc.createElement("template");
|
|
163
|
+
shadowRootTemplate.setAttribute("shadowroot", "open");
|
|
164
|
+
infobarElement.appendChild(shadowRootTemplate);
|
|
165
|
+
infobarContainer = shadowRootTemplate;
|
|
166
|
+
}
|
|
167
|
+
const shadowRootContent = doc.createElement("div");
|
|
168
|
+
const styleElement = doc.createElement("style");
|
|
169
|
+
styleElement.textContent = INFOBAR_STYLES
|
|
170
|
+
.replace(/ {2}/g, "")
|
|
171
|
+
.replace(/\n/g, "")
|
|
172
|
+
.replace(/: /g, ":")
|
|
173
|
+
.replace(/, /g, ",");
|
|
174
|
+
shadowRootContent.appendChild(styleElement);
|
|
175
|
+
const infobarContent = doc.createElement("form");
|
|
176
|
+
infobarContent.classList.add("infobar");
|
|
177
|
+
shadowRootContent.appendChild(infobarContent);
|
|
178
|
+
const iconElement = doc.createElement("span");
|
|
179
|
+
iconElement.tabIndex = -1;
|
|
180
|
+
iconElement.classList.add("infobar-icon");
|
|
181
|
+
infobarContent.appendChild(iconElement);
|
|
182
|
+
const contentElement = doc.createElement("span");
|
|
183
|
+
contentElement.tabIndex = -1;
|
|
184
|
+
contentElement.classList.add("infobar-content");
|
|
185
|
+
const closeButtonElement = doc.createElement("input");
|
|
186
|
+
closeButtonElement.type = "checkbox";
|
|
187
|
+
closeButtonElement.required = true;
|
|
188
|
+
closeButtonElement.classList.add("infobar-close-icon");
|
|
189
|
+
closeButtonElement.title = "Close";
|
|
190
|
+
contentElement.appendChild(closeButtonElement);
|
|
191
|
+
const textElement = doc.createElement("span");
|
|
192
|
+
textElement.textContent = infoData;
|
|
193
|
+
contentElement.appendChild(textElement);
|
|
194
|
+
const linkElement = doc.createElement("a");
|
|
195
|
+
linkElement.classList.add("infobar-link-icon");
|
|
196
|
+
linkElement.target = "_blank";
|
|
197
|
+
linkElement.rel = "noopener noreferrer";
|
|
198
|
+
linkElement.title = "Open source URL: " + options.saveUrl;
|
|
199
|
+
linkElement.href = options.saveUrl;
|
|
200
|
+
contentElement.appendChild(linkElement);
|
|
201
|
+
infobarContent.appendChild(contentElement);
|
|
202
|
+
if (useShadowRoot) {
|
|
203
|
+
infobarContainer.appendChild(shadowRootContent);
|
|
204
|
+
} else {
|
|
205
|
+
const scriptElement = doc.createElement("script");
|
|
206
|
+
let scriptContent = refreshInfobarInfo.toString();
|
|
207
|
+
scriptContent += extractInfobarData.toString();
|
|
208
|
+
scriptContent += "(" + initInfobar.toString() + ")(document)";
|
|
209
|
+
scriptElement.textContent = scriptContent;
|
|
210
|
+
shadowRootContent.appendChild(scriptElement);
|
|
211
|
+
infobarContainer.innerHTML = shadowRootContent.outerHTML;
|
|
212
|
+
}
|
|
213
|
+
doc.body.appendChild(infobarElement);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function extractInfobarData(doc) {
|
|
218
|
+
const result = doc.evaluate("//comment()", doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
|
|
219
|
+
let singleFileComment = result && result.singleNodeValue;
|
|
220
|
+
if (singleFileComment && singleFileComment.nodeType == Node.COMMENT_NODE && singleFileComment.textContent.includes(SINGLE_FILE_SIGNATURE)) {
|
|
221
|
+
const info = singleFileComment.textContent.split("\n");
|
|
222
|
+
const [, , urlData, ...optionalData] = info;
|
|
223
|
+
const urlMatch = urlData.match(/^ url: (.*) ?$/);
|
|
224
|
+
const saveUrl = urlMatch && urlMatch[1];
|
|
225
|
+
if (saveUrl) {
|
|
226
|
+
let infobarContent, saveDate;
|
|
227
|
+
if (optionalData.length) {
|
|
228
|
+
saveDate = optionalData[0].split("saved date: ")[1];
|
|
229
|
+
if (saveDate) {
|
|
230
|
+
optionalData.shift();
|
|
231
|
+
}
|
|
232
|
+
if (optionalData.length > 1) {
|
|
233
|
+
let content = optionalData[0].split("info: ")[1].trim();
|
|
234
|
+
for (let indexLine = 1; indexLine < optionalData.length - 1; indexLine++) {
|
|
235
|
+
content += "\n" + optionalData[indexLine].trim();
|
|
236
|
+
}
|
|
237
|
+
infobarContent = content.trim();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return { saveUrl, infobarContent, saveDate };
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function refreshInfobarInfo(doc, { saveUrl, infobarContent, saveDate }) {
|
|
246
|
+
if (saveUrl) {
|
|
247
|
+
const infobarElement = doc.querySelector("single-file-infobar");
|
|
248
|
+
const shadowRootFragment = infobarElement.shadowRoot;
|
|
249
|
+
const infobarContentElement = shadowRootFragment.querySelector(".infobar-content span");
|
|
250
|
+
infobarContentElement.textContent = infobarContent || saveDate;
|
|
251
|
+
const linkElement = shadowRootFragment.querySelector(".infobar-content .infobar-link-icon");
|
|
252
|
+
linkElement.href = saveUrl;
|
|
253
|
+
linkElement.title = "Open source URL: " + saveUrl;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function displayIcon(doc, useShadowRoot) {
|
|
258
|
+
const infoData = extractInfobarData(doc);
|
|
259
|
+
if (infoData.saveUrl) {
|
|
260
|
+
appendInfobar(doc, infoData, useShadowRoot);
|
|
261
|
+
refreshInfobarInfo(doc, infoData);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function initInfobar(doc) {
|
|
266
|
+
const infoData = extractInfobarData(doc);
|
|
267
|
+
if (infoData && infoData.saveUrl) {
|
|
268
|
+
refreshInfobarInfo(doc, infoData);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function createElement(doc, tagName, parentElement) {
|
|
273
|
+
const element = doc.createElement(tagName);
|
|
274
|
+
parentElement.appendChild(element);
|
|
275
|
+
Array.from(getComputedStyle(element)).forEach(property => element.style.setProperty(property, "initial", "important"));
|
|
276
|
+
return element;
|
|
273
277
|
}
|