Skip to content

Commit

Permalink
fix: wrong custom rules
Browse files Browse the repository at this point in the history
  • Loading branch information
7Sageer committed Aug 25, 2024
1 parent 0ad8f1a commit 0ebe3c4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/BaseConfigBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export class BaseConfigBuilder {
constructor(inputString, baseConfig) {
this.inputString = inputString;
this.config = DeepCopy(baseConfig);
this.customRules = [];
}

async build() {
Expand Down
14 changes: 8 additions & 6 deletions src/ClashConfigBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ export class ClashConfigBuilder extends BaseConfigBuilder {
}
});

this.customRules.forEach(rule => {
this.config['proxy-groups'].push({
type: "select",
name: rule.outbound,
proxies: ['🚀 节点选择', ...proxyList]
if (Array.isArray(this.customRules)) {
this.customRules.forEach(rule => {
this.config['proxy-groups'].push({
type: "select",
name: rule.name,
proxies: ['🚀 节点选择', ...proxyList]
});
});
});
}

this.config['proxy-groups'].push({
type: "select",
Expand Down
14 changes: 8 additions & 6 deletions src/SingboxConfigBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ export class ConfigBuilder extends BaseConfigBuilder {
}
});

this.customRules.forEach(rule => {
this.config.outbounds.push({
type: "selector",
tag: rule.outbound,
outbounds: ['🚀 节点选择', ...proxyList]
if (Array.isArray(this.customRules)) {
this.customRules.forEach(rule => {
this.config.outbounds.push({
type: "selector",
tag: rule.name,
outbounds: ['🚀 节点选择', ...proxyList]
});
});
});
}

this.config.outbounds.push({
type: "selector",
Expand Down
22 changes: 12 additions & 10 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,15 @@ export function generateRules(selectedRules = [], customRules = []) {
}
});

customRules.forEach(rule => {
rules.push({
site_rules: rule.sites,
ip_rules: rule.ips,
outbound: rule.outbound
});
});
if (customRules.length > 0) {
customRules.forEach((rule) => {
rules.push({
site_rules: rule.site.split(','),
ip_rules: rule.ip.split(','),
outbound: rule.name
});
});
}

return rules;
}
Expand Down Expand Up @@ -206,10 +208,10 @@ export function generateRuleSets(selectedRules = [], customRules = []) {
rule.ip_rules.forEach(ipRule => ipRuleSets.add(ipRule));
}
});

customRules.forEach(rule => {
rule.sites.forEach(site => siteRuleSets.add(site));
rule.ips.forEach(ip => ipRuleSets.add(ip));
rule.site.split(',').forEach(site => siteRuleSets.add(site.trim()));
siteRuleSets.add(rule.ip.trim());
});

const site_rule_sets = Array.from(siteRuleSets).map(rule => ({
Expand Down
8 changes: 8 additions & 0 deletions src/htmlBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,13 @@ const submitFormFunction = () => `
.map(checkbox => checkbox.value);
}
// 收集自定义规则数据
const customRules = Array.from(document.querySelectorAll('.custom-rule')).map(rule => ({
site: rule.querySelector('input[name="customRuleSite[]"]').value,
ip: rule.querySelector('input[name="customRuleIP[]"]').value,
name: rule.querySelector('input[name="customRuleName[]"]').value
}));
const xrayUrl = \`\${window.location.origin}/xray?config=\${encodeURIComponent(inputString)}\`;
const singboxUrl = \`\${window.location.origin}/singbox?config=\${encodeURIComponent(inputString)}&selectedRules=\${encodeURIComponent(JSON.stringify(selectedRules))}&customRules=\${encodeURIComponent(JSON.stringify(customRules))}\`;
const clashUrl = \`\${window.location.origin}/clash?config=\${encodeURIComponent(inputString)}&selectedRules=\${encodeURIComponent(JSON.stringify(selectedRules))}&customRules=\${encodeURIComponent(JSON.stringify(customRules))}\`;
Expand Down Expand Up @@ -709,6 +716,7 @@ const customRuleFunctions = `
const customRulesDiv = document.getElementById('customRules');
const newRuleDiv = document.createElement('div');
newRuleDiv.className = 'custom-rule mb-3 p-3 border rounded';
newRuleDiv.dataset.ruleId = customRuleCount++;
newRuleDiv.innerHTML = \`
<div class="mb-2">
<label class="form-label">Geo-Site Rule Sets</label>
Expand Down

0 comments on commit 0ebe3c4

Please sign in to comment.