51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Hexo禁用F12进入调试控制台和复制文章的内容

引言 {#引言}

如果你不希望别人直接按下F12按键进入调试控制台或者复制文章的内容,那么本文章你肯定能用得上:)

操作步骤 {#操作步骤}

修改【/butterfly/layout/includes/layout.pug】,根据图中位置添加以下 pug 代码(跟 head、body同级)。

|------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | script. ((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();}); script. function toDevtools(){ let num = 0; let devtools = new Date(); devtools.toString = function() { num++; if (num > 1) { alert('你真坏,请关闭控制台!') window.location.href = "about:blank" blast(); } } console.log('', devtools); } toDevtools(); |

将以下代码复制到自定义的disableF12.js

|---------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 13 | document.oncontextmenu = function () { return false; }; document.onselectstart = function () { return false; }; document.onkeydown = function () { if (window.event && (123 == window.event.keyCode || (window.event.ctrlKey && window.event.shiftKey && (74 === window.event.keyCode || 73 === window.event.keyCode || 67 === window.event.keyCode)) // Ctrl + Shift + I/J/C || (window.event.ctrlKey && 85 === window.event.keyCode)) // Ctrl + U || (window.event.ctrlKey && 80 === window.event.keyCode)) // Ctrl + P || (window.event.ctrlKey && 83 === window.event.keyCode)) // Ctrl + S ) { return window.event.keyCode = 0, window.event.returnValue = false, false; } }; |

重新编译运行,即可看到效果。

注意: 如果自己调试阶段,可注释第一步和第二步中的代码,再进行编译,就可以打开控制台了。部署时放开注释,编译好再丢上去就OK了。

赞(0)
未经允许不得转载:工具盒子 » Hexo禁用F12进入调试控制台和复制文章的内容