Skip to content

Commit

Permalink
feat: 0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
theajack committed Jan 5, 2022
1 parent d85fc71 commit 21d17b2
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 59 deletions.
3 changes: 3 additions & 0 deletions helper/debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
// next();
// console.log(next);
},
ondevtoolclose: function(){
text.innerHTML = 'devtool closed!'
},
clearIntervalWhenDevOpenTrigger: false,
interval: 1000,
// tkName: 'ddtk',
Expand Down
9 changes: 9 additions & 0 deletions helper/todo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--
* @Author: tackchen
* @Date: 2022-01-06 00:09:44
* @LastEditors: tackchen
* @LastEditTime: 2022-01-06 00:11:25
* @FilePath: /disable-devtool/helper/todo.md
* @Description: Coding something
-->
1. 问题:ios真机chrome 浏览器 data-to-string 和 func-to-string两个detector与开发者工具表现一致
2 changes: 1 addition & 1 deletion helper/version.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
3. Refactor the code
4. Fix the problem caused by the method on the console cannot be cached by ie

## 0.2.1
## 0.2.1 - 0.2.2
1. Add ondevtoolclose configuration
2. Add isDevToolOpened api
3. Fix the accidental injury problem of ios mobile chrome
Expand Down
2 changes: 1 addition & 1 deletion helper/version.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
3. 重构代码
4. 修复ie不能缓存console上的方法导致的问题

## 0.2.1
## 0.2.1 - 0.2.2
1. 增加 ondevtoolclose 配置
2. 增加 isDevToolOpened api
3. 修复 ios mobile chrome 的误伤问题
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ <h3>3.3 script does not use attribute configuration</h3>
<script
disable-devtool-auto
md5='1aabac6d068eef6a7bad3fdf50a05cc8'
src='https://cdn.jsdelivr.net/npm/disable-devtool@0.2.1/disable-devtool.min.js#use'
src='https://cdn.jsdelivr.net/npm/disable-devtool@0.2.2/disable-devtool.min.js#use'
></script>
<!-- <script disable-devtool-auto md5='1aabac6d068eef6a7bad3fdf50a05cc8' src='./npm/disable-devtool.min.js'></script> -->
<script>
Expand Down
2 changes: 1 addition & 1 deletion npm/disable-devtool.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "disable-devtool",
"version": "0.2.1",
"version": "0.2.2",
"description": "Disable web developer tools from the f12 button, right-click and browser ",
"main": "disable-devtool.min.js",
"unpkg": "disable-devtool.min.js",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "disable-devtool",
"version": "0.2.1",
"version": "0.2.2",
"description": "Disable web developer tools from the f12 button, right-click and browser ",
"main": "disable-devtool.min.js",
"unpkg": "disable-devtool.min.js",
Expand Down
6 changes: 3 additions & 3 deletions src/detector/date-to-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: tackchen
* @Date: 2021-11-15 22:26:57
* @LastEditors: tackchen
* @LastEditTime: 2022-01-05 22:40:41
* @LastEditTime: 2022-01-06 00:08:02
* @FilePath: /disable-devtool/src/detector/date-to-string.js
* @Description: Coding something
*/
Expand All @@ -11,8 +11,8 @@ import {registInterval} from '../utils/interval';
import {DETECTOR_TYPE, triggerOnDevOpen} from './detector';
import {clearLog, log} from '../utils/log';

