更新README.md,增加访客订阅说明和注意事项;修改_worker.js,添加访客订阅功能及相关逻辑

This commit is contained in:
cmliu
2025-01-22 02:48:53 +08:00
parent b1217f6ee3
commit e404e658fb
2 changed files with 71 additions and 15 deletions

View File

@@ -1,7 +1,8 @@
// 部署完成后在网址后面加上这个,获取自建节点和机场聚合节点,/?token=auto或/auto或
let mytoken = 'auto'; //可以随便取或者uuid生成https://1024tools.com/uuid
let mytoken = 'auto';
let guestToken = ''; //可以随便取或者uuid生成https://1024tools.com/uuid
let BotToken = ''; //可以为空,或者@BotFather中输入/start/newbot并关注机器人
let ChatID = ''; //可以为空,或者@userinfobot中获取/start
let TG = 0; //小白勿动, 开发者专用1 为推送所有的访问信息0 为不推送订阅转换后端的访问信息与异常访问
@@ -50,6 +51,9 @@ export default {
currentDate.setHours(0, 0, 0, 0);
const timeTemp = Math.ceil(currentDate.getTime() / 1000);
const fakeToken = await MD5MD5(`${mytoken}${timeTemp}`);
guestToken = env.GUESTTOKEN || env.GUEST || guestToken;
if (!guestToken) guestToken = await MD5MD5(mytoken);
const 访客订阅 = guestToken;
//console.log(`${fakeUserID}\n${fakeHostName}`); // 打印fakeID
let UD = Math.floor(((timestamp - Date.now()) / timestamp * total * 1099511627776) / 2);
@@ -57,7 +61,7 @@ export default {
let expire = Math.floor(timestamp / 1000);
SUBUpdateTime = env.SUBUPTIME || SUBUpdateTime;
if (!(token == mytoken || token == fakeToken || url.pathname == ("/" + mytoken) || url.pathname.includes("/" + mytoken + "?"))) {
if (!([mytoken, fakeToken, 访客订阅].includes(token) || url.pathname == ("/" + mytoken) || url.pathname.includes("/" + mytoken + "?"))) {
if (TG == 1 && url.pathname !== "/" && url.pathname !== "/favicon.ico") await sendMessage(`#异常访问 ${FileName}`, request.headers.get('CF-Connecting-IP'), `UA: ${userAgent}</tg-spoiler>\n域名: ${url.hostname}\n<tg-spoiler>入口: ${url.pathname + url.search}</tg-spoiler>`);
if (env.URL302) return Response.redirect(env.URL302, 302);
else if (env.URL) return await proxyURL(env.URL, url);
@@ -72,7 +76,7 @@ export default {
await 迁移地址列表(env, 'LINK.txt');
if (userAgent.includes('mozilla') && !url.search) {
await sendMessage(`#编辑订阅 ${FileName}`, request.headers.get('CF-Connecting-IP'), `UA: ${userAgentHeader}</tg-spoiler>\n域名: ${url.hostname}\n<tg-spoiler>入口: ${url.pathname + url.search}</tg-spoiler>`);
return await KV(request, env, 'LINK.txt');
return await KV(request, env, 'LINK.txt', 访客订阅);
} else {
MainData = await env.KV.get('LINK.txt') || MainData;
}
@@ -488,7 +492,7 @@ async function 迁移地址列表(env, txt = 'ADD.txt') {
return false;
}
async function KV(request, env, txt = 'ADD.txt') {
async function KV(request, env, txt = 'ADD.txt', guest) {
const url = new URL(request.url);
try {
// POST请求处理
@@ -602,6 +606,31 @@ async function KV(request, env, txt = 'ADD.txt') {
loon订阅地址:<br>
<a href="javascript:void(0)" onclick="copyToClipboard('https://${url.hostname}/${mytoken}?loon','qrcode_5')" style="color:blue;text-decoration:underline;cursor:pointer;">https://${url.hostname}/${mytoken}?loon</a><br>
<div id="qrcode_5" style="margin: 10px 10px 10px 10px;"></div>
&nbsp;&nbsp;<strong><a href="javascript:void(0);" id="noticeToggle" onclick="toggleNotice()">查看访客订阅∨</a></strong><br>
<div id="noticeContent" class="notice-content" style="display: none;">
---------------------------------------------------------------<br>
访客订阅只能使用订阅功能,无法查看配置页!<br>
GUEST访客订阅TOKEN: <strong>${guest}</strong><br>
---------------------------------------------------------------<br>
自适应订阅地址:<br>
<a href="javascript:void(0)" onclick="copyToClipboard('https://${url.hostname}/sub?token=${guest}','guest_0')" style="color:blue;text-decoration:underline;cursor:pointer;">https://${url.hostname}/sub?token=${guest}</a><br>
<div id="guest_0" style="margin: 10px 10px 10px 10px;"></div>
Base64订阅地址:<br>
<a href="javascript:void(0)" onclick="copyToClipboard('https://${url.hostname}/sub?token=${guest}&b64','guest_1')" style="color:blue;text-decoration:underline;cursor:pointer;">https://${url.hostname}/sub?token=${guest}&b64</a><br>
<div id="guest_1" style="margin: 10px 10px 10px 10px;"></div>
clash订阅地址:<br>
<a href="javascript:void(0)" onclick="copyToClipboard('https://${url.hostname}/sub?token=${guest}&clash','guest_2')" style="color:blue;text-decoration:underline;cursor:pointer;">https://${url.hostname}/sub?token=${guest}&clash</a><br>
<div id="guest_2" style="margin: 10px 10px 10px 10px;"></div>
singbox订阅地址:<br>
<a href="javascript:void(0)" onclick="copyToClipboard('https://${url.hostname}/sub?token=${guest}&sb','guest_3')" style="color:blue;text-decoration:underline;cursor:pointer;">https://${url.hostname}/sub?token=${guest}&sb</a><br>
<div id="guest_3" style="margin: 10px 10px 10px 10px;"></div>
surge订阅地址:<br>
<a href="javascript:void(0)" onclick="copyToClipboard('https://${url.hostname}/sub?token=${guest}&surge','guest_4')" style="color:blue;text-decoration:underline;cursor:pointer;">https://${url.hostname}/sub?token=${guest}&surge</a><br>
<div id="guest_4" style="margin: 10px 10px 10px 10px;"></div>
loon订阅地址:<br>
<a href="javascript:void(0)" onclick="copyToClipboard('https://${url.hostname}/sub?token=${guest}&loon','guest_5')" style="color:blue;text-decoration:underline;cursor:pointer;">https://${url.hostname}/sub?token=${guest}&loon</a><br>
<div id="guest_5" style="margin: 10px 10px 10px 10px;"></div>
</div>
---------------------------------------------------------------<br>
################################################################<br>
订阅转换配置<br>
@@ -760,6 +789,23 @@ async function KV(request, env, txt = 'ADD.txt') {
timer = setTimeout(saveContent, 5000);
});
}
function toggleNotice() {
const noticeContent = document.getElementById('noticeContent');
const noticeToggle = document.getElementById('noticeToggle');
if (noticeContent.style.display === 'none' || noticeContent.style.display === '') {
noticeContent.style.display = 'block';
noticeToggle.textContent = '隐藏访客订阅∧';
} else {
noticeContent.style.display = 'none';
noticeToggle.textContent = '查看访客订阅∨';
}
}
// 初始化 noticeContent 的 display 属性
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('noticeContent').style.display = 'none';
});
</script>
</body>
</html>