|
24 | 24 | * NOTE: This is function 2 of 2 that is git-forge specific. |
25 | 25 | */ |
26 | 26 | const isGitForgeFileUrl = function (url) { |
27 | | - return (url.indexOf('//raw.githubusercontent.com') > 0 || url.indexOf('//bitbucket.org') > 0); |
| 27 | + return (url.indexOf('//raw.githubusercontent.com') > 0 |
| 28 | + || url.indexOf('//bitbucket.org') > 0); |
28 | 29 | } |
29 | 30 |
|
30 | 31 | /** |
|
136 | 137 | } |
137 | 138 | }); |
138 | 139 | // Scripts |
139 | | - const script = document.querySelectorAll('script[type="text/htmlpreview"]'); |
| 140 | + const script = document.querySelectorAll( |
| 141 | + 'script[type="text/htmlpreview"]' |
| 142 | + ); |
140 | 143 | for (i = 0; i < script.length; ++i) { |
141 | 144 | // Get absolute URL |
142 | 145 | src = script[i].src; |
|
154 | 157 | loadJS(res[i]); |
155 | 158 | } |
156 | 159 | // Dispatch DOMContentLoaded event after loading all scripts |
157 | | - document.dispatchEvent(new Event('DOMContentLoaded', {bubbles: true, cancelable: true})); |
| 160 | + document.dispatchEvent(new Event( |
| 161 | + 'DOMContentLoaded', |
| 162 | + {bubbles: true, cancelable: true} |
| 163 | + )); |
158 | 164 | }); |
159 | 165 | }; |
160 | 166 |
|
|
163 | 169 | // Add <base> just after <head> |
164 | 170 | // and replace <script type="text/javascript"> |
165 | 171 | // with <script type="text/htmlpreview"> |
166 | | - data = data |
167 | | - .replace(/<head([^>]*)>/i, '<head$1><base href="' + rawFileUrl + '">') |
168 | | - .replace(/<script(\s*src=["'][^"']*["'])?(\s*type=["'](text|application)\/javascript["'])?/gi, '<script type="text/htmlpreview"$1'); |
| 172 | + data = data.replace( |
| 173 | + /<head([^>]*)>/i, |
| 174 | + '<head$1><base href="' + rawFileUrl + '">' |
| 175 | + ).replace( |
| 176 | + /<script(\s*src=["'][^"']*["'])?(\s*type=["'](text|application)\/javascript["'])?/gi, |
| 177 | + '<script type="text/htmlpreview"$1' |
| 178 | + ); |
169 | 179 | // Delay updating document to have it cleared before |
170 | 180 | setTimeout(function () { |
171 | 181 | document.open(); |
|
199 | 209 | ]; |
200 | 210 | return fetch(proxy[i] + url, options).then(function (res) { |
201 | 211 | if (!res.ok) { |
202 | | - throw new Error('Cannot load ' + url + ': ' + res.status + ' ' + res.statusText); |
| 212 | + const errMsg = res.status + ' ' + res.statusText; |
| 213 | + throw new Error('Cannot load ' + url + ': ' + errMsg); |
203 | 214 | } |
204 | 215 | return res.text(); |
205 | 216 | }).catch(function (error) { |
|
0 commit comments