可信源码风险提示:保存或下载前请阅读源码和权限声明。
/*
* Author: Drific
* Email: Drific_pl@163.com
* QQ: 3652967144
* 竟然是高贵的四空格缩进?!!
* 点快点,你会发现手环会“红温”
* 仅在点击时更新是因为定时更新容易出现雷霆点击间隔(如8ms)和延迟
* 显示适配米环9Pro(OS 3.1.190)
*/
/*屏幕常亮设定回调*/
const brightness = system.display;
function set_keep_screen_on(value) {
brightness.setKeepScreenOn({
keepScreenOn:value
});
};
/*rgb 10 ---> 16进制转换*/
function num_10_16(num_10) {
/*重要:保证数字处于0-255区间*/
num_10 = Math.max(0, Math.min(num_10, 255));
/* 我写的进制处理方式性能竟然比.toString(16)差9%左右(恼)*/
/*
let num_16_place1 = num_10 >> 4; //(num_10 / 16) | 0;
let num_16_place2 = num_10 & 15; //num_10 - num_16_place1*16;
const code_16 = '0123456789abcdef';
return code_16[num_16_place1] + code_16[num_16_place2];
*/
let num_16 = num_10.toString(16);
if (num_16.length === 1) num_16 = '0'+num_16;
return num_16;
};
/*手速测试时长*/
const total_time = 10000 // ms
/*声明变量*/
let on_ready = true,
start_time = null,
last_click_time = null,
residue_time = total_time,
click_count = 0,
RTCPS = 0,
best_cps = 0,
average_cps = 0,
comment = '无',
click_board_text = '开始';
/*初始化*/
function initialize() {
on_ready = true;
start_time = null;
last_click_time = null;
residue_time = total_time;
click_count = 0;
RTCPS = 0;
best_cps = 0;
average_cps = 0;
data_board_style.background = '#000';
comment = '无';
click_board_text = '开始';
set_keep_screen_on(false);
console.info('Initialized !');
}
/*同步状态*/
function sync_status() {
click_board_style.disabled = !on_ready;
ui.refresh();
};
/*更新数据*/
function update_data(now_time) {
residue_time = start_time + total_time - now_time;
average_cps = click_count / (now_time - start_time) * 1000;
let r = Math.floor( 51*(average_cps - 5) );
r = num_10_16(r);
data_board_style.background = '#' + r + '0000';
if (average_cps >= 11) comment = '夯爆了!';
else if (average_cps >= 9) comment = '夯';
else if (average_cps >= 7.5) comment = '人上人';
else if (average_cps >= 5) comment = 'NPC';
else comment = '拉完了';
};
/*超时时执行*/
function after_timeout() {
if (on_ready === false) return;
residue_time = 0;
on_ready = false;
click_board_text = '已结束';
average_cps = click_count / total_time * 1000;
console.info(
`Terminated, RTCPS: ${RTCPS}, `
+`best_cps: ${best_cps}, `
+`average_cps: ${average_cps}, `
+`click_count: ${click_count}`
);
set_keep_screen_on(false);
sync_status();
}
/*开始*/
function start(now_time) {
start_time = now_time;
last_click_time = now_time;
click_board_text = '快点';
set_keep_screen_on(true);
console.info('Started, start_time: '+start_time);
}
/*记录和纪录*/
function record(now_time) {
RTCPS = 1000 / (now_time - last_click_time);
if (RTCPS >= best_cps) {
best_cps = RTCPS;
}
last_click_time = now_time;
click_count++;
update_data(now_time);
sync_status();
}
/*拦截阈值*/
const MIN_INTERVAL = 40;
function on_click() {
const now_time = Date.now();
/*拦截异常间隔的点击,大肥鱼的支持*/
if (start_time && now_time - last_click_time < MIN_INTERVAL) {
const dt = now_time - last_click_time;
console.warn(`已拦截异常点击执行: dt=${dt}ms @${now_time}`);
return;
}
if (!start_time) start(now_time);
else if (now_time - start_time > total_time) after_timeout();
else record(now_time);
}
function reset() {
console.info('Reset !')
initialize();
sync_status();
};
function exit() {
initialize();
script.exit();
};
/* UI */
/*顶栏样式*/
/*退出键样式*/
const exit_button_style = {
size:28,
height:55,
width:65,
radius:25,
x:5,
y:0,
background:'#313131'
};
/*重置键样式*/
const title_text_style = {
align:'center',
size:32,
y:10
}
const reset_button_style = {
height:55,
width:75,
radius:25,
x:265,
y:0,
background:'#f22'
};
/*数据板样式*/
const data_board_style = {
id:'data_board',
gap:4,
padding:0,
radius:9,
background:'#000'
};
/*数据文本样式*/
const data_text_style = {
size:18,
height:72,
lineHeight:24,
lines:3
};
/*点击板样式*/
const click_board_style = {
id:'click-board',
size:29,
background:'',
height:297,
width:'100%',
radius:25,
disabled:false
};
ui.showHeader(false);
/*UI排定*/
ui.render(() => [
ui.stack([
ui.text(
'手速测试',
title_text_style
),
ui.button(
'X',
() => exit(),
exit_button_style
),
ui.button(
'重置',
() => reset(),
reset_button_style
)
],{id:'top_bar',height:55}),
ui.row([
ui.text(
`剩余时间:${residue_time}`
+`\n瞬时CPS:${RTCPS.toFixed(4)}`
+`\n平均CPS:${average_cps.toFixed(4)}`,
data_text_style
),
ui.text(
`次数:${click_count}`
+`\n最佳CPS:${best_cps.toFixed(4)}`
+`\n评价:${comment}`,
data_text_style
)
],data_board_style),
ui.button(
click_board_text,
() => on_click(),
click_board_style
)
])