B2B网络软件

 找回密码
 立即注册 审核网站号:QQ:896757558
搜索
查看: 277|回复: 0
打印 上一主题 下一主题

安卓手机脚本多种倒计时显示方式

[复制链接]

1186

主题

1191

帖子

8021

积分

abc

Rank: 9Rank: 9Rank: 9

积分
8021
跳转到指定楼层
楼主
发表于 2026-3-25 10:10:40 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
安卓手机脚本多种倒计时显示方式
安卓手机脚本多种倒计时显示方式 B2B网络软件

安卓手机脚本多种倒计时显示方式 B2B网络软件

  1. /*
  2.    倒计时工具函数 - 可直接在其他脚本中调用
  3.    提供多种倒计时显示方式
  4.    //🍎交流 QQ 群 711841924 群一,苹果内测群,528816639
  5. */

  6. /**
  7. * 格式化时间函数(内部使用)
  8. * @param {number} secs - 秒数
  9. * @returns {string} 格式化后的时间字符串
  10. */
  11. function formatTime(secs) {
  12.     var h = Math.floor(secs / 3600);
  13.     var m = Math.floor((secs % 3600) / 60);
  14.     var s = secs % 60;
  15.    
  16.     var str = "";
  17.     if (h > 0) str += h + "时";
  18.     if (m > 0 || h > 0) str += m + "分";
  19.     str += s + "秒";
  20.     return str;
  21. }

  22. /**
  23. * 在固定位置显示倒计时(悬浮窗方式)
  24. * @param {number} seconds - 倒计时秒数
  25. * @param {object} options - 配置选项
  26. */
  27. function showCountdownFloat(seconds, options) {
  28.     options = options || {};
  29.     var config = {
  30.         x: options.x || (screen.getScreenWidth() - 400) / 2,  // X 坐标
  31.         y: options.y || (screen.getScreenHeight() - 150),     // Y 坐标
  32.         width: options.width || 400,                          // 宽度
  33.         height: options.height || 60,                         // 高度
  34.         textColor: options.textColor || '#00ff00',            // 文字颜色
  35.         bgColor: options.bgColor || '#000000',                // 背景颜色
  36.         textSize: options.textSize || 24                      // 字号
  37.     };
  38.    
  39.     // 创建悬浮窗
  40.     var countdownUI = new floatUI();
  41.     countdownUI.loadXML(
  42.         '<LinearLayout orientation="vertical" w="' + config.width + '" h="' + config.height + '" gravity="center">' +
  43.         '  <TextView id="countdownText" textColor="' + config.textColor + '" background="' + config.bgColor + '" layout_width="wrap_content" layout_height="wrap_content" textSize="' + config.textSize + 'sp" />' +
  44.         '</LinearLayout>'
  45.     );
  46.    
  47.     var countdownText = countdownUI.findViewById('countdownText');
  48.    
  49.     if (countdownText) {
  50.         // 设置位置
  51.         setTimeout(function() {
  52.             countdownUI.setPosition(config.x, config.y);
  53.         }, 100);
  54.         
  55.         // 开始倒计时
  56.         var remaining = seconds;
  57.         countdownText.setText(formatTime(remaining));
  58.         
  59.         var timer = setInterval(function() {
  60.             remaining--;
  61.             
  62.             if (remaining > 0) {
  63.                 countdownText.setText(formatTime(remaining));
  64.                
  65.                 // 最后 10 秒变红
  66.                 if (remaining <= 10) {
  67.                     countdownText.setTextColor(android.graphics.Color.RED);
  68.                 }
  69.             } else {
  70.                 clearInterval(timer);
  71.                 countdownText.setText("时间到!");
  72.                 countdownText.setTextColor(android.graphics.Color.YELLOW);
  73.                 toast.show("倒计时结束!");
  74.             }
  75.         }, 1000);
  76.         
  77.         return {
  78.             stop: function() {
  79.                 clearInterval(timer);
  80.             },
  81.             update: function(newSeconds) {
  82.                 remaining = newSeconds;
  83.             }
  84.         };
  85.     }
  86.    
  87.     return null;
  88. }

  89. /**
  90. * 使用 Toast 显示倒计时(简单方式)
  91. * @param {number} seconds - 倒计时秒数
  92. */
  93. function showCountdownToast(seconds) {
  94.     var remaining = seconds;
  95.    
  96.     function formatTime(secs) {
  97.         var h = Math.floor(secs / 3600);
  98.         var m = Math.floor((secs % 3600) / 60);
  99.         var s = secs % 60;
  100.         return h + "时" + m + "分" + s + "秒";
  101.     }
  102.    
  103.     var interval = setInterval(function() {
  104.         remaining--;
  105.         
  106.         if (remaining > 0) {
  107.             toast.show("⏱️ 剩余:" + formatTime(remaining));
  108.         } else {
  109.             clearInterval(interval);
  110.             toast.show("✅ 时间到!");
  111.         }
  112.     }, 1000);
  113. }

  114. /**
  115. * 在日志中显示倒计时
  116. * @param {number} seconds - 倒计时秒数
  117. * @param {string} prefix - 日志前缀
  118. */
  119. function showCountdownLog(seconds, prefix) {
  120.     prefix = prefix || "⏱️";
  121.     var remaining = seconds;
  122.    
  123.     function formatTime(secs) {
  124.         var h = Math.floor(secs / 3600);
  125.         var m = Math.floor((secs % 3600) / 60);
  126.         var s = secs % 60;
  127.         
  128.         var str = "";
  129.         if (h > 0) str += h + "时";
  130.         if (m > 0 || h > 0) str += m + "分";
  131.         str += s + "秒";
  132.         return str;
  133.     }
  134.    
  135.     printl(prefix + " 倒计时开始:" + formatTime(remaining));
  136.    
  137.     var timer = setInterval(function() {
  138.         remaining--;
  139.         
  140.         if (remaining > 0) {
  141.             if (remaining % 5 === 0) { // 每 5 秒打印一次
  142.                 printl(prefix + " 剩余:" + formatTime(remaining));
  143.             }
  144.         } else {
  145.             clearInterval(timer);
  146.             printl(prefix + " ⏰ 时间到!");
  147.         }
  148.     }, 1000);
  149. }

  150. /**
  151. * 倒计时到指定时间点
  152. * @param {string} targetTime - 目标时间,格式 'HH:mm:ss' 或 'HH:mm'
  153. */
  154. function countdownTo(targetTime) {
  155.     var now = new Date();
  156.     var parts = targetTime.split(':');
  157.     var targetHour = parseInt(parts[0]);
  158.     var targetMin = parseInt(parts[1]);
  159.     var targetSec = parts.length > 2 ? parseInt(parts[2]) : 0;
  160.    
  161.     var target = new Date();
  162.     target.setHours(targetHour, targetMin, targetSec, 0);
  163.    
  164.     // 如果目标时间已过,设为明天
  165.     if (target <= now) {
  166.         target.setDate(target.getDate() + 1);
  167.     }
  168.    
  169.     var diffMs = target - now;
  170.     var diffSeconds = Math.floor(diffMs / 1000);
  171.    
  172.     printl("&#127919; 目标时间:" + targetTime);
  173.     printl("⏱️ 剩余时间:" + diffSeconds + "秒");
  174.    
  175.     // 显示倒计时悬浮窗
  176.     return showCountdownFloat(diffSeconds, {
  177.         y: screen.getScreenHeight() - 200
  178.     });
  179. }

  180. // 导出函数供外部使用
  181. this.showCountdownFloat = showCountdownFloat;
  182. this.showCountdownToast = showCountdownToast;
  183. this.showCountdownLog = showCountdownLog;
  184. this.countdownTo = countdownTo;

  185. // 使用示例
  186. if (typeof main !== 'function') {
  187.     printl("\n========== 倒计时工具函数使用示例 ==========\n");
  188.    
  189.     // 示例 1: 简单的 30 秒倒计时(悬浮窗)
  190.     printl("示例 1: 30 秒倒计时悬浮窗");
  191.     showCountdownFloat(30, { y: screen.getScreenHeight() - 150 });
  192.    
  193.     // 示例 2: 使用 Toast 显示倒计时
  194.     printl("示例 2: Toast 倒计时");
  195.     showCountdownToast(10);
  196.    
  197.     // 示例 3: 在日志中显示倒计时
  198.     printl("示例 3: 日志倒计时");
  199.     showCountdownLog(20, "⏱️");
  200.    
  201.     // 示例 4: 倒计时到指定时间
  202.     printl("示例 4: 倒计时到 18:30:00");
  203.     countdownTo("18:30:00");
  204.    
  205.     printl("\n============================================\n");
  206.     printl("&#128161; 提示:取消注释上面的示例代码来使用对应功能");
  207. }
复制代码




回复

使用道具 举报

本版积分规则

关闭

QQ|»营销软件综合讨论|»营销软件有问必答|»营销软件教程专区|»营销软件POST脚本分享|»营销软件普通脚本分享|»营销软件软件资讯|»营销软件精品软件|»营销软件更新公告|营销软件|B2B软件|B2B网络软件 ( 京ICP备09078825号 )本网站开发的营销软件是一款新的网络营销软件,这款营销可以去网站软件,博客软件,B2B软件,分类信息网发贴,可以抢沙发,可以到百度文库上传WORD文档,可以到一些是相册网站自动上传图片,这个自动发帖软件自带云蜘蛛,加快收录,有6种对接打码接口,方便,效率高,速度快,而且对拖动的验证码全网第一家独家支持,全部原创技术,独家研发,正版原创带版权软件。选择万能营销软件,就选择了一种赚钱的效率,从没有被超越过,一直在努力研发新技术。放飞梦想,解放双手,来点创意,成就你的梦想,就在万能营销软件开始

map2

GMT+8, 2026-10-3 13:09 , Processed in 0.288005 second(s), 36 queries .

快速回复 返回顶部 返回列表