@@ -52,11 +52,13 @@ const loadButton = document.getElementById('loadButton');
52
52
53
53
const downloadWorkspace = ( ) => {
54
54
const json = {
55
+ "name" : fileName . value || "workspace" ,
55
56
"version" : version ,
56
57
"date" : date ,
57
- "workspace" : save ( ws )
58
+ "workspace" : save ( ws ) ,
59
+ "lua" : luaGenerator . workspaceToCode ( ws )
58
60
}
59
- const blob = new Blob ( [ json ] , { type : 'application/json' } ) ;
61
+ const blob = new Blob ( [ JSON . stringify ( json ) ] , { type : 'application/json' } ) ;
60
62
const url = URL . createObjectURL ( blob ) ;
61
63
const a = document . createElement ( 'a' ) ;
62
64
a . href = url ;
@@ -73,67 +75,70 @@ const loadWorkspace = () => {
73
75
const file = input . files [ 0 ] ;
74
76
const reader = new FileReader ( ) ;
75
77
reader . onload = ( ) => {
76
- load ( ws , reader . result [ 'workspace' ] ) ;
78
+ const json = JSON . parse ( reader . result ) ;
79
+ load ( ws , json [ 'workspace' ] ) ;
80
+ fileName . value = json [ 'name' ] ;
81
+ codeDiv . innerText = json [ 'lua' ] ;
77
82
} ;
78
83
reader . readAsText ( file ) ;
79
84
} ;
80
85
} ;
81
86
82
- const uploadToPastebin = ( ) => {
83
- const code = luaGenerator . workspaceToCode ( ws ) ;
84
- const xhr = new XMLHttpRequest ( ) ;
85
- xhr . open ( 'POST' , 'https://pastebin.com/api/api_post.php' , true ) ;
86
- xhr . setRequestHeader ( 'Content-Type' , 'application/x-www-form-urlencoded' ) ;
87
- xhr . onreadystatechange = ( ) => {
88
- if ( xhr . readyState == 4 && xhr . status == 200 ) {
89
- const url = xhr . responseText ;
90
- const a = document . createElement ( 'a' ) ;
91
- a . href = url ;
92
- a . target = '_blank' ;
93
- a . click ( ) ;
94
- }
95
- } ;
96
- if ( secret [ 'connected' ] === false ) {
97
- xhr . send ( `api_dev_key=${ secret [ 'api_dev_key' ] } &api_user_key=${ secret [ 'api_user_key' ] } &api_folder_key=5BbL8uf5&api_option=paste&api_paste_code=${ encodeURIComponent ( code ) } &api_paste_private=1&api_paste_name=${ ( fileName . value || 'workspace' ) + ' | lua (' + Math . random ( ) . toString ( 36 ) . substring ( 7 ) + ')' } &api_paste_format=lua` ) ;
98
- } else {
99
- xhr . send ( `api_dev_key=${ secret [ 'api_dev_key' ] } &api_option=paste&api_paste_code=${ encodeURIComponent ( code ) } &api_paste_private=1&api_paste_name=${ ( fileName . value || 'workspace' ) + ' | lua (' + Math . random ( ) . toString ( 36 ) . substring ( 7 ) + ')' } &api_paste_format=lua` ) ;
100
- }
101
- }
102
-
103
- const uploadWorkspaceToPastebin = ( ) => {
104
- const workspace = save ( ws ) ;
105
- const xhr = new XMLHttpRequest ( ) ;
106
- xhr . open ( 'POST' , 'https://pastebin.com/api/api_post.php' , true ) ;
107
- xhr . setRequestHeader ( 'Content-Type' , 'application/x-www-form-urlencoded' ) ;
108
- xhr . onreadystatechange = ( ) => {
109
- if ( xhr . readyState == 4 && xhr . status == 200 ) {
110
- const url = xhr . responseText ;
111
- const a = document . createElement ( 'a' ) ;
112
- a . href = url ;
113
- a . target = '_blank' ;
114
- a . click ( ) ;
115
- }
116
- } ;
117
- if ( secret [ 'connected' ] === false ) {
118
- xhr . send ( `api_dev_key=${ secret [ 'api_dev_key' ] } &api_user_key=${ secret [ 'api_user_key' ] } &api_folder_key=5BbL8uf5&api_option=paste&api_paste_code=${ encodeURIComponent ( workspace ) } &api_paste_private=1&api_paste_name=${ ( fileName . value || 'workspace' ) + ' | workspace (' + Math . random ( ) . toString ( 36 ) . substring ( 7 ) + ')' } &api_paste_format=json` ) ;
119
- } else {
120
- xhr . send ( `api_dev_key=${ secret [ 'api_dev_key' ] } &api_option=paste&api_paste_code=${ encodeURIComponent ( workspace ) } &api_paste_private=1&api_paste_name=${ ( fileName . value || 'workspace' ) + ' | workspace (' + Math . random ( ) . toString ( 36 ) . substring ( 7 ) + ')' } &api_paste_format=json` ) ;
121
- }
122
- }
123
-
124
- const loadWorkspaceFromPastebin = ( ) => {
125
- const id = prompt ( 'Enter pastebin ID' ) ;
126
- if ( ! id ) return ;
127
- const xhr = new XMLHttpRequest ( ) ;
128
- xhr . open ( 'GET' , `pastebin.php?id=${ id } ` , true ) ;
129
- xhr . onreadystatechange = ( ) => {
130
- if ( xhr . readyState == 4 && xhr . status == 200 ) {
131
- load ( ws , xhr . responseText ) ;
132
- console . log ( xhr . responseText ) ;
133
- }
134
- } ;
135
- xhr . send ( ) ;
136
- }
87
+ // const uploadToPastebin = () => {
88
+ // const code = luaGenerator.workspaceToCode(ws);
89
+ // const xhr = new XMLHttpRequest();
90
+ // xhr.open('POST', 'https://pastebin.com/api/api_post.php', true);
91
+ // xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
92
+ // xhr.onreadystatechange = () => {
93
+ // if (xhr.readyState == 4 && xhr.status == 200) {
94
+ // const url = xhr.responseText;
95
+ // const a = document.createElement('a');
96
+ // a.href = url;
97
+ // a.target = '_blank';
98
+ // a.click();
99
+ // }
100
+ // };
101
+ // if (secret['connected'] === false) {
102
+ // xhr.send(`api_dev_key=${secret['api_dev_key']}&api_user_key=${secret['api_user_key']}&api_folder_key=5BbL8uf5&api_option=paste&api_paste_code=${encodeURIComponent(code)}&api_paste_private=1&api_paste_name=${(fileName.value || 'workspace') + ' | lua (' + Math.random().toString(36).substring(7) + ')'}&api_paste_format=lua`);
103
+ // } else {
104
+ // xhr.send(`api_dev_key=${secret['api_dev_key']}&api_option=paste&api_paste_code=${encodeURIComponent(code)}&api_paste_private=1&api_paste_name=${(fileName.value || 'workspace') + ' | lua (' + Math.random().toString(36).substring(7) + ')'}&api_paste_format=lua`);
105
+ // }
106
+ // }
107
+
108
+ // const uploadWorkspaceToPastebin = () => {
109
+ // const workspace = save(ws);
110
+ // const xhr = new XMLHttpRequest();
111
+ // xhr.open('POST', 'https://pastebin.com/api/api_post.php', true);
112
+ // xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
113
+ // xhr.onreadystatechange = () => {
114
+ // if (xhr.readyState == 4 && xhr.status == 200) {
115
+ // const url = xhr.responseText;
116
+ // const a = document.createElement('a');
117
+ // a.href = url;
118
+ // a.target = '_blank';
119
+ // a.click();
120
+ // }
121
+ // };
122
+ // if (secret['connected'] === false) {
123
+ // xhr.send(`api_dev_key=${secret['api_dev_key']}&api_user_key=${secret['api_user_key']}&api_folder_key=5BbL8uf5&api_option=paste&api_paste_code=${encodeURIComponent(workspace)}&api_paste_private=1&api_paste_name=${(fileName.value || 'workspace') + ' | workspace (' + Math.random().toString(36).substring(7) + ')'}&api_paste_format=json`);
124
+ // } else {
125
+ // xhr.send(`api_dev_key=${secret['api_dev_key']}&api_option=paste&api_paste_code=${encodeURIComponent(workspace)}&api_paste_private=1&api_paste_name=${(fileName.value || 'workspace') + ' | workspace (' + Math.random().toString(36).substring(7) + ')'}&api_paste_format=json`);
126
+ // }
127
+ // }
128
+
129
+ // const loadWorkspaceFromPastebin = () => {
130
+ // const id = prompt('Enter pastebin ID');
131
+ // if (!id) return;
132
+ // const xhr = new XMLHttpRequest();
133
+ // xhr.open('GET', `pastebin.php?id=${id}`, true);
134
+ // xhr.onreadystatechange = () => {
135
+ // if (xhr.readyState == 4 && xhr.status == 200) {
136
+ // load(ws, xhr.responseText);
137
+ // console.log(xhr.responseText);
138
+ // }
139
+ // };
140
+ // xhr.send();
141
+ // }
137
142
138
143
//const connectToPastebin = () => {
139
144
// const username = prompt('Enter pastebin username');
0 commit comments