倒计时

一个适用于百度的倒计时器

  1. // ==UserScript==
  2. // @name 倒计时
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.1
  5. // @description 一个适用于百度的倒计时器
  6. // @match *://www.baidu.com/*
  7. // @author Jack
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12. (function () {
  13. 'use strict';
  14. var tmp = 0;
  15. var sec2 = 25;// 防止出现 BUG
  16. var sec = 0;// 用户倒计时秒数
  17. var stime = 25;// 防止出现 BUG 直接跳出 while 循环(没有执行)
  18. var time;// 计时器
  19. function Go (){// 控制函数
  20. console.log (' 倒计时剩余 % d 秒 ',sec2 - 1);// 日志
  21. sec2 = sec2 - 1;
  22. }
  23. function isNumber (val){// 判断参数是否是数字
  24. var regPos = /^[0-9]+.?[0-9]*/; // 判断是否是数字。
  25. if (regPos.test (val) ){
  26. return true;
  27. } else {
  28. return false;
  29. }
  30. }
  31. // 生成按钮
  32. $('.s_btn_wr,#s_btn_wr').after ('<input type="button" id="djs" value="开始倒计时" class="btn self-btn bg" style="float:right; font-size:14px; text-align:center; text-decoration:none; width:100px; height:33px; line-height:33px; margin-left:5px;-webkit-appearance:none;-webkit-border-radius:0;border: 0;color:#fff;letter-spacing:1px;background:#757555;border-bottom:1px solid #757555;outline:medium;" onmouseover="this.style.background=\'#757575\'" onmouseout="this.style.background=\'#757575">')
  33. $("#djs").click (djsh)
  34. function djsh (){// 处理函数
  35. console.log ('---------------------------------');// 日志文件
  36. console.log (' 倒计时 正式版 v1.0.1');
  37. console.log ('---------------------------------');
  38. console.log (' 按钮被点击 ');
  39. //-------------------------
  40. tmp = prompt (' 请输入你要倒计时的秒数:');// 输入
  41. if (isNumber (tmp)){// 如果输入的是一个数字
  42. sec = parseInt (tmp);// 转换成 int 整数类型
  43. console.log (' 开始倒计时 % d 秒 ',sec);// 日志
  44. //stime = sec;// 计数器
  45. sec2 = sec;
  46. time = setInterval (function (){Go ();if (sec2 <= 0){
  47. console.log (' 倒计时结束 ');
  48. alert (' 时间到!!!');
  49. clearInterval (time);
  50. return;}}, 1000);// 每过一秒,计数器递减
  51. if (sec2 <= 0){
  52. console.log (' 倒计时结束 ');
  53. alert (' 时间到!!!');
  54. clearInterval (time);
  55. return;
  56. }
  57. } else {
  58. console.log ('Error:输入错误 ');// 日志
  59. alert (' 请输入正确数字!!!');// 提示消息
  60. return;// 退出
  61. }
  62. return;
  63. };
  64.  
  65. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址