From 8c888fe71d8ca929c02d84d6d15d6c53951ebe50 Mon Sep 17 00:00:00 2001
From: theajack <1506282385@qq.com>
Date: Sun, 25 Jul 2021 17:52:51 +0800
Subject: [PATCH] feat: 0.1.4
---
.eslintrc.js | 3 +-
README.cn.md | 25 ++++++++++--
README.md | 25 ++++++++++--
helper/copy-to-npm.js | 4 +-
helper/mod-index-html-version.js | 2 +-
helper/util.js | 2 +-
helper/version.md | 8 +++-
index.html | 11 ++++--
npm/README.cn.md | 63 +++++++++++++++++++++++-------
npm/README.md | 63 +++++++++++++++++++++++-------
npm/disable-devtool.min.js | 2 +-
npm/index.d.ts | 12 +++++-
npm/package.json | 2 +-
package.json | 2 +-
src/config.js | 5 ++-
src/detector/define-id.js | 24 ++++++++++++
src/detector/detector.js | 44 +++++++++++++++++++++
src/detector/log-time.js | 30 ++++++++++++++
src/detector/size.js | 28 +++++++++++++
src/detector/to-string.js | 38 ++++++++++++++++++
src/index.d.ts | 12 +++++-
src/interval.js | 16 ++++----
src/key-menu.js | 2 +-
src/main.js | 67 +++++---------------------------
src/util.js | 38 +++++++++---------
src/version.js | 2 +-
26 files changed, 394 insertions(+), 136 deletions(-)
create mode 100644 src/detector/define-id.js
create mode 100644 src/detector/detector.js
create mode 100644 src/detector/log-time.js
create mode 100644 src/detector/size.js
create mode 100644 src/detector/to-string.js
diff --git a/.eslintrc.js b/.eslintrc.js
index 3d5732d..8f59493 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -56,6 +56,7 @@ module.exports = {
"semi-spacing": "error",
"comma-spacing": "error",
"key-spacing": "error",
- "no-undef": "error"
+ "no-undef": "error",
+ "prefer-const": "error"
}
}
\ No newline at end of file
diff --git a/README.cn.md b/README.cn.md
index 3344bcd..6adae8d 100644
--- a/README.cn.md
+++ b/README.cn.md
@@ -77,7 +77,7 @@ disable-devtool 可以禁用所有一切可以进入开发者工具的方法,
2. 禁用 f12 和 ctrl+shift+i 快捷键
3. 支持识别从浏览器菜单栏打开开发者工具并关闭当前页面
4. 开发者可以绕过禁用 (url参数使用tk配合md5加密)
-5. 支持几乎所有浏览器(IE,360,qq浏览器,FireFox,Chrome,Edge...)
+5. 多种监测模式,支持几乎所有浏览器(IE,360,qq浏览器,FireFox,Chrome,Edge...)
6. 高度可配置
7. 使用极简、体积小巧 (仅7kb)
8. 支持npm引用和script标签引用(属性配置)
@@ -106,11 +106,14 @@ declare interface optionStatic {
md5?: string; // 绕过禁用的md5值,详情见3.2,默认不启用绕过禁用
url?: string; // 关闭页面失败时的跳转页面,默认值为localhost
tkName?: string; // 绕过禁用时的url参数名称,默认为 ddtk
- ondevtoolopen?(): void; // 开发者面板打开的回调,启用时url参数无效
+ ondevtoolopen?(type: DetectorType): void; // 开发者面板打开的回调,启用时url参数无效,type 为监测模式,详见3.5
interval?: number; // 定时器的时间间隔 默认200ms
disableMenu?: boolean; // 是否禁用右键菜单 默认为true
stopIntervalTime?: number; // 在移动端时取消监视的等待时长
+ clearIntervalWhenDevOpenTrigger?: boolean; // 是否在触发之后停止监控
}
+
+declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3;
```
### 3.2 md5 与 tk 绕过禁用
@@ -156,4 +159,20 @@ disableDevtool.md5('xxx');
// 参数与3.1中一致
})
-```
\ No newline at end of file
+```
+
+### 3.5 监测模式
+
+Disable-Devtool 有四种监测模式, DisableDevtool.DETECTOR_TYPE 为所有的监测模式
+
+```js
+const DETECTOR_TYPE = {
+ UNKONW: -1,
+ TO_STRING: 0,
+ DEFINE_ID: 1,
+ SIZE: 2,
+ LOG_TIME: 3,
+}
+```
+
+ondevtoolopen 事件的回调参数就是被触发的监测模式
\ No newline at end of file
diff --git a/README.md b/README.md
index 74238a3..b01c3bd 100644
--- a/README.md
+++ b/README.md
@@ -76,7 +76,7 @@ The library has the following features:
2. Disable f12 and ctrl+shift+i shortcuts
3. Support recognition to open the developer tools from the browser menu bar and close the current page
4. Developers can bypass the disablement (use tk and md5 encryption for url parameters)
-5. Support almost all browsers (IE,360,qq browser,FireFox,Chrome,Edge...)
+5. Multiple monitoring modes, support almost all browsers (IE, 360, qq browser, FireFox, Chrome, Edge...)
6. Highly configurable
7. Minimal use, small size (only 7kb)
8. Support npm reference and script tag reference (attribute configuration)
@@ -105,11 +105,14 @@ declare interface optionStatic {
md5?: string; // Bypass the disabled md5 value, see 3.2 for details, the bypass disable is not enabled by default
url?: string; // Jump to the page when closing the page fails, the default value is localhost
tkName?: string; // Bypass the url parameter name when disabled, the default is ddtk
- ondevtoolopen?(): void; // Callback for opening the developer panel, the url parameter is invalid when enabled
+ ondevtoolopen?(type: DetectorType): void; // Callback for opening the developer panel, the url parameter is invalid when it is enabled, and the type is the monitoring mode, see 3.5 for details
interval?: number; // Timer interval is 200ms by default
disableMenu?: boolean; // Whether to disable the right-click menu The default is true
stopIntervalTime?: number; // Waiting time to cancel monitoring on mobile
+ clearIntervalWhenDevOpenTrigger?: boolean; // Whether to stop monitoring after triggering
}
+
+declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3;
```
### 3.2 md5 and tk bypass disable
@@ -155,4 +158,20 @@ Note:
// The parameters are the same as in 3.1
})
-```
\ No newline at end of file
+```
+
+### 3.5 Monitoring Mode
+
+Disable-Devtool has four monitoring modes, DisableDevtool.DETECTOR_TYPE is all monitoring modes
+
+```js
+const DETECTOR_TYPE = {
+ UNKONW: -1,
+ TO_STRING: 0,
+ DEFINE_ID: 1,
+ SIZE: 2,
+ LOG_TIME: 3,
+}
+```
+
+The callback parameter of the ondevtoolopen event is the triggered monitoring mode
\ No newline at end of file
diff --git a/helper/copy-to-npm.js b/helper/copy-to-npm.js
index a5abfd2..62dff33 100644
--- a/helper/copy-to-npm.js
+++ b/helper/copy-to-npm.js
@@ -8,9 +8,9 @@ function main () {
copyPkg();
copyFiles();
}
-
+
function copyPkg () {
- let npmPkg = util.pick({
+ const npmPkg = util.pick({
target: pkg,
attrs: [
'name', 'version', 'description', 'main', 'unpkg', 'jsdelivr',
diff --git a/helper/mod-index-html-version.js b/helper/mod-index-html-version.js
index 9e72847..1fb888b 100644
--- a/helper/mod-index-html-version.js
+++ b/helper/mod-index-html-version.js
@@ -3,7 +3,7 @@ const util = require('./util');
function modIndexHtmlVersion () {
util.read('index.html', (html) => {
- let res = html.match(new RegExp(`https://cdn.jsdelivr.net/npm/disable-devtool@.*/disable-devtool.min.js#use`));
+ const res = html.match(new RegExp(`https://cdn.jsdelivr.net/npm/disable-devtool@.*/disable-devtool.min.js#use`));
if (res) {
util.write('index.html', html.replace(res[0], `https://cdn.jsdelivr.net/npm/disable-devtool@${pkg.version}/disable-devtool.min.js#use`));
}
diff --git a/helper/util.js b/helper/util.js
index 7ae2bb6..4cd5989 100644
--- a/helper/util.js
+++ b/helper/util.js
@@ -1,4 +1,4 @@
-let fs = require('fs');
+const fs = require('fs');
module.exports = {
read: function (file, cb) {
diff --git a/helper/version.md b/helper/version.md
index 73fed65..5ca068f 100644
--- a/helper/version.md
+++ b/helper/version.md
@@ -44,4 +44,10 @@
1. 加上document的判断 以适应服务端渲染 npm 调用
## 0.1.3
-1. 修复 disableMenu 参数无效的bug
\ No newline at end of file
+1. 修复 disableMenu 参数无效的bug
+
+## 0.1.4
+1. 增加 detector,增加多种监测模式
+2. 使用logTime模式兜底,兼容mac,linux
+3. 增加 clearIntervalWhenDevOpenTrigger 参数
+4. ondevtoolopen 增加 监测模式 回调参数
\ No newline at end of file
diff --git a/index.html b/index.html
index 1f370b8..544a64c 100644
--- a/index.html
+++ b/index.html
@@ -97,7 +97,7 @@ disableDevtool();
Disable f12 and ctrl+shift+i shortcuts
Support recognition to open the developer tools from the browser menu bar and close the current page
Developers can bypass the disablement (use tk and md5 encryption for url parameters)
- Support almost all browsers (IE,360,qq browser,FireFox,Chrome,Edge...)
+ Multiple monitoring modes, support almost all browsers (IE, 360, qq browser, FireFox, Chrome, Edge...)
Highly configurable
Minimal use, small size (only 7kb)
Support npm reference and script tag reference (attribute configuration)
@@ -121,11 +121,14 @@ disableDevtool(options);
md5?: string; // Bypass the disabled md5 value, see 3.2 for details, the bypass disable is not enabled by default
url?: string; // Jump to the page when closing the page fails, the default value is localhost
tkName?: string; // Bypass the url parameter name when disabled, the default is ddtk
- ondevtoolopen?(): void; // Callback for opening the developer panel, the url parameter is invalid when enabled
+ ondevtoolopen?(type: DetectorType): void; // Callback for opening the developer panel, the url parameter is invalid when it is enabled
interval?: number; // Timer interval is 200ms by default
disableMenu?: boolean; // Whether to disable the right-click menu The default is true
stopIntervalTime?: number; // Waiting time to cancel monitoring on mobile
-}
+ clearIntervalWhenDevOpenTrigger?: boolean; // Whether to stop monitoring after triggering
+}
+
+declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3;
3.2 md5 and tk bypass disable
@@ -178,7 +181,7 @@ disableDevtool(options);
-```
\ No newline at end of file
+```
+
+### 3.5 监测模式
+
+Disable-Devtool 有四种监测模式, DisableDevtool.DETECTOR_TYPE 为所有的监测模式
+
+```js
+const DETECTOR_TYPE = {
+ UNKONW: -1,
+ TO_STRING: 0,
+ DEFINE_ID: 1,
+ SIZE: 2,
+ LOG_TIME: 3,
+}
+```
+
+ondevtoolopen 事件的回调参数就是被触发的监测模式
\ No newline at end of file
diff --git a/npm/README.md b/npm/README.md
index 22126f0..b01c3bd 100644
--- a/npm/README.md
+++ b/npm/README.md
@@ -4,19 +4,35 @@
----
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
**[中文](https://github.com/theajack/disable-devtool/blob/master/README.cn.md) | [online trial/document](https://theajack.gitee.io/disable-devtool) | [Version Log](https://github.com/theajack/disable-devtool/blob/master/helper/version.md) | [Gitee](https://gitee.com/theajack/disable-devtool)**
@@ -60,7 +76,7 @@ The library has the following features:
2. Disable f12 and ctrl+shift+i shortcuts
3. Support recognition to open the developer tools from the browser menu bar and close the current page
4. Developers can bypass the disablement (use tk and md5 encryption for url parameters)
-5. Support almost all browsers (IE,360,qq browser,FireFox,Chrome,Edge...)
+5. Multiple monitoring modes, support almost all browsers (IE, 360, qq browser, FireFox, Chrome, Edge...)
6. Highly configurable
7. Minimal use, small size (only 7kb)
8. Support npm reference and script tag reference (attribute configuration)
@@ -89,11 +105,14 @@ declare interface optionStatic {
md5?: string; // Bypass the disabled md5 value, see 3.2 for details, the bypass disable is not enabled by default
url?: string; // Jump to the page when closing the page fails, the default value is localhost
tkName?: string; // Bypass the url parameter name when disabled, the default is ddtk
- ondevtoolopen?(): void; // Callback for opening the developer panel, the url parameter is invalid when enabled
+ ondevtoolopen?(type: DetectorType): void; // Callback for opening the developer panel, the url parameter is invalid when it is enabled, and the type is the monitoring mode, see 3.5 for details
interval?: number; // Timer interval is 200ms by default
disableMenu?: boolean; // Whether to disable the right-click menu The default is true
stopIntervalTime?: number; // Waiting time to cancel monitoring on mobile
+ clearIntervalWhenDevOpenTrigger?: boolean; // Whether to stop monitoring after triggering
}
+
+declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3;
```
### 3.2 md5 and tk bypass disable
@@ -139,4 +158,20 @@ Note:
// The parameters are the same as in 3.1
})
-```
\ No newline at end of file
+```
+
+### 3.5 Monitoring Mode
+
+Disable-Devtool has four monitoring modes, DisableDevtool.DETECTOR_TYPE is all monitoring modes
+
+```js
+const DETECTOR_TYPE = {
+ UNKONW: -1,
+ TO_STRING: 0,
+ DEFINE_ID: 1,
+ SIZE: 2,
+ LOG_TIME: 3,
+}
+```
+
+The callback parameter of the ondevtoolopen event is the triggered monitoring mode
\ No newline at end of file
diff --git a/npm/disable-devtool.min.js b/npm/disable-devtool.min.js
index 69a226d..0c1c3f6 100644
--- a/npm/disable-devtool.min.js
+++ b/npm/disable-devtool.min.js
@@ -1 +1 @@
-!function(n,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.DisableDevtool=e():n.DisableDevtool=e()}(this,(function(){return function(n){var e={};function t(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return n[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}return t.m=n,t.c=e,t.d=function(n,e,o){t.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:o})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,e){if(1&e&&(n=t(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var r in n)t.d(o,r,function(e){return n[e]}.bind(null,r));return o},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=0)}([function(n,e,t){"use strict";function o(){return r("qqbrowser")}function r(n){return-1!==navigator.userAgent.toLocaleLowerCase().indexOf(n)}function i(n){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(n)}t.r(e);var u={md5:"",ondevtoolopen:function(){if(u.url)window.location.href=u.url;else{try{window.opener=null,window.open("","_self"),window.close(),window.history.back()}catch(n){console.log(n)}setTimeout((function(){window.location.href="https://tackchen.gitee.io/404.html?h=".concat(encodeURIComponent(location.host))}),500)}},url:"",tkName:"ddtk",interval:200,disableMenu:!0,stopIntervalTime:5e3};var c=null,a=null,f=[];function l(){var n,e,t,o,r,i,l=!1,d=function(){l=!0},s=function(){l=!1};n=d,e=s,t=window.alert,o=window.confirm,r=window.prompt,i=function(t){return function(){n&&n(),t.apply(void 0,arguments),e&&e()}},window.alert=i(t),window.confirm=i(o),window.prompt=i(r),function(n,e){var t,o,r;void 0!==document.hidden?(t="hidden",r="visibilitychange",o="visibilityState"):void 0!==document.mozHidden?(t="mozHidden",r="mozvisibilitychange",o="mozVisibilityState"):void 0!==document.msHidden?(t="msHidden",r="msvisibilitychange",o="msVisibilityState"):void 0!==document.webkitHidden&&(t="webkitHidden",r="webkitvisibilitychange",o="webkitVisibilityState");var i=function(){document[o]===t?e():n()};document.removeEventListener(r,i,!1),document.addEventListener(r,i,!1)}(s,d),c=window.setInterval((function(){l||f.forEach((function(n){n()}))}),u.interval),a=setTimeout((function(){/(iphone|ipad|ipod|ios|android)/i.test(navigator.userAgent.toLowerCase())&&window.clearInterval(c)}),u.stopIntervalTime)}function d(n,e,t,o,r,i){return w((u=w(w(e,n),w(o,i)))<<(c=r)|u>>>32-c,t);var u,c}function s(n,e,t,o,r,i,u){return d(e&t|~e&o,n,e,r,i,u)}function v(n,e,t,o,r,i,u){return d(e&o|t&~o,n,e,r,i,u)}function m(n,e,t,o,r,i,u){return d(e^t^o,n,e,r,i,u)}function p(n,e,t,o,r,i,u){return d(t^(e|~o),n,e,r,i,u)}function w(n,e){var t=(65535&n)+(65535&e);return(n>>16)+(e>>16)+(t>>16)<<16|65535&t}var y=function(n){return function(n){for(var e="0123456789abcdef",t="",o=0;o<4*n.length;o++)t+=e.charAt(n[o>>2]>>o%4*8+4&15)+e.charAt(n[o>>2]>>o%4*8&15);return t}(function(n,e){n[e>>5]|=128<>>9<<4)]=e;for(var t=1732584193,o=-271733879,r=-1732584194,i=271733878,u=0;u>5]|=(255&n.charCodeAt(t/8))<0&&void 0!==arguments[0]?arguments[0]:{};for(var e in u)void 0!==n[e]&&i(u[e])===i(n[e])&&(u[e]=n[e])}(n),function(){if(u.md5){var n=function(n){var e=window.location.search;if(""!==e){var t=new RegExp("(^|&)"+n+"=([^&]*)(&|$)","i"),o=e.substr(1).match(t);if(null!=o)return unescape(o[2])}return""}(u.tkName);if(y(n)===u.md5)return!0}return!1}()||(l(),window.addEventListener("keydown",(function(n){if(123===((n=n||window.event).keyCode||n.which)||n.shiftKey&&n.ctrlKey&&73===n.keyCode)return n.returnValue=!1,n.preventDefault(),!1}),!1),u.disableMenu&&window.addEventListener("contextmenu",(function(n){return(n=n||window.event).returnValue=!1,n.preventDefault(),!1}),!1),function(){var n=o(),e=r("firefox"),t="";if(n){var i=0;t=/./,console.log(t),t.toString=function(){var n=g(),e=n.time,t=n.next;return i&&e-i<100?t():i=e,""}}else e?(t=/./,console.log(t),t.toString=function(){return g().next(),""}):(t=new Image).__defineGetter__("id",(function(){g().next()}));u=function(){console.log(t),console.clear()},f.push(u);var u}())}b.md5=y,b.version="0.1.3";var h=!1;function g(){var n=(new Date).getTime();return console.log("You ar not allow to use DEVTOOL!",n),h?{time:n,next:function(){}}:(o()||(h=!0),{time:n,next:function(){h=!0,window.clearTimeout(a),u.ondevtoolopen()}})}!function(){if("undefined"!=typeof document){var n=document.querySelector("[disable-devtool-auto]");if(n){var e={};["md5","url","tk-name","interval","disable-menu"].forEach((function(t){var o=n.getAttribute(t);null!==o&&("interval"===t?o=parseInt(o):"disable-menu"===t&&(o="false"!==o),e[function(n){if(-1===n.indexOf("-"))return n;var e=!1;return n.split("").map((function(n){return"-"===n?(e=!0,""):e?(e=!1,n.toUpperCase()):n})).join("")}(t)]=o)})),b(e)}}}();e.default=b}]).default}));
\ No newline at end of file
+!function(n,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.DisableDevtool=e():n.DisableDevtool=e()}(this,(function(){return function(n){var e={};function t(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return n[o].call(i.exports,i,i.exports,t),i.l=!0,i.exports}return t.m=n,t.c=e,t.d=function(n,e,o){t.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:o})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,e){if(1&e&&(n=t(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var i in n)t.d(o,i,function(e){return n[e]}.bind(null,i));return o},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=0)}([function(n,e,t){"use strict";t.r(e);var o=null,i=null,r=[],u=0;function c(){var n,e,t,c,a,l,d=!1,s=function(){d=!0},w=function(){d=!1};n=s,e=w,t=window.alert,c=window.confirm,a=window.prompt,l=function(t){return function(){n&&n(),t.apply(void 0,arguments),e&&e()}},window.alert=l(t),window.confirm=l(c),window.prompt=l(a),function(n,e){var t,o,i;void 0!==document.hidden?(t="hidden",i="visibilitychange",o="visibilityState"):void 0!==document.mozHidden?(t="mozHidden",i="mozvisibilitychange",o="mozVisibilityState"):void 0!==document.msHidden?(t="msHidden",i="msvisibilitychange",o="msVisibilityState"):void 0!==document.webkitHidden&&(t="webkitHidden",i="webkitvisibilitychange",o="webkitVisibilityState");var r=function(){document[o]===t?e():n()};document.removeEventListener(i,r,!1),document.addEventListener(i,r,!1)}(w,s),o=window.setInterval((function(){d||(r.forEach((function(n){n(u++)})),console.clear())}),v.interval),i=setTimeout((function(){/(iphone|ipad|ipod|ios|android)/i.test(navigator.userAgent.toLowerCase())&&f()}),v.stopIntervalTime)}function a(n){r.push(n)}function f(){window.clearInterval(o)}function l(){window.clearTimeout(i)}function d(n){return-1!==navigator.userAgent.toLocaleLowerCase().indexOf(n)}function s(n){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(n)}var v={md5:"",ondevtoolopen:function(){if(f(),v.url)window.location.href=v.url;else{try{window.opener=null,window.open("","_self"),window.close(),window.history.back()}catch(n){console.log(n)}setTimeout((function(){window.location.href="https://tackchen.gitee.io/404.html?h=".concat(encodeURIComponent(location.host))}),500)}},url:"",tkName:"ddtk",interval:200,disableMenu:!0,stopIntervalTime:5e3,clearIntervalWhenDevOpenTrigger:!1};function w(n,e,t,o,i,r){return h((u=h(h(e,n),h(o,r)))<<(c=i)|u>>>32-c,t);var u,c}function p(n,e,t,o,i,r,u){return w(e&t|~e&o,n,e,i,r,u)}function m(n,e,t,o,i,r,u){return w(e&o|t&~o,n,e,i,r,u)}function y(n,e,t,o,i,r,u){return w(e^t^o,n,e,i,r,u)}function b(n,e,t,o,i,r,u){return w(t^(e|~o),n,e,i,r,u)}function h(n,e){var t=(65535&n)+(65535&e);return(n>>16)+(e>>16)+(t>>16)<<16|65535&t}var g=function(n){return function(n){for(var e="0123456789abcdef",t="",o=0;o<4*n.length;o++)t+=e.charAt(n[o>>2]>>o%4*8+4&15)+e.charAt(n[o>>2]>>o%4*8&15);return t}(function(n,e){n[e>>5]|=128<>>9<<4)]=e;for(var t=1732584193,o=-271733879,i=-1732584194,r=271733878,u=0;u>5]|=(255&n.charCodeAt(t/8))<160,e=window.outerHeight-window.innerHeight>160;return!n&&!e||(D(I.SIZE),!1)}function O(){a((function(n){n%5==0&&function(){for(var n=new Date,e=0;e<1e3;e++)console.log(1);console.clear(),new Date-n>40&&(console.warn(new Date-n),D(I.LOG_TIME))}()}))}var I={UNKONW:-1,TO_STRING:0,DEFINE_ID:1,SIZE:2,LOG_TIME:3};function S(){var n;E(),(n=document.createElement("div")).__defineGetter__("id",(function(){D(I.DEFINE_ID)})),Object.defineProperty(n,"id",{get:function(){D(I.DEFINE_ID)}}),a((function(){console.log(n)})),T(),window.addEventListener("resize",(function(){setTimeout(T,100)}),!0),O()}function D(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:I.UNKONW;console.warn("You ar not allow to use DEVTOOL! 【type = ".concat(n,"】")),v.clearIntervalWhenDevOpenTrigger&&f(),l(),v.ondevtoolopen(n)}function _(n){!function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var e in v)void 0!==n[e]&&s(v[e])===s(n[e])&&(v[e]=n[e])}(n),function(){if(v.md5){var n=function(n){var e=window.location.search;if(""!==e){var t=new RegExp("(^|&)"+n+"=([^&]*)(&|$)","i"),o=e.substr(1).match(t);if(null!=o)return unescape(o[2])}return""}(v.tkName);if(g(n)===v.md5)return!0}return!1}()||(c(),window.addEventListener("keydown",(function(n){if(123===((n=n||window.event).keyCode||n.which)||n.shiftKey&&n.ctrlKey&&73===n.keyCode)return n.returnValue=!1,n.preventDefault(),!1}),!1),v.disableMenu&&window.addEventListener("contextmenu",(function(n){return(n=n||window.event).returnValue=!1,n.preventDefault(),!1}),!1),S())}_.md5=g,_.version="0.1.4",_.DETECTOR_TYPE=I,function(){if("undefined"!=typeof document){var n=document.querySelector("[disable-devtool-auto]");if(n){var e={};["md5","url","tk-name","interval","disable-menu"].forEach((function(t){var o=n.getAttribute(t);null!==o&&("interval"===t?o=parseInt(o):"disable-menu"===t&&(o="false"!==o),e[function(n){if(-1===n.indexOf("-"))return n;var e=!1;return n.split("").map((function(n){return"-"===n?(e=!0,""):e?(e=!1,n.toUpperCase()):n})).join("")}(t)]=o)})),_(e)}}}();e.default=_}]).default}));
\ No newline at end of file
diff --git a/npm/index.d.ts b/npm/index.d.ts
index 1b4bdbb..8eeaaee 100644
--- a/npm/index.d.ts
+++ b/npm/index.d.ts
@@ -1,15 +1,25 @@
+
+declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3;
declare interface optionStatic {
md5?: string; // 绕过禁用的md5值,详情见3.2,默认不启用绕过禁用
url?: string; // 关闭页面失败时的跳转页面,默认值为localhost
tkName?: string; // 绕过禁用时的url参数名称,默认为 ddtk
- ondevtoolopen?(): void; // 开发者面板打开的回调,启用时url参数无效
+ ondevtoolopen?(type: DETECTOR_TYPE): void; // 开发者面板打开的回调,启用时url参数无效
interval?: number; // 定时器的时间间隔 默认200ms
disableMenu?: boolean; // 是否禁用右键菜单 默认为true
stopIntervalTime?: number; // 在移动端时取消监视的等待时长
+ clearIntervalWhenDevOpenTrigger?: boolean; // 是否在触发之后停止监控
}
declare interface DDTStatic {
(option?: optionStatic): void;
md5(text?: string): string;
+ DETECTOR_TYPE: {
+ UNKONW: -1;
+ TO_STRING: 0;
+ DEFINE_ID: 1;
+ SIZE: 2;
+ LOG_TIME: 3;
+ }
version: string;
}
diff --git a/npm/package.json b/npm/package.json
index 5ea5563..f903bed 100644
--- a/npm/package.json
+++ b/npm/package.json
@@ -1,6 +1,6 @@
{
"name": "disable-devtool",
- "version": "0.1.3",
+ "version": "0.1.4",
"description": "Disable web developer tools from the f12 button, right-click and browser ",
"main": "disable-devtool.min.js",
"unpkg": "disable-devtool.min.js",
diff --git a/package.json b/package.json
index 310c327..3128d92 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "disable-devtool",
- "version": "0.1.3",
+ "version": "0.1.4",
"description": "Disable web developer tools from the f12 button, right-click and browser ",
"main": "disable-devtool.min.js",
"unpkg": "disable-devtool.min.js",
diff --git a/src/config.js b/src/config.js
index bcc8ee4..eeb0d5b 100644
--- a/src/config.js
+++ b/src/config.js
@@ -1,6 +1,6 @@
import {closeWindow} from './util';
-export let config = {
+export const config = {
md5: '',
ondevtoolopen: closeWindow, // ondevtoolopen 优先级高于 url
url: '',
@@ -8,10 +8,11 @@ export let config = {
interval: 200,
disableMenu: true, // 该参数ie下无效,ie 右键菜单会阻塞线程影响debug延迟计算 禁用右键菜单
stopIntervalTime: 5000, // 在移动端时取消监视的等待时长
+ clearIntervalWhenDevOpenTrigger: false, // 是否在触发之后停止监控
};
export function mergeConfig (opts = {}) {
- for (let k in config) {
+ for (const k in config) {
if (typeof opts[k] !== 'undefined' && typeof config[k] === typeof opts[k]) {
config[k] = opts[k];
}
diff --git a/src/detector/define-id.js b/src/detector/define-id.js
new file mode 100644
index 0000000..60e9321
--- /dev/null
+++ b/src/detector/define-id.js
@@ -0,0 +1,24 @@
+/*
+ * @Author: theajack
+ * @Date: 2021-07-24 23:15:49
+ * @LastEditor: theajack
+ * @LastEditTime: 2021-07-25 16:46:36
+ * @Description: Coding something
+ */
+import {DETECTOR_TYPE, triggerOnDevOpen} from './detector';
+import {registInterval} from '../interval';
+
+export default function detector () {
+ const div = document.createElement('div');
+ div.__defineGetter__('id', function () {
+ triggerOnDevOpen(DETECTOR_TYPE.DEFINE_ID);
+ });
+ Object.defineProperty(div, 'id', {
+ get: function () {
+ triggerOnDevOpen(DETECTOR_TYPE.DEFINE_ID);
+ },
+ });
+ registInterval(() => {
+ console.log(div);
+ });
+}
\ No newline at end of file
diff --git a/src/detector/detector.js b/src/detector/detector.js
new file mode 100644
index 0000000..690eb69
--- /dev/null
+++ b/src/detector/detector.js
@@ -0,0 +1,44 @@
+/*
+ * @Author: theajack
+ * @Date: 2021-07-24 23:16:34
+ * @LastEditor: theajack
+ * @LastEditTime: 2021-07-25 17:07:04
+ * @Description: Coding something
+ */
+
+import {config} from '../config';
+import ToStringDetector from './to-string';
+import DefineIdDetector from './define-id';
+import SizeDetector from './size';
+import LogTimeDetector from './log-time';
+import {clearDDInterval, clearDDTimeout} from '../interval';
+
+const detectorList = [];
+
+export const DETECTOR_TYPE = {
+ UNKONW: -1,
+ TO_STRING: 0,
+ DEFINE_ID: 1,
+ SIZE: 2,
+ LOG_TIME: 3,
+};
+
+export function registDetector (detector) {
+ detectorList.push(detector);
+}
+
+export function initDetectors () {
+ ToStringDetector();
+ DefineIdDetector();
+ SizeDetector();
+ LogTimeDetector();
+}
+
+export function triggerOnDevOpen (type = DETECTOR_TYPE.UNKONW) {
+ console.warn(`You ar not allow to use DEVTOOL! 【type = ${type}】`);
+ if (config.clearIntervalWhenDevOpenTrigger) {
+ clearDDInterval();
+ }
+ clearDDTimeout();
+ config.ondevtoolopen(type);
+}
\ No newline at end of file
diff --git a/src/detector/log-time.js b/src/detector/log-time.js
new file mode 100644
index 0000000..5a39f34
--- /dev/null
+++ b/src/detector/log-time.js
@@ -0,0 +1,30 @@
+/*
+ * @Author: theajack
+ * @Date: 2021-07-24 23:15:22
+ * @LastEditor: theajack
+ * @LastEditTime: 2021-07-25 16:35:51
+ * @Description: Coding something
+ */
+
+import {DETECTOR_TYPE, triggerOnDevOpen} from './detector';
+import {registInterval} from '../interval';
+
+function logTime () {
+ const d = new Date();
+ for (let i = 0; i < 1000; i++) {
+ console.log(1);
+ }
+ console.clear();
+ if (new Date() - d > 40) {
+ console.warn(new Date() - d);
+ triggerOnDevOpen(DETECTOR_TYPE.LOG_TIME);
+ }
+}
+
+export default function detector () {
+ registInterval((time) => {
+ if (time % 5 === 0) {
+ logTime();
+ }
+ });
+}
\ No newline at end of file
diff --git a/src/detector/size.js b/src/detector/size.js
new file mode 100644
index 0000000..f6da5c8
--- /dev/null
+++ b/src/detector/size.js
@@ -0,0 +1,28 @@
+/*
+ * @Author: theajack
+ * @Date: 2021-07-24 23:15:54
+ * @LastEditor: theajack
+ * @LastEditTime: 2021-07-25 17:12:51
+ * @Description: Coding something
+ * @FilePath: \disable-devtool\src\detector\size.js
+ */
+
+import {DETECTOR_TYPE, triggerOnDevOpen} from './detector';
+
+function checkWindowSizeUneven () {
+ const threshold = 160;
+ const widthUneven = window.outerWidth - window.innerWidth > threshold;
+ const heightUneven = window.outerHeight - window.innerHeight > threshold;
+ if (widthUneven || heightUneven) {
+ triggerOnDevOpen(DETECTOR_TYPE.SIZE);
+ return false;
+ }
+ return true;
+}
+
+export default function detector () {
+ checkWindowSizeUneven();
+ window.addEventListener('resize', () => {
+ setTimeout(checkWindowSizeUneven, 100);
+ }, true);
+}
\ No newline at end of file
diff --git a/src/detector/to-string.js b/src/detector/to-string.js
new file mode 100644
index 0000000..7a80fff
--- /dev/null
+++ b/src/detector/to-string.js
@@ -0,0 +1,38 @@
+/*
+ * @Author: theajack
+ * @Date: 2021-07-24 23:15:01
+ * @LastEditor: theajack
+ * @LastEditTime: 2021-07-25 16:54:13
+ * @Description: Coding something
+ */
+
+import {registInterval} from '../interval';
+import {isFirefox, isQQBrowser} from '../util';
+import {DETECTOR_TYPE, triggerOnDevOpen} from './detector';
+
+// 这个方法在chrome 中无论是否打开都会触发
+export default function detector () {
+ const isQQ = isQQBrowser();
+ const isFF = isFirefox();
+ if (!isQQ && !isFF) return;
+ let lastTime = 0;
+ const reg = /./;
+ console.log(reg);
+ reg.toString = function () {
+ if (isQQ) { // ! qq浏览器在控制台没有打开的时候也会触发 打开的时候会连续触发两次 使用这个来判断
+ const time = new Date().getTime();
+ if (lastTime && time - lastTime < 100) {
+ triggerOnDevOpen(DETECTOR_TYPE.TO_STRING);
+ } else {
+ lastTime = time;
+ }
+ } else if (isFF) {
+ triggerOnDevOpen(DETECTOR_TYPE.TO_STRING);
+ }
+ return '';
+ };
+
+ registInterval(() => {
+ console.log(reg);
+ });
+}
\ No newline at end of file
diff --git a/src/index.d.ts b/src/index.d.ts
index 1b4bdbb..8eeaaee 100644
--- a/src/index.d.ts
+++ b/src/index.d.ts
@@ -1,15 +1,25 @@
+
+declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3;
declare interface optionStatic {
md5?: string; // 绕过禁用的md5值,详情见3.2,默认不启用绕过禁用
url?: string; // 关闭页面失败时的跳转页面,默认值为localhost
tkName?: string; // 绕过禁用时的url参数名称,默认为 ddtk
- ondevtoolopen?(): void; // 开发者面板打开的回调,启用时url参数无效
+ ondevtoolopen?(type: DETECTOR_TYPE): void; // 开发者面板打开的回调,启用时url参数无效
interval?: number; // 定时器的时间间隔 默认200ms
disableMenu?: boolean; // 是否禁用右键菜单 默认为true
stopIntervalTime?: number; // 在移动端时取消监视的等待时长
+ clearIntervalWhenDevOpenTrigger?: boolean; // 是否在触发之后停止监控
}
declare interface DDTStatic {
(option?: optionStatic): void;
md5(text?: string): string;
+ DETECTOR_TYPE: {
+ UNKONW: -1;
+ TO_STRING: 0;
+ DEFINE_ID: 1;
+ SIZE: 2;
+ LOG_TIME: 3;
+ }
version: string;
}
diff --git a/src/interval.js b/src/interval.js
index e2b2913..cee5a92 100644
--- a/src/interval.js
+++ b/src/interval.js
@@ -2,24 +2,26 @@ import {config} from './config';
import {hackAlert, isPC, onPageShowHide} from './util';
let interval = null, timer = null;
-let calls = [];
+const calls = [];
+let time = 0;
export function initInterval () {
let _pause = false;
- let pause = () => {_pause = true;};
- let goon = () => {_pause = false;};
+ const pause = () => {_pause = true;};
+ const goon = () => {_pause = false;};
hackAlert(pause, goon); // 防止 alert等方法触发了debug延迟计算
onPageShowHide(goon, pause); // 防止切后台触发了debug延迟计算
interval = window.setInterval(() => {
if (_pause) return;
- calls.forEach(fn => {fn();});
+ calls.forEach(fn => {fn(time++);});
+ console.clear();
}, config.interval);
// 两秒之后判断 如果不是pc去掉定时器interval,为了优化移动端的性能
// 如果控制面板被打开了该定时器timer会被清除
timer = setTimeout(() => {
if (!isPC()) {
- clearInterval();
+ clearDDInterval();
}
}, config.stopIntervalTime);
}
@@ -28,10 +30,10 @@ export function registInterval (fn) {
calls.push(fn);
}
-export function clearInterval () {
+export function clearDDInterval () {
window.clearInterval(interval);
}
-export function clearTimeout () {
+export function clearDDTimeout () {
window.clearTimeout(timer);
}
\ No newline at end of file
diff --git a/src/key-menu.js b/src/key-menu.js
index 0d72d57..5519724 100644
--- a/src/key-menu.js
+++ b/src/key-menu.js
@@ -3,7 +3,7 @@ import {config} from './config';
export function disableKeyAndMenu () {
window.addEventListener('keydown', (e) => {
e = e || window.event;
- let keyCode = e.keyCode || e.which;
+ const keyCode = e.keyCode || e.which;
// alert(e.keyCode);
if (keyCode === 123 || (e.shiftKey && e.ctrlKey && e.keyCode === 73)) {
e.returnValue = false;
diff --git a/src/main.js b/src/main.js
index b6b7f0d..543706d 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,39 +1,26 @@
import {disableKeyAndMenu} from './key-menu';
-import {initInterval, registInterval, clearTimeout} from './interval';
-import {formatName, getUrlParam, isFirefox, isQQBrowser} from './util';
+import {initInterval} from './interval';
+import {formatName, getUrlParam} from './util';
import {mergeConfig, config} from './config';
import md5 from './md5';
import version from './version';
+import {DETECTOR_TYPE, initDetectors} from './detector/detector';
export function disableDevtool (opts) {
mergeConfig(opts);
if (checkTk()) {return;}
initInterval();
disableKeyAndMenu();
- initDevTool();
+ initDetectors();
}
-
+
disableDevtool.md5 = md5;
disableDevtool.version = version;
-
-let hasOpened = false;
-export function onDevToolOpen () {
- let time = new Date().getTime();
- console.log('You ar not allow to use DEVTOOL!', time);
- if (hasOpened) {return {time, next () {}};}
- if (!isQQBrowser()) {
- hasOpened = true;
- }
- return {time, next () {
- hasOpened = true;
- clearTimeout();
- config.ondevtoolopen();
- }};
-}
+disableDevtool.DETECTOR_TYPE = DETECTOR_TYPE;
function checkTk () {
if (config.md5) { // 启用了 md5
- let tk = getUrlParam(config.tkName);
+ const tk = getUrlParam(config.tkName);
if (md5(tk) === config.md5) { // 命中tk
return true;
}
@@ -41,51 +28,15 @@ function checkTk () {
return false;
}
-function initDevTool () {
- const isQQ = isQQBrowser();
- const isFF = isFirefox();
- let toTest = '';
- if (isQQ) {
- let lastTime = 0;
- toTest = /./;
- console.log(toTest);
- toTest.toString = function () {
- let {time, next} = onDevToolOpen();
- if (lastTime && time - lastTime < 100) {
- next();
- } else {
- lastTime = time;
- }
- return '';
- };
- } else if (isFF) {
- toTest = /./;
- console.log(toTest);
- toTest.toString = function () {
- onDevToolOpen().next();
- return '';
- };
- } else {
- toTest = new Image();
- toTest.__defineGetter__('id', function () {
- onDevToolOpen().next();
- });
- }
- registInterval(() => {
- console.log(toTest);
- console.clear();
- });
-}
-
function checkScriptUse () {
if (typeof document === 'undefined') {
return;
}
- let dom = document.querySelector('[disable-devtool-auto]');
+ const dom = document.querySelector('[disable-devtool-auto]');
if (!dom) {
return;
}
- let json = {};
+ const json = {};
['md5', 'url', 'tk-name', 'interval', 'disable-menu'].forEach(name => {
let value = dom.getAttribute(name);
if (value !== null) {
diff --git a/src/util.js b/src/util.js
index 9e4101c..cd92b2c 100644
--- a/src/util.js
+++ b/src/util.js
@@ -1,27 +1,29 @@
import {config} from './config';
+import {clearDDInterval} from './interval';
export function isPC () {
return !/(iphone|ipad|ipod|ios|android)/i.test(navigator.userAgent.toLowerCase());
}
export function closeWindow () {
- // 需要是有js跳转到这个页面才可以关闭这个页面
+ clearDDInterval();
if (config.url) {
window.location.href = config.url;
} else {
try {
window.opener = null;
window.open('', '_self');
+ // 需要是有js跳转到这个页面才可以关闭这个页面
window.close();
window.history.back();
} catch (e) {
console.log(e);
}
setTimeout(() => {
+ // 否则执行跳转到 url
window.location.href = `https://tackchen.gitee.io/404.html?h=${encodeURIComponent(location.host)}`;
}, 500);
}
- // 否则执行跳转到 url
}
export function getNowTime () {
@@ -29,10 +31,10 @@ export function getNowTime () {
}
export function getUrlParam (name) {
- let search = window.location.search;
+ const search = window.location.search;
if (search !== '') {
- let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
- let r = search.substr(1).match(reg);
+ const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
+ const r = search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
@@ -44,7 +46,7 @@ export function formatName (name) {
if (name.indexOf('-') === -1) {
return name;
}
- var flag = false;
+ let flag = false;
return name.split('').map(c => {
if (c === '-') {
flag = true;
@@ -60,7 +62,7 @@ export function formatName (name) {
export function onPageShowHide (onshow, onhide) {
- var hidden, state, visibilityChange;
+ let hidden, state, visibilityChange;
if (typeof document.hidden !== 'undefined') {
hidden = 'hidden';
visibilityChange = 'visibilitychange';
@@ -78,7 +80,7 @@ export function onPageShowHide (onshow, onhide) {
visibilityChange = 'webkitvisibilitychange';
state = 'webkitVisibilityState';
}
- var cb = function () {
+ const cb = function () {
if (document[state] === hidden) {
onhide();
} else {
@@ -90,10 +92,10 @@ export function onPageShowHide (onshow, onhide) {
}
export function hackAlert (before, after) {
- let _alert = window.alert;
- let _confirm = window.confirm;
- let _prompt = window.prompt;
- let mod = (fn) => {
+ const _alert = window.alert;
+ const _confirm = window.confirm;
+ const _prompt = window.prompt;
+ const mod = (fn) => {
return (...args) => {
if (before) {before();}
fn(...args);
@@ -106,15 +108,15 @@ export function hackAlert (before, after) {
}
export function isIE () {
- var userAgent = navigator.userAgent; // 取得浏览器的userAgent字符串
- var isIE = userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1; // 判断是否IE<11浏览器
- var isEdge = userAgent.indexOf('Edge') > -1 && !isIE; // 判断是否IE的Edge浏览器
- var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf('rv:11.0') > -1;
+ const userAgent = navigator.userAgent; // 取得浏览器的userAgent字符串
+ const isIE = userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1; // 判断是否IE<11浏览器
+ const isEdge = userAgent.indexOf('Edge') > -1 && !isIE; // 判断是否IE的Edge浏览器
+ const isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf('rv:11.0') > -1;
return isIE || isEdge || isIE11;
// if (isIE) {
- // var reIE = new RegExp('MSIE (\\d+\\.\\d+);');
+ // let reIE = new RegExp('MSIE (\\d+\\.\\d+);');
// reIE.test(userAgent);
- // var fIEVersion = parseFloat(RegExp['$1']);
+ // let fIEVersion = parseFloat(RegExp['$1']);
// if (fIEVersion == 7) {
// return 7;
// } else if (fIEVersion == 8) {
diff --git a/src/version.js b/src/version.js
index 8624e2e..f566764 100644
--- a/src/version.js
+++ b/src/version.js
@@ -1 +1 @@
-export default '0.1.3';
\ No newline at end of file
+export default '0.1.4';
\ No newline at end of file