forked from ret-Phoenix/SmartConfigurator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.js
More file actions
80 lines (69 loc) · 1.82 KB
/
format.js
File metadata and controls
80 lines (69 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var fso = new ActiveXObject("Scripting.FileSystemObject");
var str_from_file = "";
function echo(prmTxt)
{
with (new ActiveXObject("WScript.Shell")) res = Popup("<"+prmTxt+">", 0, "title", 0);
}
function GetFromClipboard() {
// fso = new ActiveXObject("Scripting.FileSystemObject");
f=fso.OpenTextFile('tmp/module.txt',1);
var textFromFile = f.ReadAll();
if (!textFromFile) {
return;
}
return textFromFile;
}
function JSTrim(vValue)
{
return vValue.replace(/(^\s*)|(\s*$)/g, "");
}
function wtiteToResultFile(file_name, file_data) {
f = fso.CreateTextFile(file_name, true);
f.Write(file_data);
f.Close();
}
function un_format_block_vert(arg){
var list_rows = str_from_file.split('\r').join('').split('\n');;
new_str_arr = "";
for (var i = 0; i < list_rows.length; i++) {
cur_row = JSTrim(list_rows[i]);
if (cur_row.substring(0,1) == "|") {
cur_row = cur_row.substring(1);
}
new_str_arr += cur_row + '\r\n';
}
wtiteToResultFile("tmp/module.txt", JSTrim(new_str_arr));
}
function format_block_vert(arg){
var list_rows = str_from_file.split('\r').join('').split('\n');;
new_str_arr = "";
for (var i = 0; i < list_rows.length; i++) {
new_str_arr += "| " + JSTrim(list_rows[i]) + '\r\n';
}
new_str_arr = JSTrim(new_str_arr);
wtiteToResultFile("tmp/module.txt", new_str_arr);
}
function Run()
{
arg=WScript.Arguments;
fso = new ActiveXObject("Scripting.FileSystemObject");
if (arg(0) != 'null') {
f=fso.OpenTextFile(arg(0),1);
var lTxt=f.ReadAll();
str_from_file =lTxt.split('\r').join('').split('\n');
f.close();
} else {
str_from_file = GetFromClipboard();
}
switch (arg(1)) {
case "format_block_vert":
format_block_vert(str_from_file);
break;
case "un_format_block_vert":
un_format_block_vert(str_from_file);
break;
default:
return; // íå äîëæíî áûòü â ïðèíöèïå
}
}
Run();