From f8d01801b817e0eb8082d6ce44fdd42213d29b0e Mon Sep 17 00:00:00 2001 From: tackchen Date: Mon, 15 Nov 2021 23:58:47 +0800 Subject: [PATCH] feat: 0.1.7 --- README.cn.md | 17 +++-- README.md | 22 ++++--- helper/version.en.md | 62 +++++++++++++++++++ helper/version.md | 9 ++- index.html | 9 ++- npm/README.cn.md | 17 +++-- npm/README.md | 22 ++++--- npm/disable-devtool.min.js | 2 +- npm/index.d.ts | 10 ++- npm/package.json | 2 +- package.json | 2 +- public/main.js | 9 +-- src/config.js | 8 ++- src/detector/date-to-string.js | 31 ++++++++++ src/detector/debugger.js | 21 +++++++ src/detector/detector.js | 39 +++++++++--- src/detector/func-to-string.js | 31 ++++++++++ .../{to-string.js => reg-to-string.js} | 6 +- src/detector/size.js | 9 ++- src/index.d.ts | 10 ++- src/interval.js | 2 +- src/main.js | 8 ++- src/version.js | 2 +- 23 files changed, 280 insertions(+), 70 deletions(-) create mode 100644 helper/version.en.md create mode 100644 src/detector/date-to-string.js create mode 100644 src/detector/debugger.js create mode 100644 src/detector/func-to-string.js rename src/detector/{to-string.js => reg-to-string.js} (86%) diff --git a/README.cn.md b/README.cn.md index 0036576..fc9bc9e 100644 --- a/README.cn.md +++ b/README.cn.md @@ -110,10 +110,11 @@ declare interface optionStatic { interval?: number; // 定时器的时间间隔 默认200ms disableMenu?: boolean; // 是否禁用右键菜单 默认为true stopIntervalTime?: number; // 在移动端时取消监视的等待时长 - clearIntervalWhenDevOpenTrigger?: boolean; // 是否在触发之后停止监控 + clearIntervalWhenDevOpenTrigger?: boolean; // 是否在触发之后停止监控 默认为false + detactors?: Array; // 启用的检测器 检测器详情见 3.5 默认为全部,建议使用全部 } -declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3; +declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3 | 4; // 检测器详情见 3.5 ``` ### 3.2 md5 与 tk 绕过禁用 @@ -141,6 +142,7 @@ disableDevtool.md5('xxx'); tk-name='xxx' interval='xxx' disable-menu='xxx' + detectors='xxx' > ``` @@ -149,6 +151,7 @@ disableDevtool.md5('xxx'); 1. 如希望自动禁用,属性配置时必须要带上 `disable-devtool-auto` 属性 2. 属性配置都是可选的,字段与3.1中一致,区别是将驼峰形式改成横线分割 3. 该script标签建议放在body最底部 +4. detectors 需要使用空格分割,如 detectors='1 2 3' ### 3.4 script不使用属性配置 @@ -163,14 +166,16 @@ disableDevtool.md5('xxx'); ### 3.5 监测模式 -Disable-Devtool 有四种监测模式, DisableDevtool.DETECTOR_TYPE 为所有的监测模式 +Disable-Devtool 有五种监测模式, DisableDevtool.DETECTOR_TYPE 为所有的监测模式枚举 ```js const DETECTOR_TYPE = { UNKONW: -1, - TO_STRING: 0, - DEFINE_ID: 1, - SIZE: 2, + REG_TO_STRING: 0, // 根据正则检测 + DEFINE_ID: 1, // 根据dom id检测 + SIZE: 2, // 根据窗口尺寸检测 + DATE_TO_STRING: 3, // 根据Date.toString 检测 + FUNC_TO_STRING: 4, // 根据Function.toString 检测 } ``` diff --git a/README.md b/README.md index eea4e59..da7432f 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ test

-**[中文](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)** +**[中文](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.en.md) | [Gitee](https://gitee.com/theajack/disable-devtool)** ## 1. Quick use @@ -108,11 +108,11 @@ declare interface optionStatic { 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 + clearIntervalWhenDevOpenTrigger?: boolean; // Whether to stop monitoring after triggering The default is false + detactors?: Array; // Enabled detectors For details of detectors, see 3.5. The default is all, it is recommended to use all } -declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3; +declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3 | 4; // For details of the detector, see 3.5 ``` ### 3.2 md5 and tk bypass disable @@ -140,6 +140,7 @@ disableDevtool.md5('xxx'); tk-name='xxx' interval='xxx' disable-menu='xxx' + detectors='xxx' > ``` @@ -148,6 +149,7 @@ Note: 1. If you want to automatically disable,you must bring the `disable-devtool-auto` attribute when configuring attributes 2. Attribute configuration is optional, the fields are the same as in 3.1, the difference is that the hump form is changed to horizontal line division 3. The script tag is recommended to be placed at the bottom of the body +4. detectors Need to use spaces to separate, such as detectors='1 2 3' ### 3.4 script does not use attribute configuration @@ -162,14 +164,16 @@ Note: ### 3.5 Monitoring Mode -Disable-Devtool has four monitoring modes, DisableDevtool.DETECTOR_TYPE is all monitoring modes +Disable-Devtool has five monitoring modes, DisableDevtool.DETECTOR_TYPE is an enumeration of all monitoring modes ```js const DETECTOR_TYPE = { - UNKONW: -1, - TO_STRING: 0, - DEFINE_ID: 1, - SIZE: 2, + UNKONW: -1, + REG_TO_STRING: 0, // According to regular detection + DEFINE_ID: 1, // Detect according to dom id + SIZE: 2, // Detect according to window size + DATE_TO_STRING: 3, // Check according to Date.toString + FUNC_TO_STRING: 4, // Detect according to Function.toString } ``` diff --git a/helper/version.en.md b/helper/version.en.md new file mode 100644 index 0000000..162f932 --- /dev/null +++ b/helper/version.en.md @@ -0,0 +1,62 @@ +# Version Log: + +## 0.0.1 +1. Support configurable whether to disable the right-click menu +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 disabling (use tk and md5 encryption for url parameters) +5. Support almost all browsers +6. Highly configurable +7. Minimal use, small size (only 7kb) +8. Support npm reference and script tag reference (attribute configuration) + +## 0.0.2 +1. Solve the bug of invalid CDN file + +## 0.0.3 +1. Solve the problem of native methods such as alert that will affect debug timing +2. Resolve the page and the background will affect the debug timing. +3. Compatible with ie, the disableMenu parameter is invalid under ie, because the right-click under ie will block the main process and cannot monitor +4. Add config.stopIntervalTime to indicate the waiting time for canceling monitoring on the mobile terminal +5. Optimize the logic of judging the opening of the developer tool + +## 0.0.4 +1. Modify webpack packaging configuration + +## 0.0.5 +1. Optimize onDevToolOpen event trigger logic + +## 0.0.6 +1. For the label attribute configuration, remove the id='disable-devtool' condition and use the disable-devtool-auto attribute +2. Modify the readme + +## 0.1.0 +1. Fix the invalid problem under firefox and qq browser +2. Enable disableMenu configuration +3. Remove internal debug logic +4. Add the default redirect 404 page + +## 0.1.1 +1. Increase the delay of jumping to the default page after history.back +2. Optimize ondeltoolopen logic + +## 0.1.2 +1. Add the judgment of the document to adapt to the server-side rendering npm call + +## 0.1.3 +1. Fix the bug that disableMenu parameter is invalid + +## 0.1.4 +1. Add detector, add multiple monitoring modes +2. Use logTime mode, compatible with mac and linux +3. Add the clearIntervalWhenDevOpenTrigger parameter +4. ondevtoolopen adds monitoring mode callback parameters + +## 0.1.5 +1. Remove the log-time monitoring type (because of inaccuracy) + +## 0.1.6 - 0.1.7 +1. Add DateToString monitoring type +2. Add FuncToString monitoring type +3. Add detectors configuration +4. Fix ios 15 accidental injury problem \ No newline at end of file diff --git a/helper/version.md b/helper/version.md index dc28ace..c7b323d 100644 --- a/helper/version.md +++ b/helper/version.md @@ -53,5 +53,10 @@ 4. ondevtoolopen 增加 监测模式 回调参数 ## 0.1.5 - -1. 去掉log-time监测类型(因为不准确) \ No newline at end of file +1. 去掉log-time监测类型(因为不准确) + +## 0.1.6 - 0.1.7 +1. 增加 DateToString 监测类型 +2. 增加 FuncToString 监测类型 +3. 增加 detectors 配置 +4. 修复ios 15误伤问题 \ No newline at end of file diff --git a/index.html b/index.html index 3db1f0e..d41f7cb 100644 --- a/index.html +++ b/index.html @@ -126,6 +126,7 @@ disableDevtool(options);

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 + detactors?: Array; // Enabled detectors For details of detectors, see 3.5. The default is all, it is recommended to use all } declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3;

@@ -160,7 +161,8 @@ declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3;

url='xxx' tk-name='xxx' interval='xxx' - disable-menu='xxx'> + disable-menu='xxx' + detectors='xxx'> </script>

@@ -168,7 +170,8 @@ declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3;

1. You must bring the disable-devtool-auto attribute when configuring attributes
2.Attribute configuration is optional, the fields are the same as in 3.1, the difference is that the hump form is changed to horizontal line division
- 3. The script tag is recommended to be placed at the bottom of the body

+ 3. The script tag is recommended to be placed at the bottom of the body
+ 4. detectors Need to use spaces to separate, such as detectors='1 2 3'

3.3 script does not use attribute configuration

@@ -181,7 +184,7 @@ declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3;

``` @@ -149,6 +151,7 @@ disableDevtool.md5('xxx'); 1. 如希望自动禁用,属性配置时必须要带上 `disable-devtool-auto` 属性 2. 属性配置都是可选的,字段与3.1中一致,区别是将驼峰形式改成横线分割 3. 该script标签建议放在body最底部 +4. detectors 需要使用空格分割,如 detectors='1 2 3' ### 3.4 script不使用属性配置 @@ -163,14 +166,16 @@ disableDevtool.md5('xxx'); ### 3.5 监测模式 -Disable-Devtool 有四种监测模式, DisableDevtool.DETECTOR_TYPE 为所有的监测模式 +Disable-Devtool 有五种监测模式, DisableDevtool.DETECTOR_TYPE 为所有的监测模式枚举 ```js const DETECTOR_TYPE = { UNKONW: -1, - TO_STRING: 0, - DEFINE_ID: 1, - SIZE: 2, + REG_TO_STRING: 0, // 根据正则检测 + DEFINE_ID: 1, // 根据dom id检测 + SIZE: 2, // 根据窗口尺寸检测 + DATE_TO_STRING: 3, // 根据Date.toString 检测 + FUNC_TO_STRING: 4, // 根据Function.toString 检测 } ``` diff --git a/npm/README.md b/npm/README.md index eea4e59..da7432f 100644 --- a/npm/README.md +++ b/npm/README.md @@ -35,7 +35,7 @@ test

-**[中文](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)** +**[中文](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.en.md) | [Gitee](https://gitee.com/theajack/disable-devtool)** ## 1. Quick use @@ -108,11 +108,11 @@ declare interface optionStatic { 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 + clearIntervalWhenDevOpenTrigger?: boolean; // Whether to stop monitoring after triggering The default is false + detactors?: Array; // Enabled detectors For details of detectors, see 3.5. The default is all, it is recommended to use all } -declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3; +declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3 | 4; // For details of the detector, see 3.5 ``` ### 3.2 md5 and tk bypass disable @@ -140,6 +140,7 @@ disableDevtool.md5('xxx'); tk-name='xxx' interval='xxx' disable-menu='xxx' + detectors='xxx' > ``` @@ -148,6 +149,7 @@ Note: 1. If you want to automatically disable,you must bring the `disable-devtool-auto` attribute when configuring attributes 2. Attribute configuration is optional, the fields are the same as in 3.1, the difference is that the hump form is changed to horizontal line division 3. The script tag is recommended to be placed at the bottom of the body +4. detectors Need to use spaces to separate, such as detectors='1 2 3' ### 3.4 script does not use attribute configuration @@ -162,14 +164,16 @@ Note: ### 3.5 Monitoring Mode -Disable-Devtool has four monitoring modes, DisableDevtool.DETECTOR_TYPE is all monitoring modes +Disable-Devtool has five monitoring modes, DisableDevtool.DETECTOR_TYPE is an enumeration of all monitoring modes ```js const DETECTOR_TYPE = { - UNKONW: -1, - TO_STRING: 0, - DEFINE_ID: 1, - SIZE: 2, + UNKONW: -1, + REG_TO_STRING: 0, // According to regular detection + DEFINE_ID: 1, // Detect according to dom id + SIZE: 2, // Detect according to window size + DATE_TO_STRING: 3, // Check according to Date.toString + FUNC_TO_STRING: 4, // Detect according to Function.toString } ``` diff --git a/npm/disable-devtool.min.js b/npm/disable-devtool.min.js index b2dddcf..1ac6409 100644 --- a/npm/disable-devtool.min.js +++ b/npm/disable-devtool.min.js @@ -1 +1 @@ -!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.DisableDevtool=n():e.DisableDevtool=n()}(this,(function(){return function(e){var n={};function t(o){if(n[o])return n[o].exports;var i=n[o]={i:o,l:!1,exports:{}};return e[o].call(i.exports,i,i.exports,t),i.l=!0,i.exports}return t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var i in e)t.d(o,i,function(n){return e[n]}.bind(null,i));return o},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=0)}([function(e,n,t){"use strict";t.r(n);var o=null,i=null,r=[],u=0;function c(){var e,n,t,c,a,d,l=!1,s=function(){l=!0},w=function(){l=!1};e=s,n=w,t=window.alert,c=window.confirm,a=window.prompt,d=function(t){return function(){e&&e(),t.apply(void 0,arguments),n&&n()}},window.alert=d(t),window.confirm=d(c),window.prompt=d(a),function(e,n){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?n():e()};document.removeEventListener(i,r,!1),document.addEventListener(i,r,!1)}(w,s),o=window.setInterval((function(){l||(r.forEach((function(e){e(u++)})),console.clear())}),v.interval),i=setTimeout((function(){/(iphone|ipad|ipod|ios|android)/i.test(navigator.userAgent.toLowerCase())&&f()}),v.stopIntervalTime)}function a(e){r.push(e)}function f(){window.clearInterval(o)}function d(){window.clearTimeout(i)}function l(e){return-1!==navigator.userAgent.toLocaleLowerCase().indexOf(e)}function s(e){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}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(e){console.log(e)}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(e,n,t,o,i,r){return h((u=h(h(n,e),h(o,r)))<<(c=i)|u>>>32-c,t);var u,c}function p(e,n,t,o,i,r,u){return w(n&t|~n&o,e,n,i,r,u)}function m(e,n,t,o,i,r,u){return w(n&o|t&~o,e,n,i,r,u)}function y(e,n,t,o,i,r,u){return w(n^t^o,e,n,i,r,u)}function b(e,n,t,o,i,r,u){return w(t^(n|~o),e,n,i,r,u)}function h(e,n){var t=(65535&e)+(65535&n);return(e>>16)+(n>>16)+(t>>16)<<16|65535&t}var g=function(e){return function(e){for(var n="0123456789abcdef",t="",o=0;o<4*e.length;o++)t+=n.charAt(e[o>>2]>>o%4*8+4&15)+n.charAt(e[o>>2]>>o%4*8&15);return t}(function(e,n){e[n>>5]|=128<>>9<<4)]=n;for(var t=1732584193,o=-271733879,i=-1732584194,r=271733878,u=0;u>5]|=(255&e.charCodeAt(t/8))<160,n=window.outerHeight-window.innerHeight>160;return!e&&!n||(I(T.SIZE),!1)}var T={UNKONW:-1,TO_STRING:0,DEFINE_ID:1,SIZE:2};function O(){var e;E(),(e=document.createElement("div")).__defineGetter__("id",(function(){I(T.DEFINE_ID)})),Object.defineProperty(e,"id",{get:function(){I(T.DEFINE_ID)}}),a((function(){console.log(e)})),S(),window.addEventListener("resize",(function(){setTimeout(S,100)}),!0)}function I(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:T.UNKONW;console.warn("You ar not allow to use DEVTOOL! 【type = ".concat(e,"】")),v.clearIntervalWhenDevOpenTrigger&&f(),d(),v.ondevtoolopen(e)}function _(e){!function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var n in v)void 0!==e[n]&&s(v[n])===s(e[n])&&(v[n]=e[n])}(e),function(){if(v.md5){var e=function(e){var n=window.location.search;if(""!==n){var t=new RegExp("(^|&)"+e+"=([^&]*)(&|$)","i"),o=n.substr(1).match(t);if(null!=o)return unescape(o[2])}return""}(v.tkName);if(g(e)===v.md5)return!0}return!1}()||(c(),window.addEventListener("keydown",(function(e){if(123===((e=e||window.event).keyCode||e.which)||e.shiftKey&&e.ctrlKey&&73===e.keyCode)return e.returnValue=!1,e.preventDefault(),!1}),!1),v.disableMenu&&window.addEventListener("contextmenu",(function(e){return(e=e||window.event).returnValue=!1,e.preventDefault(),!1}),!1),O())}_.md5=g,_.version="0.1.5",_.DETECTOR_TYPE=T,function(){if("undefined"!=typeof document){var e=document.querySelector("[disable-devtool-auto]");if(e){var n={};["md5","url","tk-name","interval","disable-menu"].forEach((function(t){var o=e.getAttribute(t);null!==o&&("interval"===t?o=parseInt(o):"disable-menu"===t&&(o="false"!==o),n[function(e){if(-1===e.indexOf("-"))return e;var n=!1;return e.split("").map((function(e){return"-"===e?(n=!0,""):n?(n=!1,e.toUpperCase()):e})).join("")}(t)]=o)})),_(n)}}}();n.default=_}]).default})); \ No newline at end of file +!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.DisableDevtool=n():e.DisableDevtool=n()}(this,(function(){return function(e){var n={};function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}return t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)t.d(o,r,function(n){return e[n]}.bind(null,r));return o},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=0)}([function(e,n,t){"use strict";t.r(n);var o=null,r=null,i=[],u=0;function c(){var e,n,t,c,a,f,d=!1,s=function(){d=!0},w=function(){d=!1};e=s,n=w,t=window.alert,c=window.confirm,a=window.prompt,f=function(t){return function(){e&&e(),t.apply(void 0,arguments),n&&n()}},window.alert=f(t),window.confirm=f(c),window.prompt=f(a),function(e,n){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?n():e()};document.removeEventListener(r,i,!1),document.addEventListener(r,i,!1)}(w,s),o=window.setInterval((function(){d||(i.forEach((function(e){e(u++)})),console.clear())}),v.interval),r=setTimeout((function(){/(iphone|ipad|ipod|ios|android)/i.test(navigator.userAgent.toLowerCase())&&l()}),v.stopIntervalTime)}function a(e){i.push(e)}function l(){window.clearInterval(o)}function f(){window.clearTimeout(r)}function d(e){return-1!==navigator.userAgent.toLocaleLowerCase().indexOf(e)}function s(e){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var v={md5:"",ondevtoolopen:function(){if(l(),v.url)window.location.href=v.url;else{try{window.opener=null,window.open("","_self"),window.close(),window.history.back()}catch(e){console.log(e)}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,detectors:"all"},w=["detectors"];function p(e,n,t,o,r,i){return g((u=g(g(n,e),g(o,i)))<<(c=r)|u>>>32-c,t);var u,c}function m(e,n,t,o,r,i,u){return p(n&t|~n&o,e,n,r,i,u)}function y(e,n,t,o,r,i,u){return p(n&o|t&~o,e,n,r,i,u)}function b(e,n,t,o,r,i,u){return p(n^t^o,e,n,r,i,u)}function h(e,n,t,o,r,i,u){return p(t^(n|~o),e,n,r,i,u)}function g(e,n){var t=(65535&e)+(65535&n);return(e>>16)+(n>>16)+(t>>16)<<16|65535&t}var T,_=function(e){return function(e){for(var n="0123456789abcdef",t="",o=0;o<4*e.length;o++)t+=n.charAt(e[o>>2]>>o%4*8+4&15)+n.charAt(e[o>>2]>>o%4*8&15);return t}(function(e,n){e[n>>5]|=128<>>9<<4)]=n;for(var t=1732584193,o=-271733879,r=-1732584194,i=271733878,u=0;u>5]|=(255&e.charCodeAt(t/8))<20,n=window.outerHeight-window.innerHeight>250;return!e&&!n||(D(S.SIZE),!1)}function O(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}var S={UNKONW:-1,REG_TO_STRING:0,DEFINE_ID:1,SIZE:2,DATE_TO_STRING:3,FUNC_TO_STRING:4},I=(O(T={},S.REG_TO_STRING,(function(){var e=d("qqbrowser"),n=d("firefox");if(e||n){var t=0,o=/./;console.log(o),o.toString=function(){if(e){var o=(new Date).getTime();t&&o-t<100?D(S.REG_TO_STRING):t=o}else n&&D(S.REG_TO_STRING);return""},a((function(){console.log(o)}))}})),O(T,S.DEFINE_ID,(function(){var e=document.createElement("div");e.__defineGetter__("id",(function(){D(S.DEFINE_ID)})),Object.defineProperty(e,"id",{get:function(){D(S.DEFINE_ID)}}),a((function(){console.log(e)}))})),O(T,S.SIZE,(function(){E(),window.addEventListener("resize",(function(){setTimeout(E,100)}),!0)})),O(T,S.DATE_TO_STRING,(function(){var e=0,n=new Date;n.toString=function(){return e++,""},a((function(){e=0,console.log(n),console.clear(),e>=2&&D(S.DATE_TO_STRING)}))})),O(T,S.FUNC_TO_STRING,(function(){var e=0,n=function(){};n.toString=function(){return e++,""},a((function(){e=0,console.log(n),console.clear(),e>=2&&D(S.FUNC_TO_STRING)}))})),T);function D(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:S.UNKONW;console.warn("You ar not allow to use DEVTOOL! 【type = ".concat(e,"】")),document.body.innerHTML="You ar not allow to use DEVTOOL! 【type = ".concat(e,"】"),v.clearIntervalWhenDevOpenTrigger&&l(),f(),v.ondevtoolopen(e)}function N(e){!function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var n in v)void 0===e[n]||s(v[n])!==s(e[n])&&!w.includes(n)||(v[n]=e[n])}(e),function(){if(v.md5){var e=function(e){var n=window.location.search;if(""!==n){var t=new RegExp("(^|&)"+e+"=([^&]*)(&|$)","i"),o=n.substr(1).match(t);if(null!=o)return unescape(o[2])}return""}(v.tkName);if(_(e)===v.md5)return!0}return!1}()||(c(),window.addEventListener("keydown",(function(e){if(123===((e=e||window.event).keyCode||e.which)||e.shiftKey&&e.ctrlKey&&73===e.keyCode)return e.returnValue=!1,e.preventDefault(),!1}),!1),v.disableMenu&&window.addEventListener("contextmenu",(function(e){return(e=e||window.event).returnValue=!1,e.preventDefault(),!1}),!1),("all"===v.detectors?Object.keys(I):v.detectors).forEach((function(e){I[e]&&I[e]()})))}N.md5=_,N.version="0.1.7",N.DETECTOR_TYPE=S,function(){if("undefined"!=typeof document){var e=document.querySelector("[disable-devtool-auto]");if(e){var n={};["md5","url","tk-name","interval","disable-menu","detectors"].forEach((function(t){var o=e.getAttribute(t);null!==o&&("interval"===t?o=parseInt(o):"disable-menu"===t?o="false"!==o:"detector"===t&&"all"!==o&&(o=o.split(" ")),n[function(e){if(-1===e.indexOf("-"))return e;var n=!1;return e.split("").map((function(e){return"-"===e?(n=!0,""):n?(n=!1,e.toUpperCase()):e})).join("")}(t)]=o)})),N(n)}}}();n.default=N}]).default})); \ No newline at end of file diff --git a/npm/index.d.ts b/npm/index.d.ts index c022cbb..1fd3a5d 100644 --- a/npm/index.d.ts +++ b/npm/index.d.ts @@ -1,5 +1,5 @@ -declare type DETECTOR_TYPE = -1 | 0 | 1 | 2; +declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3 | 4; declare interface optionStatic { md5?: string; // 绕过禁用的md5值,详情见3.2,默认不启用绕过禁用 url?: string; // 关闭页面失败时的跳转页面,默认值为localhost @@ -9,16 +9,20 @@ declare interface optionStatic { disableMenu?: boolean; // 是否禁用右键菜单 默认为true stopIntervalTime?: number; // 在移动端时取消监视的等待时长 clearIntervalWhenDevOpenTrigger?: boolean; // 是否在触发之后停止监控 + detectors: Array; // 启用的监测器 默认为全部 } declare interface DDTStatic { (option?: optionStatic): void; md5(text?: string): string; DETECTOR_TYPE: { UNKONW: -1; - TO_STRING: 0; + REG_TO_STRING: 0; DEFINE_ID: 1; SIZE: 2; - // LOG_TIME: 3; + DATE_TO_STRING: 3; + FUNC_TO_STRING: 4; + // DEBUGGER: 5; + // LOG_TIME: 6; } version: string; } diff --git a/npm/package.json b/npm/package.json index eb678da..8f8f666 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "disable-devtool", - "version": "0.1.5", + "version": "0.1.7", "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 4fd6671..af9b196 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "disable-devtool", - "version": "0.1.5", + "version": "0.1.7", "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/public/main.js b/public/main.js index 67ea270..fdfb7fe 100644 --- a/public/main.js +++ b/public/main.js @@ -4,16 +4,17 @@ import disableDevtool from '../src'; // debugger; disableDevtool({ - md5: 'd4de605ccb923b7e876b3218a1474653', + md5: '0b9e05caf5000360ec1c263335bd83fe', // ddtk // url: 'https://www.qq.com', // ondevtoolopen: () => { // window.location.href = 'https://www.qq.com'; // }, interval: 1000, - tkName: 'xx', + // tkName: 'ddtk', // disableMenu: false // url: 'https://www.baidu.com' + // detectors: [disableDevtool.DETECTOR_TYPE.DATE_TO_STRING], }); -console.log(disableDevtool.version); -console.log(disableDevtool.md5('theajack')); \ No newline at end of file +// console.log(disableDevtool.version); +// console.log(disableDevtool.md5('xx')); \ No newline at end of file diff --git a/src/config.js b/src/config.js index eeb0d5b..ed1a789 100644 --- a/src/config.js +++ b/src/config.js @@ -9,11 +9,17 @@ export const config = { disableMenu: true, // 该参数ie下无效,ie 右键菜单会阻塞线程影响debug延迟计算 禁用右键菜单 stopIntervalTime: 5000, // 在移动端时取消监视的等待时长 clearIntervalWhenDevOpenTrigger: false, // 是否在触发之后停止监控 + detectors: 'all', }; +const MultiTypeKeys = ['detectors']; + export function mergeConfig (opts = {}) { for (const k in config) { - if (typeof opts[k] !== 'undefined' && typeof config[k] === typeof opts[k]) { + if ( + typeof opts[k] !== 'undefined' && + (typeof config[k] === typeof opts[k] || MultiTypeKeys.includes(k)) + ) { config[k] = opts[k]; } } diff --git a/src/detector/date-to-string.js b/src/detector/date-to-string.js new file mode 100644 index 0000000..925bb7b --- /dev/null +++ b/src/detector/date-to-string.js @@ -0,0 +1,31 @@ +/* + * @Author: tackchen + * @Date: 2021-11-15 22:26:57 + * @LastEditors: tackchen + * @LastEditTime: 2021-11-15 23:48:53 + * @FilePath: /disable-devtool/src/detector/date-to-string.js + * @Description: Coding something + */ + +import {registInterval} from '../interval'; +import {DETECTOR_TYPE, triggerOnDevOpen} from './detector'; + +export default function detector () { + let count = 0; + const date = new Date(); + date.toString = () => { + count ++; + return ''; + }; + + const checkIsOpen = () => { + count = 0; + console.log(date); + console.clear(); + if (count >= 2) { + triggerOnDevOpen(DETECTOR_TYPE.DATE_TO_STRING); + } + }; + + registInterval(checkIsOpen); +} \ No newline at end of file diff --git a/src/detector/debugger.js b/src/detector/debugger.js new file mode 100644 index 0000000..de15072 --- /dev/null +++ b/src/detector/debugger.js @@ -0,0 +1,21 @@ +/* + * @Author: tackchen + * @Date: 2021-11-15 22:26:57 + * @LastEditors: tackchen + * @LastEditTime: 2021-11-15 23:49:00 + * @FilePath: /disable-devtool/src/detector/debugger.js + * @Description: Coding something + */ + +import {registInterval} from '../interval'; +import {DETECTOR_TYPE, triggerOnDevOpen} from './detector'; + +export default function detector () { + registInterval(() => { + const date = Date.now(); + (() => {debugger;})(); + if (Date.now() - date > 100) { + triggerOnDevOpen(DETECTOR_TYPE.DEBUGGER); + } + }); +} \ No newline at end of file diff --git a/src/detector/detector.js b/src/detector/detector.js index b54467c..e3740fb 100644 --- a/src/detector/detector.js +++ b/src/detector/detector.js @@ -2,25 +2,40 @@ * @Author: theajack * @Date: 2021-07-24 23:16:34 * @LastEditor: theajack - * @LastEditTime: 2021-07-27 23:36:44 + * @LastEditTime: 2021-11-15 23:55:08 * @Description: Coding something */ import {config} from '../config'; -import ToStringDetector from './to-string'; +import RegToStringDetector from './reg-to-string'; import DefineIdDetector from './define-id'; import SizeDetector from './size'; -// import LogTimeDetector from './log-time'; +import DateToStringDetector from './date-to-string'; +import FuncToStringDetector from './func-to-string'; +// import DebuggerDetector from './debugger'; // 会debuger显示devtool +// import LogTimeDetector from './log-time'; // 不准确 容易误伤 import {clearDDInterval, clearDDTimeout} from '../interval'; const detectorList = []; export const DETECTOR_TYPE = { UNKONW: -1, - TO_STRING: 0, + REG_TO_STRING: 0, DEFINE_ID: 1, SIZE: 2, - // LOG_TIME: 3, + DATE_TO_STRING: 3, + FUNC_TO_STRING: 4, + // DEBUGGER: 5, + // LOG_TIME: 6, +}; + +const Detectors = { + [DETECTOR_TYPE.REG_TO_STRING]: RegToStringDetector, + [DETECTOR_TYPE.DEFINE_ID]: DefineIdDetector, + [DETECTOR_TYPE.SIZE]: SizeDetector, + [DETECTOR_TYPE.DATE_TO_STRING]: DateToStringDetector, + [DETECTOR_TYPE.FUNC_TO_STRING]: FuncToStringDetector, + // [DETECTOR_TYPE.DEBUGGER]: DebuggerDetector, }; export function registDetector (detector) { @@ -28,14 +43,20 @@ export function registDetector (detector) { } export function initDetectors () { - ToStringDetector(); - DefineIdDetector(); - SizeDetector(); - // LogTimeDetector(); + const typeArray = config.detectors === 'all' ? + Object.keys(Detectors) : config.detectors; + + typeArray.forEach(type => { + if (Detectors[type]) { + Detectors[type](); + } + }); } export function triggerOnDevOpen (type = DETECTOR_TYPE.UNKONW) { console.warn(`You ar not allow to use DEVTOOL! 【type = ${type}】`); + document.body.innerHTML = `You ar not allow to use DEVTOOL! 【type = ${type}】`; + // alert(`You ar not allow to use DEVTOOL! 【type = ${type}】`); if (config.clearIntervalWhenDevOpenTrigger) { clearDDInterval(); } diff --git a/src/detector/func-to-string.js b/src/detector/func-to-string.js new file mode 100644 index 0000000..06ab483 --- /dev/null +++ b/src/detector/func-to-string.js @@ -0,0 +1,31 @@ +/* + * @Author: tackchen + * @Date: 2021-11-15 22:26:57 + * @LastEditors: tackchen + * @LastEditTime: 2021-11-15 23:49:07 + * @FilePath: /disable-devtool/src/detector/func-to-string.js + * @Description: Coding something + */ + +import {registInterval} from '../interval'; +import {DETECTOR_TYPE, triggerOnDevOpen} from './detector'; + +export default function detector () { + let count = 0; + const func = () => {}; + func.toString = () => { + count ++; + return ''; + }; + + const checkIsOpen = () => { + count = 0; + console.log(func); + console.clear(); + if (count >= 2) { + triggerOnDevOpen(DETECTOR_TYPE.FUNC_TO_STRING); + } + }; + + registInterval(checkIsOpen); +} \ No newline at end of file diff --git a/src/detector/to-string.js b/src/detector/reg-to-string.js similarity index 86% rename from src/detector/to-string.js rename to src/detector/reg-to-string.js index 7a80fff..95c0dc1 100644 --- a/src/detector/to-string.js +++ b/src/detector/reg-to-string.js @@ -2,7 +2,7 @@ * @Author: theajack * @Date: 2021-07-24 23:15:01 * @LastEditor: theajack - * @LastEditTime: 2021-07-25 16:54:13 + * @LastEditTime: 2021-11-15 22:26:29 * @Description: Coding something */ @@ -22,12 +22,12 @@ export default function detector () { if (isQQ) { // ! qq浏览器在控制台没有打开的时候也会触发 打开的时候会连续触发两次 使用这个来判断 const time = new Date().getTime(); if (lastTime && time - lastTime < 100) { - triggerOnDevOpen(DETECTOR_TYPE.TO_STRING); + triggerOnDevOpen(DETECTOR_TYPE.REG_TO_STRING); } else { lastTime = time; } } else if (isFF) { - triggerOnDevOpen(DETECTOR_TYPE.TO_STRING); + triggerOnDevOpen(DETECTOR_TYPE.REG_TO_STRING); } return ''; }; diff --git a/src/detector/size.js b/src/detector/size.js index f6da5c8..b9f232b 100644 --- a/src/detector/size.js +++ b/src/detector/size.js @@ -2,17 +2,16 @@ * @Author: theajack * @Date: 2021-07-24 23:15:54 * @LastEditor: theajack - * @LastEditTime: 2021-07-25 17:12:51 + * @LastEditTime: 2021-11-15 23:44:27 * @Description: Coding something - * @FilePath: \disable-devtool\src\detector\size.js + * @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; + const widthUneven = window.outerWidth - window.innerWidth > 20; + const heightUneven = window.outerHeight - window.innerHeight > 250; // 调大一点防止误伤 if (widthUneven || heightUneven) { triggerOnDevOpen(DETECTOR_TYPE.SIZE); return false; diff --git a/src/index.d.ts b/src/index.d.ts index c022cbb..1fd3a5d 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,5 +1,5 @@ -declare type DETECTOR_TYPE = -1 | 0 | 1 | 2; +declare type DETECTOR_TYPE = -1 | 0 | 1 | 2 | 3 | 4; declare interface optionStatic { md5?: string; // 绕过禁用的md5值,详情见3.2,默认不启用绕过禁用 url?: string; // 关闭页面失败时的跳转页面,默认值为localhost @@ -9,16 +9,20 @@ declare interface optionStatic { disableMenu?: boolean; // 是否禁用右键菜单 默认为true stopIntervalTime?: number; // 在移动端时取消监视的等待时长 clearIntervalWhenDevOpenTrigger?: boolean; // 是否在触发之后停止监控 + detectors: Array; // 启用的监测器 默认为全部 } declare interface DDTStatic { (option?: optionStatic): void; md5(text?: string): string; DETECTOR_TYPE: { UNKONW: -1; - TO_STRING: 0; + REG_TO_STRING: 0; DEFINE_ID: 1; SIZE: 2; - // LOG_TIME: 3; + DATE_TO_STRING: 3; + FUNC_TO_STRING: 4; + // DEBUGGER: 5; + // LOG_TIME: 6; } version: string; } diff --git a/src/interval.js b/src/interval.js index cee5a92..b7442a0 100644 --- a/src/interval.js +++ b/src/interval.js @@ -17,7 +17,7 @@ export function initInterval () { calls.forEach(fn => {fn(time++);}); console.clear(); }, config.interval); - // 两秒之后判断 如果不是pc去掉定时器interval,为了优化移动端的性能 + // stopIntervalTime 之后判断 如果不是pc去掉定时器interval,为了优化移动端的性能 // 如果控制面板被打开了该定时器timer会被清除 timer = setTimeout(() => { if (!isPC()) { diff --git a/src/main.js b/src/main.js index 543706d..6921139 100644 --- a/src/main.js +++ b/src/main.js @@ -13,7 +13,7 @@ export function disableDevtool (opts) { disableKeyAndMenu(); initDetectors(); } - + disableDevtool.md5 = md5; disableDevtool.version = version; disableDevtool.DETECTOR_TYPE = DETECTOR_TYPE; @@ -37,13 +37,17 @@ function checkScriptUse () { return; } const json = {}; - ['md5', 'url', 'tk-name', 'interval', 'disable-menu'].forEach(name => { + ['md5', 'url', 'tk-name', 'interval', 'disable-menu', 'detectors'].forEach(name => { let value = dom.getAttribute(name); if (value !== null) { if (name === 'interval') { value = parseInt(value); } else if (name === 'disable-menu') { value = value === 'false' ? false : true; + } else if (name === 'detector') { + if (value !== 'all') { + value = value.split(' '); + } } json[formatName(name)] = value; } diff --git a/src/version.js b/src/version.js index 4339244..2e1c624 100644 --- a/src/version.js +++ b/src/version.js @@ -1 +1 @@ -export default '0.1.5'; \ No newline at end of file +export default '0.1.7'; \ No newline at end of file