-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
90 lines (68 loc) · 2.32 KB
/
app.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function apply() {
let sourceText = source.value;
let sourceObject = {};
if(!sourceText.trim()){
console.error("Source config is empty!");
dest.value = "Source config is empty!" ;
return;
}
try {
sourceObject = JSON.parse(sourceText);
} catch (error) {
console.error(error);
dest.value = "Failed to parse Source Config , Error: \n\n" + error.message
return;
}
let proxyOutbound = sourceObject.outbounds.find(r => r.tag == "proxy");
if (!proxyOutbound) {
console.error("Can not find the outbound with proxy tag.");
dest.value = "Can not find the outbound with proxy tag.";
return;
}
proxyOutbound={...proxyOutbound};
let destObject = { ...sourceObject };
if (!proxyOutbound.streamSettings.sockopt) {
proxyOutbound.streamSettings.sockopt = {};
}
proxyOutbound.streamSettings.sockopt = {
...proxyOutbound.streamSettings.sockopt,
dialerProxy: "fragment",
tcpKeepAliveIdle: 100,
tcpNoDelay: true
};
destObject.outbounds = destObject.outbounds.filter(r => r.tag != "fragment" && r.tag != "proxy")
destObject.outbounds.unshift(
{
"tag": "fragment",
"protocol": "freedom",
"settings": {
"domainStrategy": "AsIs",
"fragment": {
"packets": fg_method.value,
"length": fg_length.value,
"interval": fg_interval.value
}
},
"streamSettings": {
"sockopt": {
"tcpKeepAliveIdle": 100,
"tcpNoDelay": true
}
}
}
);
destObject.outbounds.unshift(proxyOutbound);
dest.value = JSON.stringify(destObject, null, 4);
return true;
}
async function copyToClipboard(text){
// Get the text field
let copyText = document.getElementById("dest");
// Select the text field
copyText.select();
copyText.setSelectionRange(0, 99999); // For mobile devices
// Copy the text inside the text field
await navigator.clipboard.writeText(text);
// Alert the copied text
alert("Copied to clipboard!");
}