File tree 1 file changed +30
-0
lines changed
src/pages/options/routes/script
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -240,6 +240,27 @@ function ScriptEditor() {
240
240
} ) ;
241
241
} ) ;
242
242
} ;
243
+ const saveAs = ( script : Script , e : editor . IStandaloneCodeEditor ) => {
244
+ return new Promise < void > ( ( resolve ) => {
245
+ try {
246
+ chrome . downloads . download (
247
+ {
248
+ url : URL . createObjectURL (
249
+ new Blob ( [ e . getValue ( ) ] , { type : "text/javascript" } )
250
+ ) ,
251
+ saveAs : true , // true直接弹出对话框;false弹出下载选项
252
+ filename : `${ script . name } .user.js` ,
253
+ } ,
254
+ ( ) => {
255
+ Message . success ( "另存为成功" ) ;
256
+ resolve ( ) ;
257
+ }
258
+ ) ;
259
+ } catch ( err ) {
260
+ Message . error ( `另存为失败: ${ err } ` ) ;
261
+ }
262
+ } ) ;
263
+ } ;
243
264
const menu : EditorMenu [ ] = [
244
265
{
245
266
title : "文件" ,
@@ -249,6 +270,11 @@ function ScriptEditor() {
249
270
hotKey : KeyMod . CtrlCmd | KeyCode . KeyS ,
250
271
action : save ,
251
272
} ,
273
+ {
274
+ title : "另存为" ,
275
+ hotKey : KeyMod . CtrlCmd | KeyMod . Shift | KeyCode . KeyS ,
276
+ action : saveAs ,
277
+ } ,
252
278
] ,
253
279
} ,
254
280
{
@@ -557,6 +583,10 @@ function ScriptEditor() {
557
583
{ item . items . map ( ( menuItem , i ) => {
558
584
const btn = (
559
585
< Button
586
+ style = { {
587
+ width : "100%" ,
588
+ textAlign : "left" ,
589
+ } }
560
590
key = { `sm_${ menuItem . title } ` }
561
591
size = "mini"
562
592
onClick = { ( ) => {
You can’t perform that action at this time.
0 commit comments