Skip to content

Commit 6838d55

Browse files
committed
feat: 0.3.5
1 parent 7479601 commit 6838d55

File tree

11 files changed

+96
-24
lines changed

11 files changed

+96
-24
lines changed

README.cn.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@
2525
</p>
2626
<p align="center">
2727
<a href="https://github.com/theajack" target="_black">
28-
<img src="https://img.shields.io/badge/Author-%20theajack%20-7289da.svg?&logo=github" alt="author" />
28+
<img src="https://img.shields.io/badge/Author-%20theajack%20-7289da.svg?logo=github" alt="author" />
2929
</a>
3030
<a href="https://www.github.com/theajack/disable-devtool/blob/master/LICENSE" target="_black">
31-
<img src="https://img.shields.io/github/license/theajack/disable-devtool?color=%232DCE89&logo=github" alt="license" />
31+
<img src="https://img.shields.io/github/license/theajack/disable-devtool?color=%232DCE89" alt="license" />
3232
</a>
3333
<a href="https://cdn.jsdelivr.net/npm/disable-devtool"><img src="https://img.shields.io/bundlephobia/minzip/disable-devtool.svg" alt="Size"></a>
3434
<a href="https://github.com/theajack/disable-devtool/search?l=javascript"><img src="https://img.shields.io/github/languages/top/theajack/disable-devtool.svg" alt="TopLang"></a>
35-
<a href="https://www.github.com/theajack/disable-devtool"><img src="https://img.shields.io/librariesio/dependent-repos/npm/disable-devtool.svg" alt="Dependent"></a>
36-
<a href="https://github.com/theajack/disable-devtool/blob/master/test/test-report.txt"><img src="https://img.shields.io/badge/test-passed-44BB44" alt="test"></a>
35+
<!-- <a href="https://www.github.com/theajack/disable-devtool"><img src="https://img.shields.io/librariesio/dependent-repos/npm/disable-devtool.svg" alt="Dependent"></a> -->
36+
<img src="https://img.shields.io/badge/test-passed-44BB44" alt="test">
37+
<img src="https://shiyix.cn/api2/util/badge/stat?c=Visitors-disabledevtool" alt="visitors">
38+
3739
</p>
3840

