新建Javascript文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var rAF = function () {
return (
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
function (callback) {
window.setTimeout(callback, 1000 / 60);
}
);
}();
var frame = 0;
var allFrameCount = 0;
var lastTime = Date.now();
var lastFameTime = Date.now();
var loop = function () {
var now = Date.now();
var fs = (now - lastFameTime);
var fps = Math.round(1000 / fs);

lastFameTime = now;
// 不置 0,在动画的开头及结尾记录此值的差值算出 FPS
allFrameCount++;
frame++;

if (now > 1000 + lastTime) {
var fps = Math.round((frame * 1000) / (now - lastTime));
if(fps<=6){
var kd=`<span style="color:#bd0000">卡成ppt</span>`
}
else if(fps<=10){
var kd=`<span style="color:red">电竞级帧率</span>`
}
else if(fps<=14){
var kd=`<span style="color:yellow">难受</span>`
}
else if(fps<24){
var kd=`<span style="color:orange">卡</span>`
}
else if(fps<=40){
var kd=`<span style="color:green">...</span>`
}
else{
var kd=`<span style="color:#425aef">正常</span>`
}
document.getElementById("fps").innerHTML=`FPS:${fps} ${kd}`;
frame = 0;
lastTime = now;
};

rAF(loop);
}

loop();


新建Css文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* 帧率检测 */
#fps {
position: fixed;
/* 指定位置 */
left: 10px;
bottom: 10px;
z-index: 1919810;
}
[data-theme="light"] #fps {
background-color: rgba(255, 255, 255, 0.85);
backdrop-filter: var(--backdrop-filter);
padding: 4px;
border-radius: 4px;
}
[data-theme="dark"] #fps {
background-color: rgba(0, 0, 0, 0.72);
backdrop-filter: var(--backdrop-filter);
padding: 4px;
border-radius: 4px;
}


修改_config.butterfly.yml

1
2
3
4
5
6
7
8
9
10
11
# Inject
# Insert the code to head (before '</head>' tag) and the bottom (before '</body>' tag)
# 插入代码到头部 </head> 之前 和 底部 </body> 之前
inject:
head:
# 零零散散的css
- <link rel="stylesheet" href="/css/新建的fps的.css">
bottom:
# 显示FPS
- <script type="text/javascript" src="/js/新建的fps的.js"></script>
- <div id="fps"></div>