|
|
°²×¿½Å±¾Ïß³ÌÈ«¾Ö±äÁ¿H5¿ÉÊÓ»¯¿ØÖÆÌ¨
- //ÓöàÏß³ÌÒì²½×ÓÈÎÎñÔËÐÐÒ»¸ö¶¨Ê±
- // AIWROK ¶àÏß³ÌʵʱÈÕÖ¾¼à¿ØÏµÍ³
- var threads = {};
- var threadStatus = {
- countdown: 'running',
- randomLetter: 'running',
- randomTime: 'running',
- randomNumber: 'running'
- };
- // ¸¨Öúº¯Êý£º½«Ó¢ÎÄ״̬ת»»ÎªÖÐÎÄ
- function getStatusText(status) {
- if(status === 'running') return 'ÕýÔÚÔËÐÐ';
- if(status === 'stopping') return 'ÕýÔÚÍ£Ö¹';
- if(status === 'stopped') return 'ÒÑÍ£Ö¹';
- return status;
- }
- // ÈÕÖ¾Êä³öº¯Êý - ͬʱÊä³öµ½¿ØÖÆÌ¨ºÍH5½çÃæ
- function logToH5(message, level) {
- // Êä³öµ½¿ØÖÆÌ¨
- console.log(message);
-
- // Êä³öµ½H5½çÃæ£¨Èç¹ûLogManagerH5¿ÉÓã©
- if(typeof LogManagerH5 !== 'undefined' && LogManagerH5.info) {
- try {
- switch(level) {
- case 'success':
- LogManagerH5.success(message);
- break;
- case 'warn':
- LogManagerH5.warn(message);
- break;
- case 'error':
- LogManagerH5.error(message);
- break;
- case 'gold':
- LogManagerH5.gold(message);
- break;
- default:
- LogManagerH5.info(message);
- }
- } catch(e) {
- // Èç¹ûH5ÈÕ־ʧ°Ü£¬ÖÁÉÙ¿ØÖÆÌ¨ÓÐÊä³ö
- }
- }
- }
- // Ïß³Ì1: µ¹¼ÆÊ±Ïß³Ì (ÿ10·ÖÖÓµ¹¼ÆÊ±)
- threads.countdown = new thread().runJsCode(function fun(){
- logToH5("[µ¹¼ÆÊ±Ïß³Ì] Æô¶¯ - ¿ªÊ¼10·ÖÖÓµ¹¼ÆÊ±", 'info');
- var startTime = Date.now();
- while(threadStatus.countdown === 'running') {
- var elapsed = Math.floor((Date.now() - startTime) / 1000);
- var remaining = 600 - elapsed; // 10·ÖÖÓ = 600Ãë
- if(remaining <= 0) {
- logToH5("[µ¹¼ÆÊ±Ïß³Ì] µ¹¼ÆÊ±½áÊø!", 'success');
- break;
- }
- logToH5("[µ¹¼ÆÊ±Ïß³Ì] Ê£Óàʱ¼ä: " + remaining + " Ãë", 'info');
- sleep.second(1);
- }
- threadStatus.countdown = 'stopped';
- logToH5("[µ¹¼ÆÊ±Ïß³Ì] ÒÑÍ£Ö¹", 'warn');
- }, "-µ¹¼ÆÊ±Ïß³Ì")
- // Ïß³Ì2: Ëæ»ú×ÖĸÉú³ÉÏß³Ì
- threads.randomLetter = new thread().runJsCode(function fun(){
- logToH5("[Ëæ»ú×ÖĸÏß³Ì] Æô¶¯", 'info');
- while(threadStatus.randomLetter === 'running') {
- var letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
- var randomIndex = Math.floor(Math.random() * letters.length);
- var randomLetter = letters.charAt(randomIndex);
- logToH5("[Ëæ»ú×ÖĸÏß³Ì] Éú³ÉËæ»ú×Öĸ: " + randomLetter, 'gold');
- sleep.second(1);
- }
- threadStatus.randomLetter = 'stopped';
- logToH5("[Ëæ»ú×ÖĸÏß³Ì] ÒÑÍ£Ö¹", 'warn');
- }, "-Ëæ»ú×ÖĸÏß³Ì")
- // Ïß³Ì3: Ëæ»úʱ¼ä¶ÎÏÔʾÏß³Ì
- threads.randomTime = new thread().runJsCode(function fun(){
- logToH5("[Ëæ»úʱ¼äÏß³Ì] Æô¶¯", 'info');
- while(threadStatus.randomTime === 'running') {
- var hours = Math.floor(Math.random() * 24);
- var minutes = Math.floor(Math.random() * 60);
- var seconds = Math.floor(Math.random() * 60);
- var timeStr = String(hours).padStart(2, '0') + ':' +
- String(minutes).padStart(2, '0') + ':' +
- String(seconds).padStart(2, '0');
- logToH5("[Ëæ»úʱ¼äÏß³Ì] Ëæ»úʱ¼ä: " + timeStr, 'info');
- sleep.second(1);
- }
- threadStatus.randomTime = 'stopped';
- logToH5("[Ëæ»úʱ¼äÏß³Ì] ÒÑÍ£Ö¹", 'warn');
- }, "-Ëæ»úʱ¼äÏß³Ì")
- // Ïß³Ì4: Ëæ»úÊý×ÖÉú³ÉÏß³Ì
- threads.randomNumber = new thread().runJsCode(function fun(){
- logToH5("[Ëæ»úÊý×ÖÏß³Ì] Æô¶¯", 'info');
- while(threadStatus.randomNumber === 'running') {
- var randomNumber = Math.floor(Math.random() * 1000); // 0-999Ö®¼äµÄËæ»úÊý
- logToH5("[Ëæ»úÊý×ÖÏß³Ì] Éú³ÉËæ»úÊý×Ö: " + randomNumber, 'success');
- sleep.second(1);
- }
- threadStatus.randomNumber = 'stopped';
- logToH5("[Ëæ»úÊý×ÖÏß³Ì] ÒÑÍ£Ö¹", 'warn');
- }, "-Ëæ»úÊý×ÖÏß³Ì")
- // Ïß³Ì5: ¼à¿ØÏß³Ì - »ñÈ¡ÆäËûÏß³Ì״̬²¢ÔÚ10ÃëºóÍ£Ö¹ËùÓÐÏß³Ì
- threads.monitor = new thread().runJsCode(function fun(){
- logToH5("[¼à¿ØÏß³Ì] Æô¶¯ - ½«¼à¿ØÆäËûÏß³Ì״̬", 'info');
- var startTime = Date.now();
- var elapsedSeconds = 0;
-
- // ¸¨Öúº¯Êý£º½«Ó¢ÎÄ״̬ת»»ÎªÖÐÎÄ
- function getStatusText(status) {
- if(status === 'running') return 'ÕýÔÚÔËÐÐ';
- if(status === 'stopping') return 'ÕýÔÚÍ£Ö¹';
- if(status === 'stopped') return 'ÒÑÍ£Ö¹';
- return status;
- }
-
- // ¼à¿Ø10ÃëÖÓ
- while(elapsedSeconds < 10) {
- logToH5("[¼à¿ØÏß³Ì] µ±Ç°¸÷Ïß³Ì״̬ (ÒÑÔËÐÐ " + elapsedSeconds + " Ãë):", 'info');
- logToH5(" - µ¹¼ÆÊ±Ïß³Ì: " + getStatusText(threadStatus.countdown), 'info');
- logToH5(" - Ëæ»ú×ÖĸÏß³Ì: " + getStatusText(threadStatus.randomLetter), 'info');
- logToH5(" - Ëæ»úʱ¼äÏß³Ì: " + getStatusText(threadStatus.randomTime), 'info');
- logToH5(" - Ëæ»úÊý×ÖÏß³Ì: " + getStatusText(threadStatus.randomNumber), 'info');
-
- sleep.second(1); // ʹÓÃsecond´úÌæmillisecond
- elapsedSeconds++;
- }
-
- logToH5("[¼à¿ØÏß³Ì] 10ÃëÒѵ½£¬ÕýÔÚÍ£Ö¹ËùÓÐÏß³Ì...", 'warn');
-
- // ¸üÐÂ״̬±ê¼Ç
- threadStatus.countdown = 'stopping';
- threadStatus.randomLetter = 'stopping';
- threadStatus.randomTime = 'stopping';
- threadStatus.randomNumber = 'stopping';
-
- // µÈ´ýһС¶Îʱ¼äÈÃÆäËûÏ̼߳ì²âµ½×´Ì¬±ä»¯²¢×ÔÐÐÍ£Ö¹
- sleep.second(1);
-
- // Ç¿ÖÆÍ£Ö¹ËùÓй¤×÷Ïß³Ì
- try {
- if(threads.countdown && threads.countdown.isAlive()) {
- threads.countdown.interrupt();
- logToH5("[¼à¿ØÏß³Ì] ÒÑÖжϵ¹¼ÆÊ±Ïß³Ì", 'success');
- }
- } catch(e) {
- logToH5("[¼à¿ØÏß³Ì] Í£Ö¹µ¹¼ÆÊ±Ïß³Ìʱ³ö´í: " + e.message, 'error');
- }
-
- try {
- if(threads.randomLetter && threads.randomLetter.isAlive()) {
- threads.randomLetter.interrupt();
- logToH5("[¼à¿ØÏß³Ì] ÒÑÖжÏËæ»ú×ÖĸÏß³Ì", 'success');
- }
- } catch(e) {
- logToH5("[¼à¿ØÏß³Ì] Í£Ö¹Ëæ»ú×ÖĸÏß³Ìʱ³ö´í: " + e.message, 'error');
- }
-
- try {
- if(threads.randomTime && threads.randomTime.isAlive()) {
- threads.randomTime.interrupt();
- logToH5("[¼à¿ØÏß³Ì] ÒÑÖжÏËæ»úʱ¼äÏß³Ì", 'success');
- }
- } catch(e) {
- logToH5("[¼à¿ØÏß³Ì] Í£Ö¹Ëæ»úʱ¼äÏß³Ìʱ³ö´í: " + e.message, 'error');
- }
-
- try {
- if(threads.randomNumber && threads.randomNumber.isAlive()) {
- threads.randomNumber.interrupt();
- logToH5("[¼à¿ØÏß³Ì] ÒÑÖжÏËæ»úÊý×ÖÏß³Ì", 'success');
- }
- } catch(e) {
- logToH5("[¼à¿ØÏß³Ì] Í£Ö¹Ëæ»úÊý×ÖÏß³Ìʱ³ö´í: " + e.message, 'error');
- }
-
- logToH5("[¼à¿ØÏß³Ì] ËùÓÐÏß³ÌÒÑÍ£Ö¹£¬½Å±¾¼´½«½áÊø", 'success');
-
- // ×îºóÍ£Ö¹ËùÓнű¾
- stopAll();
- }, "-¼à¿ØÏß³Ì")
- logToH5("ËùÓÐÏß³ÌÒÑÆô¶¯£¬¼à¿ØÏ߳̽«ÔÚ10ÃëºóÍ£Ö¹ËùÓÐÆäËûÏß³Ì", 'success');
¸´ÖÆ´úÂë
|
|