3941
<h2>🚀 一行代码搞定禁用web开发者工具 </h2>
@@ -179,10 +181,23 @@ import DisableDevtool from 'disable-devtool';
179181
DisableDevtool(options);
180182
```
181183

184+
#### 3.1.1 返回值
185+
186+
返回值 DisableDevtool 的返回值为如下类型
187+
188+
```ts
189+
interface IDDResult {
190+
success: boolean; // 表示是否正常启用
191+
reason: string; // 未正常启用的原因
192+
}
193+
```
194+
195+
#### 3.1.2 参数
196+
182197
options中的参数与说明如下:
183198

184199
```ts
185-
declare interface IConfig {
200+
interface IConfig {
186201
md5?: string; // 绕过禁用的md5值,详情见3.2,默认不启用绕过禁用
187202
url?: string; // 关闭页面失败时的跳转页面,默认值为localhost
188203
tkName?: string; // 绕过禁用时的url参数名称,默认为 ddtk
@@ -192,14 +207,15 @@ declare interface IConfig {
192207
disableMenu?: boolean; // 是否禁用右键菜单 默认为true
193208
stopIntervalTime?: number; // 在移动端时取消监视的等待时长
194209
clearIntervalWhenDevOpenTrigger?: boolean; // 是否在触发之后停止监控 默认为false, 在使用ondevtoolclose时该参数无效
195-
detactors?: Array<DetectorType>; // 启用的检测器 检测器详情见 3.5 默认为全部,建议使用全部
210+
detectors?: Array<DetectorType>; // 启用的检测器 检测器详情见 3.5 默认为全部,建议使用全部
196211
clearLog?: boolean; // 是否每次都清除log
197212
disableSelect?: boolean; // 是否禁用选择文本 默认为false
198213
disableCopy?: boolean; // 是否禁用复制 默认为false
199214
disableCut?: boolean; // 是否禁用剪切 默认为false
200215
disablePaste: boolean; // 是否禁用粘贴 默认为false
201216
ignore?: (string|RegExp)[] | null | (()=>boolean); // 某些情况忽略禁用
202217
disableIframeParents?: boolean; // iframe中是否禁用所有父窗口
218+
timeOutUrl?: // 关闭页面超时跳转的url;
203219
}
204220

205221
enum DetectorType {
@@ -276,7 +292,7 @@ enum DetectorType {
276292
Unknown = -1,
277293
RegToString = 0, // 根据正则检测
278294
DefineId, // 根据dom id检测
279-
Size, // 根据窗口尺寸检测
295+
Size, // 根据窗口尺寸检测 // 0.3.5版本后该探测器默认不启用
280296
DateToString, // 根据Date.toString 检测
281297
FuncToString, // 根据Function.toString 检测
282298
Debugger, // 根据断点检测,仅在ios chrome 真机情况下有效

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@
2525
</p>
2626
<p align="center">
2727
<a href="https://github.com/theajack" target="_black">
28-
<img src="https://img.shields.io/badge/Author-%20theajack%20-7289da.svg?&logo=github" alt="author" />
28+
<img src="https://img.shields.io/badge/Author-%20theajack%20-7289da.svg?logo=github" alt="author" />
2929
</a>
3030
<a href="https://www.github.com/theajack/disable-devtool/blob/master/LICENSE" target="_black">
31-
<img src="https://img.shields.io/github/license/theajack/disable-devtool?color=%232DCE89&logo=github" alt="license" />
31+
<img src="https://img.shields.io/github/license/theajack/disable-devtool?color=%232DCE89" alt="license" />
3232
</a>
3333
<a href="https://cdn.jsdelivr.net/npm/disable-devtool"><img src="https://img.shields.io/bundlephobia/minzip/disable-devtool.svg" alt="Size"></a>
3434
<a href="https://github.com/theajack/disable-devtool/search?l=javascript"><img src="https://img.shields.io/github/languages/top/theajack/disable-devtool.svg" alt="TopLang"></a>
35-
<a href="https://www.github.com/theajack/disable-devtool"><img src="https://img.shields.io/librariesio/dependent-repos/npm/disable-devtool.svg" alt="Dependent"></a>
36-
<a href="https://github.com/theajack/disable-devtool/blob/master/test/test-report.txt"><img src="https://img.shields.io/badge/test-passed-44BB44" alt="test"></a>
35+
<!-- <a href="https://www.github.com/theajack/disable-devtool"><img src="https://img.shields.io/librariesio/dependent-repos/npm/disable-devtool.svg" alt="Dependent"></a> -->
36+
<img src="https://img.shields.io/badge/test-passed-44BB44" alt="test">
37+
<img src="https://shiyix.cn/api2/util/badge/stat?c=Visitors-disabledevtool" alt="visitors">
3738
</p>
3839

3940
<h2>🚀 One line of code to disable web developer tools </h2>
@@ -179,6 +180,19 @@ import DisableDevtool from 'disable-devtool';
179180
DisableDevtool(options);
180181
```
181182

183+
#### 3.1.1 Return value
184+
185+
Return value DisableDevtool The return value is of the following type
186+
187+
```ts
188+
interface IDDResult {
189+
success: boolean; Indicates whether it is enabled normally
190+
reason: string; The reason why it was not properly enabled
191+
}
192+
```
193+
194+
#### 3.1.2 parameters
195+
182196
The parameters and descriptions in options are as follows:
183197

184198
```ts
@@ -192,21 +206,22 @@ declare interface IConfig {
192206
disableMenu?: boolean; // Whether to disable the right-click menu Default is true
193207
stopIntervalTime?: number; // Waiting time to cancel monitoring on mobile
194208
clearIntervalWhenDevOpenTrigger?: boolean; // Whether to stop monitoring after triggering the default is false, this parameter is invalid when using ondevtoolclose
195-
detactors?: Array<DetectorType>; // Enabled detectors See 3.5 for details of detectors. The default is all, it is recommended to use all
209+
detectors?: Array<DetectorType>; // Enabled detectors See 3.5 for details of detectors. The default is all, it is recommended to use all
196210
clearLog?: boolean; // Whether to clear the log every time
197211
disableSelect?: boolean; // Whether to disable selection text Default is false
198212
disableCopy?: boolean; // Whether to disable copying, default is false
199213
disableCut?: boolean; // Whether to disable cutting, default is false
200214
disablePaste: boolean; // Whether to disable paste, default is false
201215
ignore?: (string| RegExp)[] | null | (()=>boolean); // Some cases ignore the disablement
202216
disableIframeParents?: boolean; // Whether all parent windows are disabled in the iframe
217+
timeOutUrl?: // Turn off URLs that page timeouts forward towards
203218
}
204219

205220
enum DetectorType {
206221
Unknown = -1,
207222
RegToString = 0, // Check according to regular
208223
DefineId, // detect based on dom id
209-
Size, // Detect based on window size
224+
Size, // Detect based on window size // After version 0.3.5, this probe is not enabled by default
210225
DateToString, // check against Date.toString
211226
FuncToString, // check according to Function.toString
212227
Debugger, // According to breakpoint detection, it is only valid in the case of ios chrome real machine

scripts/version.en.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
-->
66
# Version Log:
77

8+
## 0.3.5
9+
10+
1. Fix the problem that the debugging mode in the PC iOS mobile terminal does not work
11+
2. Remove the default enablement of sizeDetector
12+
3. Add timeOutUrl to handle the jump that closes the page timeout
13+
4. Add disableDevtool to repeatedly enable judgment and increase the return value
14+
5. Optimize the judgment of seobot
15+
816
## 0.3.4
917

1018
Fix false detection issue in iOS Edge browser

scripts/version.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
-->
66
# Version Log:
77

8+
## 0.3.5
9+
10+
1. 修复pc端ios移动端中调试模式不起作用的问题
11+
2. 去除sizeDetector的默认启用
12+
3. 增加timeOutUrl,用来处理关闭页面超时的跳转
13+
4. 增加disableDevtool重复启用判断,增加返回值
14+
5. 优化seobot的判断
15+
816
## 0.3.4
917

1018
1. 修复ios edge浏览器中的误检测问题

src/detector/sub-detector/performance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class extends Detector {
1616
constructor () {
1717
super({
1818
type: DetectorType.Performance,
19-
enabled: IS.chrome
19+
enabled: IS.chrome || !IS.mobile
2020
});
2121
}
2222

src/main.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@ import {initLogs} from './utils/log';
1818
import {checkScriptUse} from './plugins/script-use';
1919

2020
export const disableDevtool: IDisableDevtool = Object.assign(((opts?: Partial<IConfig>) => {
21+
const r = (reason = '') => ({success: !reason, reason});
22+
if (disableDevtool.isRunning) return r('already running');
2123
initIS(); // ! 首先初始化env
2224
initLogs(); // 然后初始化log
2325
mergeConfig(opts);
2426
// 被 token 绕过 或者
27+
if (checkTk()) return r('token passed');
2528
// 开启了保护seo 并且 是seobot
26-
if (checkTk() || (config.seo && IS.seoBot)) {return;}
29+
if ((config.seo && IS.seoBot)) return r('seobot');
2730
disableDevtool.isRunning = true;
2831
initInterval(disableDevtool);
2932
disableKeyAndMenu(disableDevtool);
3033
initDetectors();
34+
return r();
3135
}), {
3236
isRunning: false,
3337
isSuspend: false,

src/plugins/script-use.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
export function checkScriptUse () {
8-
if (!window || !window.document) return null;
8+
if ('undefined' === typeof window || !window.document) return null;
99
const dom = document.querySelector('[disable-devtool-auto]');
1010
if (!dom) {
1111
return null;

src/type.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {DetectorType} from './utils/enum';
99
export interface IConfig {
1010
md5: string; // 绕过禁用的md5值,详情见3.2,默认不启用绕过禁用
1111
url: string; // 关闭页面失败时的跳转页面,默认值为localhost
12+
timeOutUrl: string; // 关闭页面超时跳转的url
1213
tkName: string; // 绕过禁用时的url参数名称,默认为 ddtk
1314
ondevtoolopen(type: DetectorType, next: Function): void; // 开发者面板打开的回调,启用时url参数无效
1415
ondevtoolclose: Function | null;
@@ -28,7 +29,7 @@ export interface IConfig {
2829
}
2930

3031
export interface IDisableDevtool {
31-
(opts?: Partial<IConfig>): void;
32+
(opts?: Partial<IConfig>): {success:boolean, reason:string};
3233
isRunning: boolean;
3334
isSuspend: boolean;
3435
md5: (v: string) => string;

src/utils/close-window.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: tackchen
33
* @Date: 2021-12-24 15:14:06
44
* @LastEditors: Please set LastEditors
5-
* @LastEditTime: 2023-02-16 23:27:03
5+
* @LastEditTime: 2023-06-21 08:00:32
66
* @FilePath: /disable-devtool/src/close-window.js
77
* @Description: Coding something
88
*/
@@ -25,7 +25,7 @@ export function closeWindow () {
2525
}
2626
setTimeout(() => {
2727
// 否则执行跳转到 url
28-
window.location.href = `https://theajack.github.io/disable-devtool/404.html?h=${encodeURIComponent(location.host)}`;
28+
window.location.href = config.timeOutUrl || `https://theajack.github.io/disable-devtool/404.html?h=${encodeURIComponent(location.host)}`;
2929
}, 500);
3030
}
3131
}

src/utils/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ export const config: IConfig = {
1111
ondevtoolopen: closeWindow, // ondevtoolopen 优先级高于 url
1212
ondevtoolclose: null, // ondevtoolclose 监听
1313
url: '',
14+
timeOutUrl: '',
1415
tkName: 'ddtk',
1516
interval: 200,
1617
disableMenu: true, // 是否禁用右键菜单
1718
stopIntervalTime: 5000, // 在移动端时取消监视的等待时长
1819
clearIntervalWhenDevOpenTrigger: false, // 是否在触发之后停止监控
19-
detectors: 'all',
20+
detectors: [0, 1, 3, 4, 5, 6, 7], // 'all', ! 默认去掉sizeDetector 因为会误伤
2021
clearLog: true,
2122
disableSelect: false,
2223
disableCopy: false,

0 commit comments

Comments
 (0)