Skip to content

Commit

Permalink
加入自动sync脚本;添加Quantumultx和Loon;
Browse files Browse the repository at this point in the history
  • Loading branch information
cmliu committed Nov 17, 2024
1 parent 4be8254 commit 79d8556
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
40 changes: 40 additions & 0 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Upstream Sync

permissions:
contents: write

on:
schedule:
- cron: "0 0 * * *" # every day
workflow_dispatch:

jobs:
sync_latest_from_upstream:
name: Sync latest commits from upstream repo
runs-on: ubuntu-latest
if: ${{ github.event.repository.fork }}

steps:
# Step 1: run a standard checkout action
- name: Checkout target repo
uses: actions/checkout@v3

# Step 2: run the sync action
- name: Sync upstream changes
id: sync
uses: aormsby/[email protected]
with:
upstream_sync_repo: cmliu/CF-Workers-SUB
upstream_sync_branch: main
target_sync_branch: main
target_repo_token: ${{ secrets.GITHUB_TOKEN }} # automatically generated, no need to set

# Set test_mode true to run tests instead of the true action!!
test_mode: false

- name: Sync check
if: failure()
run: |
echo "[Error] 由于上游仓库的 workflow 文件变更,导致 GitHub 自动暂停了本次自动更新,你需要手动 Sync Fork 一次,详细教程请查看项目README.md "
echo "[Error] Due to a change in the workflow file of the upstream repository, GitHub has automatically suspended the scheduled automatic update. You need to manually sync your fork. Please refer to the project README.md for instructions. "
exit 1
12 changes: 11 additions & 1 deletion _worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default {
mytoken = env.TOKEN || mytoken;
BotToken = env.TGTOKEN || BotToken;
ChatID = env.TGID || ChatID;
TG = env.TG || TG;
TG = env.TG || TG;
subconverter = env.SUBAPI || subconverter;
if( subconverter.includes("http://") ){
subconverter = subconverter.split("//")[1];
Expand Down Expand Up @@ -88,6 +88,10 @@ export default {
订阅格式 = 'singbox';
} else if (userAgent.includes('surge') || ( url.searchParams.has('surge') && !userAgent.includes('subconverter'))){
订阅格式 = 'surge';
} else if (userAgent.includes('quantumult%20x') || (url.searchParams.has('quanx') && !userAgent.includes('subconverter'))){
订阅格式 = 'quanx';
} else if (userAgent.includes('loon') || (url.searchParams.has('loon') && !userAgent.includes('subconverter'))){
订阅格式 = 'loon';
}

let subconverterUrl ;
Expand All @@ -99,6 +103,8 @@ export default {
if (url.searchParams.has('clash')) 追加UA = 'clash';
else if(url.searchParams.has('singbox')) 追加UA = 'singbox';
else if(url.searchParams.has('surge')) 追加UA = 'surge';
else if(url.searchParams.has('quanx')) 追加UA = 'Quantumult%20X';
else if(url.searchParams.has('loon')) 追加UA = 'Loon';

const 请求订阅响应内容 = await getSUB(urls ,request ,追加UA, userAgentHeader);
console.log(请求订阅响应内容);
Expand Down Expand Up @@ -159,6 +165,10 @@ export default {
subconverterUrl = `${subProtocol}://${subconverter}/sub?target=singbox&url=${encodeURIComponent(订阅转换URL)}&insert=false&config=${encodeURIComponent(subconfig)}&emoji=true&list=false&tfo=false&scv=true&fdn=false&sort=false&new_name=true`;
} else if (订阅格式 == 'surge'){
subconverterUrl = `${subProtocol}://${subconverter}/sub?target=surge&url=${encodeURIComponent(订阅转换URL)}&insert=false&config=${encodeURIComponent(subconfig)}&emoji=true&list=false&tfo=false&scv=true&fdn=false&sort=false&new_name=true`;
} else if (订阅格式 == 'quanx'){
subconverterUrl = `${subProtocol}://${subconverter}/sub?target=quanx&url=${encodeURIComponent(订阅转换URL)}&insert=false&config=${encodeURIComponent(subconfig)}&emoji=true&list=false&tfo=false&scv=true&fdn=false&sort=false&udp=true`;
} else if (订阅格式 == 'loon'){
subconverterUrl = `${subProtocol}://${subconverter}/sub?target=loon&url=${encodeURIComponent(订阅转换URL)}&insert=false&config=${encodeURIComponent(subconfig)}&emoji=true&list=false&tfo=false&scv=true&fdn=false&sort=false`;
}
//console.log(订阅转换URL);
try {
Expand Down

0 comments on commit 79d8556

Please sign in to comment.