export default function detector (isTrueIOSChrome) {
if (isTrueIOSChrome) return;
export default function detector (isIOSChrome) {
if (isIOSChrome) return;
const type = DETECTOR_TYPE.DATE_TO_STRING;
let count = 0;
const date = new Date();
Expand Down
6 changes: 3 additions & 3 deletions src/detector/debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
* @Author: tackchen
* @Date: 2021-11-15 22:26:57
* @LastEditors: tackchen
* @LastEditTime: 2022-01-05 22:38:55
* @LastEditTime: 2022-01-06 00:08:11
* @FilePath: /disable-devtool/src/detector/debugger.js
* @Description: Coding something
*/

import {registInterval} from '../utils/interval';
import {DETECTOR_TYPE, triggerOnDevOpen} from './detector';

export default function detector (isTrueIOSChrome) {
if (isTrueIOSChrome) {
export default function detector (isIOSChrome) {
if (isIOSChrome) {
const type = DETECTOR_TYPE.DEBUGGER;
// 仅在 ios chrome 下生效
registInterval(type, () => {
Expand Down
38 changes: 13 additions & 25 deletions src/detector/detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: theajack
* @Date: 2021-07-24 23:16:34
* @LastEditor: theajack
* @LastEditTime: 2022-01-05 23:39:06
* @LastEditTime: 2022-01-06 00:09:02
* @Description: Coding something
*/

Expand All @@ -16,7 +16,7 @@ import DebuggerDetector from './debugger';
// import LogTimeDetector from './log-time'; // 不准确 容易误伤 故弃用
import {clearDDInterval, clearDDTimeout} from '../utils/interval';
import {closeWindow} from '../utils/close-window';
import {isIOSChrome, isLogRegExpCount3} from '../utils/util';
import {isIOSChrome} from '../utils/util';
import {isDevToolOpened, isLastStateOpened, markDevToolOpenState} from '../utils/open-state';

export const DETECTOR_TYPE = {
Expand All @@ -41,31 +41,19 @@ const Detectors = {
};

export function initDetectors () {
// ! 判断是否是 ios chrome 真机, true时 禁用 date 和 func detector,因为会误伤。启用debugger detector兜底
// 不使用 async/await 是为了减少打包体积

const initFunc = (isTrueIOSChrome) => {
const typeArray = config.detectors === 'all' ?
Object.keys(Detectors) : config.detectors;

if (isTrueIOSChrome) {
typeArray.push(DETECTOR_TYPE.DEBUGGER); // 会debuger显示devtool, 仅在ios chrome 真机生效
}
// ! 判断是否是 ios chrome true时 禁用 date 和 func detector,因为会误伤。启用debugger detector兜底
const typeArray = config.detectors === 'all' ?
Object.keys(Detectors) : config.detectors;

typeArray.forEach(type => {
if (Detectors[type]) {
Detectors[type](isTrueIOSChrome);
}
});
};

if (!isIOSChrome) {
initFunc(false);
} else {
isLogRegExpCount3().then(bool => {
initFunc(bool);
});
if (isIOSChrome) {
typeArray.push(DETECTOR_TYPE.DEBUGGER); // 会debuger显示devtool, 仅在ios chrome 真机生效
}

typeArray.forEach(type => {
if (Detectors[type]) {
Detectors[type](isIOSChrome);
}
});
}

export function triggerOnDevOpen (type = DETECTOR_TYPE.UNKONW) {
Expand Down
6 changes: 3 additions & 3 deletions src/detector/func-to-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: tackchen
* @Date: 2021-11-15 22:26:57
* @LastEditors: tackchen
* @LastEditTime: 2022-01-05 22:39:48
* @LastEditTime: 2022-01-06 00:07:54
* @FilePath: /disable-devtool/src/detector/func-to-string.js
* @Description: Coding something
*/
Expand All @@ -13,8 +13,8 @@ import {registInterval} from '../utils/interval';
import {DETECTOR_TYPE, triggerOnDevOpen} from './detector';
import {log, clearLog} from '../utils/log';

export default function detector (isTrueIOSChrome) {
if (isTrueIOSChrome) return;
export default function detector (isIOSChrome) {
if (isIOSChrome) return;
const type = DETECTOR_TYPE.FUNC_TO_STRING;
let count = 0;
const func = () => {};
Expand Down
18 changes: 0 additions & 18 deletions src/utils/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {log} from './log';

export function isPC () {
return !/(iphone|ipad|ipod|ios|android)/i.test(navigator.userAgent.toLowerCase());
}
Expand Down Expand Up @@ -114,19 +112,3 @@ export const isOldEdge = hasUaName('edge') && !hasUaName('chrome');
export const isIE = isOldEdge || hasUaName('trident') || hasUaName('msie');

export const isIOSChrome = hasUaName('crios');

// ios chrome log regExp count=3 , 以此区别真机和开发者工具模拟的
export function isLogRegExpCount3 () {
return new Promise((resolve) => {
let count = 0;
const target = new RegExp();
target.toString = () => {
count ++;
return '';
};
log(target);
setTimeout(() => {
resolve(count === 3);
}, 100);
});
}
2 changes: 1 addition & 1 deletion src/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '0.2.1';
export default '0.2.2';

0 comments on commit 21d17b2

Please sign in to comment.