-
Notifications
You must be signed in to change notification settings - Fork 6
/
EncodingConvert.js
65 lines (57 loc) · 2.5 KB
/
EncodingConvert.js
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
// EncodingConvert
// Authors: @Chaoses-Ib, @laoqiuqiu
// Version: 220619.2
// Homepage: https://github.com/Chaoses-Ib/IbDOpusScripts
// Use in command:
// Rename PRESET="EncodingConvert" SCRIPTARG srcEncoding:1 dstEncoding:3
var encodings = ['utf-8', 'gbk', 'big5', 'shift-jis', 'euc-kr'];
function OnGetNewName(getNewNameData)
{
return encodingConvert(encodings[getNewNameData.custom.srcEncoding], encodings[getNewNameData.custom.dstEncoding], getNewNameData.newname);
}
function OnGetCustomFields(getFieldData)
{
// Default: gbk, shift-jis
srcCombo = DOpus.Create.Vector(1, DOpus.strings.Get('utf-8'), DOpus.strings.Get('gbk'), DOpus.strings.Get('big5'), DOpus.strings.Get('shift-jis'), DOpus.strings.Get('euc-kr'));
getFieldData.fields.srcEncoding = srcCombo;
getFieldData.field_labels('srcEncoding') = DOpus.strings.Get('srcEncoding');
dstCombo = DOpus.Create().Vector(srcCombo);
dstCombo(0) = 3;
getFieldData.fields.dstEncoding = dstCombo;
getFieldData.field_labels('dstEncoding') = DOpus.strings.Get('dstEncoding');
}
function encodingConvert(srcEncoding, dstEncoding, string) {
// Encodings: https://docs.microsoft.com/en-us/previous-versions/exchange-server/exchange-10/ms526296(v=exchg.10)
var stream = new ActiveXObject('Adodb.Stream');
stream.Open();
stream.Charset = srcEncoding;
stream.WriteText(string);
stream.Position = 0;
stream.Charset = dstEncoding;
var result = stream.ReadText();
stream.Close();
return result;
}
==SCRIPT RESOURCES
<resources>
<resource type="strings">
<strings lang="english">
<string id="srcEncoding" text="Source encoding" />
<string id="dstEncoding" text="Destination encoding" />
<string id="utf-8" text="UTF-8" />
<string id="gbk" text="GBK (Simplified Chinese)" />
<string id="big5" text="Big5 (Traditional Chinese)" />
<string id="shift-jis" text="Shift-JIS (Japanese)" />
<string id="euc-kr" text="EUC-KR (Korean)" />
</strings>
<strings lang="chs">
<string id="srcEncoding" text="源编码" />
<string id="dstEncoding" text="目标编码" />
<string id="utf-8" text="UTF-8" />
<string id="gbk" text="GBK(简体中文)" />
<string id="big5" text="Big5(繁体中文)" />
<string id="shift-jis" text="Shift-JIS(日语)" />
<string id="euc-kr" text="EUC-KR(韩语)" />
</strings>
</resource>
</resources>