前言

一直都很想要实现@轻笑的这个禁用F12的功能,还没有可用的教程

20221107-1

索性自己开抄,于是就有了封面的效果

20221107-2

实现

添加bandev.js

新建source/js/bandevjs(自行修改提示文字)

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
((function() {var callbacks = [],timeLimit = 50,open = false;setInterval(loop, 1);return {addListener: function(fn) {callbacks.push(fn);},cancleListenr: function(fn) {callbacks = callbacks.filter(function(v) {return v !== fn;});}}
function loop() {var startTime = new Date();debugger;if (new Date() - startTime > timeLimit) {if (!open) {callbacks.forEach(function(fn) {fn.call(null);});}open = true;window.stop();alert('此处添加关掉调试时提示的文字');document.body.innerHTML = "";} else {open = false;}}})()).addListener(function() {window.location.reload();});


function toDevtools(){
let num = 0;
let devtools = new Date();
devtools.toString = function() {
num++;
if (num > 1) {
window.location.href = "about:blank"
blast();
}
}
console.log('', devtools);
}
toDevtools();


document.onkeydown = document.onkeyup = document.onkeypress = function(event) {
var e = event || window.event || arguments.callee.caller.arguments[0];
if (e && (e.keyCode == 123)) {
e.keyCode = 0;
e.returnValue = false;
btf.snackbarShow('此处添加按F12时提示的文字');
return (false);
}
}
$(document).keydown(function(e){
if( e.ctrlKey == true && e.keyCode == 83 ){
console.log('ctrl+s');
return false;
}
});

引入JS

修改_config.butterfly.yml,注意缩进

1
2
3
4
inject:
head:
#禁用F12
+ - <script src="/js/bandev.js"></script>

Hexo三连即可

总结

到这里就结束了,本文仅提供了调试模式暂停和禁止F12的方法,如有错误欢迎指正