File tree Expand file tree Collapse file tree
src/pages/options/routes/script Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -240,6 +240,27 @@ function ScriptEditor() {
240240 } ) ;
241241 } ) ;
242242 } ;
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+ } ;
243264 const menu : EditorMenu [ ] = [
244265 {
245266 title : "文件" ,
@@ -249,6 +270,11 @@ function ScriptEditor() {
249270 hotKey : KeyMod . CtrlCmd | KeyCode . KeyS ,
250271 action : save ,
251272 } ,
273+ {
274+ title : "另存为" ,
275+ hotKey : KeyMod . CtrlCmd | KeyMod . Shift | KeyCode . KeyS ,
276+ action : saveAs ,
277+ } ,
252278 ] ,
253279 } ,
254280 {
@@ -557,6 +583,10 @@ function ScriptEditor() {
557583 { item . items . map ( ( menuItem , i ) => {
558584 const btn = (
559585 < Button
586+ style = { {
587+ width : "100%" ,
588+ textAlign : "left" ,
589+ } }
560590 key = { `sm_${ menuItem . title } ` }
561591 size = "mini"
562592 onClick = { ( ) => {
You can’t perform that action at this time.
0 commit comments