Skip to content

Commit 7f5b665

Browse files
committed
AI.sct: Reduce file sizes to keep virus scanning engines happy
1 parent ddb3888 commit 7f5b665

File tree

2 files changed

+34
-85
lines changed

2 files changed

+34
-85
lines changed

Plugins/dlls/AI.sct

+19-83
Original file line numberDiff line numberDiff line change
@@ -34,46 +34,15 @@ var pluginArguments = "";
3434
var variables = new Array();
3535
var mergeApp;
3636

37-
function get_PluginEvent() {
38-
return "EDITOR_SCRIPT";
39-
}
40-
41-
function get_PluginDescription() {
42-
return "AI-assisted text conversion functions";
43-
}
44-
45-
function get_PluginFileFilters() {
46-
return ".*";
47-
}
48-
49-
function get_PluginExtendedProperties() {
50-
return "GenerateUnpacker;" +
51-
"AIConvertText.MenuCaption=Convert Text with AI...;" +
52-
"AIConvertText.Description=Text converter using OpenAI API.\r\n" +
53-
"Usage: AIConvertText PROMPT;" +
54-
"AIConvertText.ArgumentsRequired;";
55-
}
56-
57-
function get_PluginArguments() {
58-
return pluginArguments;
59-
}
60-
61-
function put_PluginArguments(NewValue) {
62-
pluginArguments = NewValue;
63-
}
64-
65-
function get_PluginVariables() {
66-
return variables.join("\0");
67-
}
68-
69-
function put_PluginVariables(NewValue) {
70-
variables = NewValue.split("\0");
71-
}
72-
73-
function regRead(Key, DefaultValue) {
74-
return mergeApp.GetOption(Key, DefaultValue);
75-
}
76-
37+
function get_PluginEvent() { return "EDITOR_SCRIPT"; }
38+
function get_PluginDescription() { return "AI-assisted text conversion functions"; }
39+
function get_PluginFileFilters() { return ".*"; }
40+
function get_PluginExtendedProperties() { return "GenerateUnpacker;AIConvertText.MenuCaption=Convert Text with AI...;AIConvertText.Description=Text converter using OpenAI API.\r\nUsage: AIConvertText PROMPT;AIConvertText.ArgumentsRequired;"; }
41+
function get_PluginArguments() { return pluginArguments; }
42+
function put_PluginArguments(NewValue) { pluginArguments = NewValue; }
43+
function get_PluginVariables() { return variables.join("\0"); }
44+
function put_PluginVariables(NewValue) { variables = NewValue.split("\0"); }
45+
function regRead(Key, DefaultValue) { return mergeApp.GetOption(Key, DefaultValue); }
7746
function regWrite(Key, Value, TypeNm) {
7847
mergeApp.SaveOption(Key, (TypeNm === "REG_DWORD") ? parseInt(Value, 10) : String(Value));
7948
}
@@ -106,50 +75,23 @@ function ReplaceVariables(str) {
10675
return newstr;
10776
}
10877

109-
function IsFirstArgumentEmpty() {
110-
return (pluginArguments.match(/^\s*$/) !== null);
111-
}
78+
function IsFirstArgumentEmpty() { return pluginArguments.match(/^\s*$/) !== null; }
11279

11380
function Unescape(text) {
81+
var map = { 'a': String.fromCharCode(0x07), 'b': '\b', 't': '\t', 'n': '\n', 'v': String.fromCharCode(0x0b), 'f': '\f', 'r': '\r', '\"': '\"', '\\': '\\' };
11482
var result = "";
11583
var textLen = text.length;
11684
var i = 0;
11785
while (i < textLen) {
11886
var ch = text.charAt(i);
119-
switch (ch) {
120-
case "\\":
87+
if (ch === "\\") {
12188
if (i < textLen - 1) {
12289
i++;
12390
ch = text.charAt(i);
124-
switch (ch) {
125-
case "a":
126-
result += String.fromCharCode(0x07);
127-
break;
128-
case "b":
129-
result += "\b";
130-
break;
131-
case "t":
132-
result += "\t";
133-
break;
134-
case "n":
135-
result += "\n";
136-
break;
137-
case "v":
138-
result += String.fromCharCode(0x0b);
139-
break;
140-
case "f":
141-
result += "\f";
142-
break;
143-
case "r":
144-
result += "\r";
145-
break;
146-
case "\"":
147-
result += "\"";
148-
break;
149-
case "\\":
150-
result += "\\";
151-
break;
152-
case "x":
91+
var ch2 = map[ch];
92+
if (ch2 !== undefined) {
93+
result += ch2;
94+
} else if (ch == "x") {
15395
if (i + 2 < textLen) {
15496
try {
15597
result += String.fromCharCode(parseInt(text.substring(i + 1, i + 3), 16));
@@ -160,31 +102,25 @@ function Unescape(text) {
160102
} else {
161103
result += "\\x";
162104
}
163-
break;
164-
default:
105+
} else {
165106
if (!isNaN(ch)) {
166107
result += (ch !== '0') ? '$' + ch : '$&';
167108
} else {
168109
result += '\\' + ch;
169110
}
170-
break;
171111
}
172112
} else {
173113
result += ch;
174114
}
175-
break;
176-
default:
115+
} else {
177116
result += ch;
178-
break;
179117
}
180118
i++;
181119
}
182120
return result;
183121
}
184122

185-
function PluginOnEvent(eventType, obj) {
186-
mergeApp = obj;
187-
}
123+
function PluginOnEvent(eventType, obj) { mergeApp = obj; }
188124

189125
function quote(text) {
190126
return text.replace(/\\/g, "\\\\").replace(/\"/g, "\\\"").replace(/\r/g, "\\r").replace(/\n/g, "\\n").replace(/\t/g, "\\t")

Testing/PluginTests/PluginTests.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ function printPluginInfo(p) {
214214
WScript.Echo("");
215215
}
216216

217+
function AITest() {
218+
var asciiChars = "";
219+
var p = GetObject("script: " + ScriptFolder + "\\..\\..\\Plugins\\dlls\\AI.sct");
220+
printPluginInfo(p);
221+
222+
p.PluginOnEvent(0, MergeApp);
223+
224+
// AIConvertText
225+
p.PluginArguments = "Translate the given text into Japanese";
226+
WScript.Echo(p.AIConvertText("Hello World!"));
227+
}
228+
217229
function EditorAddinTest() {
218230
var asciiChars = "";
219231
var p = GetObject("script: " + ScriptFolder + "\\..\\..\\Plugins\\dlls\\editor addin.sct");
@@ -226,8 +238,8 @@ function EditorAddinTest() {
226238
p.PluginOnEvent(0, MergeApp);
227239

228240
// AIConvertText
229-
//p.PluginArguments = "Translate the given text into Japanese";
230-
//WScript.Echo(p.AIConvertText("Hello World!"));
241+
p.PluginArguments = "Translate the given text into Japanese";
242+
WScript.Echo(p.AIConvertText("Hello World!"));
231243

232244
// MakeUpper
233245
setTestName("MakeUpper");
@@ -668,6 +680,7 @@ function CompareMSPowerPointFilesTest() {
668680
p.PluginOnEvent(1, MergeApp);
669681
}
670682

683+
// AITest();
671684
EditorAddinTest();
672685
InsertDateTimeTest();
673686
IgnoreLeadingLineNumbersTest();

0 commit comments

Comments
 (0)