瀏覽代碼

share claim bonus 超过2秒跳转到下载页

guoziyun 10 月之前
父節點
當前提交
124c372724
共有 2 個文件被更改,包括 59 次插入2 次删除
  1. 4 2
      routes/v2/share.js
  2. 55 0
      views/v2/share.ejs

+ 4 - 2
routes/v2/share.js

@@ -19,8 +19,10 @@ router.get('/:id', function (req, res, next) {
     let applink = `https://art.pcoloring.com${req.originalUrl}`;
     let downlink = `https://pcoloring.com/anc/`;
 
-    let openapplink = applink.concat(req.originalUrl.includes('?') ? '&check=1' : '?check=1');
-
+    let openapplink = applink;
+    if (!req.originalUrl.includes('check')) {
+      openapplink = applink.concat(req.originalUrl.includes('?') ? '&check=1' : '?check=1');
+    }
 
     const userAgent = req.headers['user-agent'];
     console.log('User-Agent:', userAgent);

+ 55 - 0
views/v2/share.ejs

@@ -406,6 +406,60 @@
 
   <script>
 
+    // claim bonus 超过2秒自动跳转到下载页
+    document.addEventListener('DOMContentLoaded', function () {
+      // 检查 URL 中是否包含 check=1 参数
+      const urlParams = new URLSearchParams(window.location.search);
+      const hasCheckParam = urlParams.has('check');
+
+      console.log(window.location.search);
+
+      console.log('hasCheckParam:', hasCheckParam);
+
+      // 定义下载页面 URL(与 Download App 按钮保持一致)
+      const downloadUrl = document.querySelector('.btn-secondary').href;
+
+      // 如果是带 check 参数的页面,则执行拉起检测逻辑
+      if (hasCheckParam) {
+        let appLaunched = false;
+
+        // 监听页面可见性变化(判断 App 是否被拉起)
+        document.addEventListener('visibilitychange', function () {
+          if (document.hidden) {
+            // 页面被隐藏,说明 App 可能被成功拉起
+            appLaunched = true;
+          }
+        });
+
+        // 监听页面焦点变化(辅助判断)
+        window.addEventListener('blur', function () {
+          appLaunched = true;
+        });
+
+        // 2 秒后检查是否成功拉起 App
+        setTimeout(function () {
+          if (!appLaunched) {
+            // 未拉起 App,跳转到下载页
+            window.location.href = downloadUrl;
+          }
+        }, 2000);
+      }
+
+      // 为 Claim Bonus 按钮添加防重复点击逻辑(可选)
+      const claimButton = document.querySelector('.btn-primary');
+      if (claimButton) {
+        claimButton.addEventListener('click', function (e) {
+          // 只有在没有 check 参数时才允许跳转(避免循环跳转)
+          if (!hasCheckParam) {
+            // 可添加加载状态
+            this.textContent = 'Launching...';
+            this.disabled = true;
+          }
+        });
+      }
+    });
+
+
     // 图片加载逻辑
     const header = document.getElementById('header');
     const posterImg = document.getElementById('poster-img');
@@ -449,6 +503,7 @@
     } else {
       wechatGuideOverlay.classList.remove('active'); // 确保隐藏
     }
+
   </script>
 </body>