File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,39 @@ globalThis.setInterval = (fn, interval) => {
1212} ;
1313// TODO: clearInterval
1414
15+ globalThis . $quote = arg => {
16+ // Sources:
17+ // - https://stackoverflow.com/a/47469792
18+ // - https://docs.microsoft.com/en-gb/archive/blogs/twistylittlepassagesallalike/everyone-quotes-command-line-arguments-the-wrong-way
19+ if ( ! ( / [ \t \n \v ] / . exec ( arg ) ) ) {
20+ return arg ;
21+ }
22+ let str = '"' ;
23+ for ( let i = 0 ; i < arg . length ; i ++ ) {
24+ let slashes = 0 ;
25+ while ( i < arg . length && arg [ i ] === '\\' ) {
26+ slashes ++ ;
27+ i ++ ;
28+ }
29+ if ( i === arg . length ) {
30+ str += '\\' . repeat ( slashes * 2 ) ;
31+ break ;
32+ } else if ( arg [ i ] === '"' ) {
33+ str += '\\' . repeat ( slashes * 2 + 1 ) + arg [ i ] ;
34+ } else {
35+ str += '\\' . repeat ( slashes ) + arg [ i ] ;
36+ }
37+ }
38+ return str + '"' ;
39+ } ;
40+
41+ globalThis . $ps = async cmd => await $ ( `powershell -Command ${ globalThis . $quote ( cmd ) } ` ) ;
42+
43+ globalThis . $psFetch = async url => {
44+ const cmd = `$ProgressPreference='SilentlyContinue';$(Invoke-WebRequest '${ url . replace ( / ' / g, "''" ) } ').Content` ;
45+ return await globalThis . $ps ( cmd ) ;
46+ } ;
47+
1548setInterval ( __wbc . yieldToC , 10 ) ;
1649setInterval ( __wbc . checkBarSize , 100 ) ;
1750
You can’t perform that action at this time.
0 commit comments