tiktok主页链接:利用cloudflare的workers功能制作分流链接(附跳转站外方案)
← 返回博客列表

tiktok主页链接:利用cloudflare的workers功能制作分流链接(附跳转站外方案)

2024/10/24·Tiktok教程

  tiktok内部浏览器打开效果如下 关于域名绑定可到油管观看教程 以下为worker代码 //

tiktok内部浏览器打开效果如下

图片[1]|5v|5v

关于域名绑定可到油管观看教程

图片[2]|5v|5v

以下为worker代码

// Cloudflare Workers KV 命名空间
const VISIT_COUNTERs = VISIT_COUNTER; // 替换为你的 KV 命名空间名称

async function handleRequest(request) {
    const url = new URL(request.url);

    if (url.pathname === '/increment-button-click') {
        // 更新按钮点击量
        await incrementCounter(VISIT_COUNTERs, 'button_clicks');
        return new Response('Button click counted', { status: 200 });
    }

    // 更新访问量计数
    const visitCount = await incrementCounter(VISIT_COUNTERs, 'page_views');

    // 获取按钮点击量
    const buttonClickCount = await VISIT_COUNTERs.get('button_clicks') || 0;

    // 获取用户的国家信息
    const country = request.headers.get('cf-ipcountry') || 'Unknown';

    // 返回包含自定义 HTML 的响应
    return new Response(getHtml(country, visitCount, buttonClickCount), {
        headers: { 'Content-Type': 'text/html' },
    });
}

// 更新计数器的函数
async function incrementCounter(kvNamespace, key) {
    const count = await kvNamespace.get(key) || 0;
    const newCount = parseInt(count) + 1;
    await kvNamespace.put(key, newCount);
    return newCount;
}

// 生成 HTML 页面
function getHtml(country, visitCount, buttonClickCount) {
    return `
    
    
    
        
        
        tiktok
        
        
            body {
                background-color: #ffffff;
                display: flex;
                justify-content: center;
                align-items: center;
                height: 100vh;
                font-family: Arial, sans-serif;
                margin: 0;
            }
            .container {
                text-align: center;
                max-width: 600px;
                padding: 20px;
                border: 1px solid #e0e0e0;
                border-radius: 8px;
                box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            }
            .profile-pic {
                width: 150px;
                height: 150px;
                border-radius: 50%;
                overflow: hidden;
                margin: 0 auto 20px;
            }
            .profile-pic img {
                width: 100%;
                height: 100%;
                object-fit: cover;
            }
            .message-title {
                font-weight: bold;
                margin-top: 20px;
                font-size: 18px;
            }
            .message-body {
                text-align: left;
                margin: 20px 0;
                line-height: 1.6;
                font-size: 16px;
            }
            .detail-button {
                display: inline-block;
                padding: 10px 20px;
                border: 2px solid #e0e0e0;
                border-radius: 8px;
                background-color: #ffffff;
                cursor: pointer;
                font-weight: bold;
                margin-top: 20px;
                text-align: center;
            }
            .detail-button:hover {
                background-color: #f0f0f0;
            }
            /* 灰色透明遮罩 */
            .overlay {
                position: fixed;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background: rgba(0, 0, 0, 0.7);
                display: none;
                justify-content: center;
                align-items: center;
                color: white;
                z-index: 1000;
            }
            .overlay .content {
                text-align: center;
            }
           /* 箭头样式 */
            .overlay .arrow {
                     position: absolute;
                top: 10px;
                right: 10px;
                width: 50px;
                height: 50px;
                background: url('https://imgsa.baidu.com/forum/pic/item/c2cec3fdfc03924578a70d2bc194a4c27d1e2580.jpg') no-repeat center;
                background-size: contain;
    }
            .overlay .message {
                margin-top: 40px;
                font-size: 18px;
            }
        
        
            function showOverlay() {
                const userAgent = navigator.userAgent.toLowerCase();
                if (userAgent.includes("musical")) {
                    document.querySelector('.overlay').style.display = 'flex';
                }
            }
    
            window.onload = showOverlay;
    
            async function redirectToLink() {
                const country = '${country}';
                await fetch('/increment-button-click'); // 更新按钮点击量
    
                if (country === 'GB') {
                    window.location.href = 'whatsapp://send/?phone=17879516980';
                } else if (country === 'JP') {
                    window.location.href = 'whatsapp://send/?phone=17879516980';
                } else {
                    window.location.href = 'whatsapp://send/?phone=17879516980';
                }
            }
        
    
    
        
            
                
            
            Dear TikTok User:
            
                Since you have good qualifications, we sincerely invite you to join the internal test of TikTok Shop e-commerce self-operated no-source mode! You don't need to stock goods. We support drop shipping. New merchants can apply for 2000USD traffic support. The number of places is limited. Click the button below to contact the account manager to join for free.
                This invitation information is valid until October 30, 2024!
            
            Join us
        
    
        
        
            
                
                Please click on the upper right corner and Open in browser
                tk.sex2x.com
            
        
    
    
    `;
}

addEventListener('fetch', event => {
    event.respondWith(handleRequest(event.request));
});

然后到KV新建一个名为VISIT_COUNTER的空间,用来储存计数器

图片[3]|5v|5v

然后回去刚刚创建的workers设置里把KV绑定一下,自定义域名最好也绑定一下

图片[4]|5v|5v

  • 增加防官方电脑审核
  • 增加域名随机后缀指向
  • 演示WhatsApp、Line跳出格式
/ Cloudflare Workers KV 命名空间
const VISIT_COUNTERs = VISIT_COUNTER; // 替换为你的 KV 命名空间名称



const IF_UA = 1     //1:开启防官方电脑审核
const WIN_UA_REurl = "https://www.tiktok.com/@memezar"   //防官方电脑审核地址
const domain = "https://de.cmcnca.com/"    //worker绑定的域名

async function handleRequest(request) {
    const url = new URL(request.url);
    
    // 如果是随机字符串路径,重定向到你的逻辑页面
    const randomPathPattern = /^\/[a-zA-Z0-9]{1,10}$/; // 假设随机字符串长度为1到10
    if (randomPathPattern.test(url.pathname)) {
        return Response.redirect(domain, 302);
    }

    if(IF_UA == 1){
        // 获取 User-Agent
        const userAgent = request.headers.get("User-Agent") || "";
        // 定义手机标识符
        const mobileIndicators = ["Android", "iPhone", "iPad", "iPod", "Windows Phone", "webOS", "BlackBerry"];
        // 判断是否为手机 UA
        const isMobile = mobileIndicators.some(indicator => userAgent.includes(indicator));
        // 如果是电脑 UA,重定向到 
        if (!isMobile) {
            return Response.redirect(WIN_UA_REurl, 302);
        }
    }

     

    if (url.pathname === '/increment-button-click') {
        // 更新按钮点击量
        await incrementCounter(VISIT_COUNTERs, 'button_clicks');
        return new Response('Button click counted', { status: 200 });
    }

    // 更新访问量计数
    const visitCount = await incrementCounter(VISIT_COUNTERs, 'page_views');

    // 获取按钮点击量
    const buttonClickCount = await VISIT_COUNTERs.get('button_clicks') || 0;

    // 获取用户的国家信息
    const country = request.headers.get('cf-ipcountry') || 'Unknown';

    // 返回包含自定义 HTML 的响应
    return new Response(getHtml(country, visitCount, buttonClickCount), {
        headers: { 'Content-Type': 'text/html' },
    });
}

// 更新计数器的函数
async function incrementCounter(kvNamespace, key) {
    const count = await kvNamespace.get(key) || 0;
    const newCount = parseInt(count) + 1;
    await kvNamespace.put(key, newCount);
    return newCount;
}

// 生成 HTML 页面
function getHtml(country, visitCount, buttonClickCount) {
    return `
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>tiktok</title>
    <link rel="icon" href="https://www.tiktok.com/favicon.ico" type="image/x-icon">
    <style>
        body {
            background-color: #ffffff;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            font-family: Arial, sans-serif;
            margin: 0;
        }
        .container {
            text-align: center;
            max-width: 600px;
            padding: 20px;
            border: 1px solid #e0e0e0;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        .profile-pic {
            width: 150px;
            height: 150px;
            border-radius: 50%;
            overflow: hidden;
            margin: 0 auto 20px;
        }
        .profile-pic img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .message-title {
            font-weight: bold;
            margin-top: 20px;
            font-size: 18px;
        }
        .message-body {
            text-align: left;
            margin: 20px 0;
            line-height: 1.6;
            font-size: 16px;
        }
        .detail-button {
            display: inline-block;
            padding: 10px 20px;
            border: 2px solid #e0e0e0;
            border-radius: 8px;
            background-color: #ffffff;
            cursor: pointer;
            font-weight: bold;
            margin-top: 20px;
            text-align: center;
        }
        .detail-button:hover {
            background-color: #f0f0f0;
        }
        /* 灰色透明遮罩 */
        .overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            display: none;
            justify-content: center;
            align-items: center;
            color: white;
            z-index: 1000;
            backdrop-filter: blur(8px); /* 调整模糊程度 */
        }
        .overlay .content {
            text-align: center;
        }
        /* 箭头样式 */
        .overlay .arrow {
            position: absolute;
            top: 10px;
            right: 10px;
            width: 50px;
            height: 50px;
            background: url('') no-repeat center;
            background-size: contain;
        }
        .overlay .message {
            margin-top: 40px;
            font-size: 18px;
        }
        .btn{
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 8px;
            width: 100px;
            height: 50px
        }
    </style>
    <script>
        window.onload = showOverlay;
        async function redirectToLink() {
            const country = '${country}';
            await fetch('/increment-button-click'); // 更新按钮点击量
			let linkToCopy;
            if (country === 'DE') {
                // 德国链接数组
                const deLinks = [
                    'line://ti/p/15878206798',
                    'line://ti/p//16723673953',
                    'line://ti/p//15878207105',
                    'line://ti/p//12368057606',
                    'line://ti/p//16723693467',
                    'line://ti/p//12368057694', 
                ];
                    // 随机选择一个链接
                    const randomLink = deLinks[Math.floor(Math.random() * deLinks.length)];
                    window.location.href = randomLink;
            } else if (country === 'JP') {
                window.location.href = 'whatsapp://send?phone=15878206798&text=hi';
            } else {
                window.location.href = 'https://tiktok.com';
            }
			// 将链接复制到剪贴板
        }
    </script>
</head>
<body>
<div class="container">
    <div class="profile-pic">
        <img src="https://www.strategyand.pwc.com/gx/en/alumni/middle-east/featured-alumni/teaser-alumni-shant-oknayan.gif" alt="Profile Picture">
    </div>
    <div class="message-body">
    Jeden Tag 1 bis 3 Stunden von zu Hause aus arbeiten und dabei ein verlockendes Gehalt von 200 bis 400 Euro verdienen. Diese Tätigkeit ist besonders geeignet für diejenigen, die ihr Einkommen in ihrer Freizeit aufbessern möchten. <strong>Wenn Sie 22 Jahre oder älter sind</strong>, laden wir Sie herzlich ein, unserem Team beizutreten!
    </div>
    <div class="detail-button" onclick="redirectToLink()">Beitreten</div>
</div>
</body>
</html>
    `;
}

addEventListener('fetch', event => {
    event.respondWith(handleRequest(event.request));
});