Skip to content

Commit

Permalink
feat: 0.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
theajack committed Jun 21, 2023
1 parent 7479601 commit 6838d55
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 24 deletions.
30 changes: 23 additions & 7 deletions README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@
</p>
<p align="center">
<a href="https://github.com/theajack" target="_black">
<img src="https://img.shields.io/badge/Author-%20theajack%20-7289da.svg?&logo=github" alt="author" />
<img src="https://img.shields.io/badge/Author-%20theajack%20-7289da.svg?logo=github" alt="author" />
</a>
<a href="https://www.github.com/theajack/disable-devtool/blob/master/LICENSE" target="_black">
<img src="https://img.shields.io/github/license/theajack/disable-devtool?color=%232DCE89&logo=github" alt="license" />
<img src="https://img.shields.io/github/license/theajack/disable-devtool?color=%232DCE89" alt="license" />
</a>
<a href="https://cdn.jsdelivr.net/npm/disable-devtool"><img src="https://img.shields.io/bundlephobia/minzip/disable-devtool.svg" alt="Size"></a>
<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>
<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>
<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>
<!-- <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> -->
<img src="https://img.shields.io/badge/test-passed-44BB44" alt="test">
<img src="https://shiyix.cn/api2/util/badge/stat?c=Visitors-disabledevtool" alt="visitors">

</p>

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

#### 3.1.1 返回值

返回值 DisableDevtool 的返回值为如下类型

```ts
interface IDDResult {
success: boolean; // 表示是否正常启用
reason: string; // 未正常启用的原因
}
```

#### 3.1.2 参数

options中的参数与说明如下:

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

enum DetectorType {
Expand Down Expand Up @@ -276,7 +292,7 @@ enum DetectorType {
Unknown = -1,
RegToString = 0, // 根据正则检测
DefineId, // 根据dom id检测
Size, // 根据窗口尺寸检测
Size, // 根据窗口尺寸检测 // 0.3.5版本后该探测器默认不启用
DateToString, // 根据Date.toString 检测
FuncToString, // 根据Function.toString 检测
Debugger, // 根据断点检测,仅在ios chrome 真机情况下有效
Expand Down
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
</p>
<p align="center">
<a href="https://github.com/theajack" target="_black">
<img src="https://img.shields.io/badge/Author-%20theajack%20-7289da.svg?&logo=github" alt="author" />
<img src="https://img.shields.io/badge/Author-%20theajack%20-7289da.svg?logo=github" alt="author" />
</a>
<a href="https://www.github.com/theajack/disable-devtool/blob/master/LICENSE" target="_black">
<img src="https://img.shields.io/github/license/theajack/disable-devtool?color=%232DCE89&logo=github" alt="license" />
<img src="https://img.shields.io/github/license/theajack/disable-devtool?color=%232DCE89" alt="license" />
</a>
<a href="https://cdn.jsdelivr.net/npm/disable-devtool"><img src="https://img.shields.io/bundlephobia/minzip/disable-devtool.svg" alt="Size"></a>
<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>
<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>
<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>
<!-- <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> -->
<img src="https://img.shields.io/badge/test-passed-44BB44" alt="test">
<img src="https://shiyix.cn/api2/util/badge/stat?c=Visitors-disabledevtool" alt="visitors">
</p>

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

#### 3.1.1 Return value

Return value DisableDevtool The return value is of the following type

```ts
interface IDDResult {
success: boolean; Indicates whether it is enabled normally
reason: string; The reason why it was not properly enabled
}
```

#### 3.1.2 parameters

The parameters and descriptions in options are as follows:

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

enum DetectorType {
Unknown = -1,
RegToString = 0, // Check according to regular
DefineId, // detect based on dom id
Size, // Detect based on window size
Size, // Detect based on window size // After version 0.3.5, this probe is not enabled by default
DateToString, // check against Date.toString
FuncToString, // check according to Function.toString
Debugger, // According to breakpoint detection, it is only valid in the case of ios chrome real machine
Expand Down
8 changes: 8 additions & 0 deletions scripts/version.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
-->
# Version Log:

## 0.3.5

1. Fix the problem that the debugging mode in the PC iOS mobile terminal does not work
2. Remove the default enablement of sizeDetector
3. Add timeOutUrl to handle the jump that closes the page timeout
4. Add disableDevtool to repeatedly enable judgment and increase the return value
5. Optimize the judgment of seobot

## 0.3.4

Fix false detection issue in iOS Edge browser
Expand Down
8 changes: 8 additions & 0 deletions scripts/version.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
-->
# Version Log:

## 0.3.5

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

## 0.3.4

1. 修复ios edge浏览器中的误检测问题
Expand Down
2 changes: 1 addition & 1 deletion src/detector/sub-detector/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class extends Detector {
constructor () {
super({
type: DetectorType.Performance,
enabled: IS.chrome
enabled: IS.chrome || !IS.mobile
});
}

Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ import {initLogs} from './utils/log';
import {checkScriptUse} from './plugins/script-use';

export const disableDevtool: IDisableDevtool = Object.assign(((opts?: Partial<IConfig>) => {
const r = (reason = '') => ({success: !reason, reason});
if (disableDevtool.isRunning) return r('already running');
initIS(); // ! 首先初始化env
initLogs(); // 然后初始化log
mergeConfig(opts);
// 被 token 绕过 或者
if (checkTk()) return r('token passed');
// 开启了保护seo 并且 是seobot
if (checkTk() || (config.seo && IS.seoBot)) {return;}
if ((config.seo && IS.seoBot)) return r('seobot');
disableDevtool.isRunning = true;
initInterval(disableDevtool);
disableKeyAndMenu(disableDevtool);
initDetectors();
return r();
}), {
isRunning: false,
isSuspend: false,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/script-use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

export function checkScriptUse () {
if (!window || !window.document) return null;
if ('undefined' === typeof window || !window.document) return null;
const dom = document.querySelector('[disable-devtool-auto]');
if (!dom) {
return null;
Expand Down
3 changes: 2 additions & 1 deletion src/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {DetectorType} from './utils/enum';
export interface IConfig {
md5: string; // 绕过禁用的md5值,详情见3.2,默认不启用绕过禁用
url: string; // 关闭页面失败时的跳转页面,默认值为localhost
timeOutUrl: string; // 关闭页面超时跳转的url
tkName: string; // 绕过禁用时的url参数名称,默认为 ddtk
ondevtoolopen(type: DetectorType, next: Function): void; // 开发者面板打开的回调,启用时url参数无效
ondevtoolclose: Function | null;
Expand All @@ -28,7 +29,7 @@ export interface IConfig {
}

export interface IDisableDevtool {
(opts?: Partial<IConfig>): void;
(opts?: Partial<IConfig>): {success:boolean, reason:string};
isRunning: boolean;
isSuspend: boolean;
md5: (v: string) => string;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/close-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: tackchen
* @Date: 2021-12-24 15:14:06
* @LastEditors: Please set LastEditors
* @LastEditTime: 2023-02-16 23:27:03
* @LastEditTime: 2023-06-21 08:00:32
* @FilePath: /disable-devtool/src/close-window.js
* @Description: Coding something
*/
Expand All @@ -25,7 +25,7 @@ export function closeWindow () {
}
setTimeout(() => {
// 否则执行跳转到 url
window.location.href = `https://theajack.github.io/disable-devtool/404.html?h=${encodeURIComponent(location.host)}`;
window.location.href = config.timeOutUrl || `https://theajack.github.io/disable-devtool/404.html?h=${encodeURIComponent(location.host)}`;
}, 500);
}
}
3 changes: 2 additions & 1 deletion src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ export const config: IConfig = {
ondevtoolopen: closeWindow, // ondevtoolopen 优先级高于 url
ondevtoolclose: null, // ondevtoolclose 监听
url: '',
timeOutUrl: '',
tkName: 'ddtk',
interval: 200,
disableMenu: true, // 是否禁用右键菜单
stopIntervalTime: 5000, // 在移动端时取消监视的等待时长
clearIntervalWhenDevOpenTrigger: false, // 是否在触发之后停止监控
detectors: 'all',
detectors: [0, 1, 3, 4, 5, 6, 7], // 'all', ! 默认去掉sizeDetector 因为会误伤
clearLog: true,
disableSelect: false,
disableCopy: false,
Expand Down
27 changes: 23 additions & 4 deletions src/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,17 @@ export const IS = {
iosEdge: false,
chrome: false,
seoBot: false,
mobile: false,
};

export function initIS () {
const ua = navigator.userAgent.toLowerCase();

const has = (name: string) => ua.indexOf(name) !== -1;

const mobile = isMobile();
const iframe = !!window.top && window !== window.top;
const pc = !/(iphone|ipad|ipod|ios|android)/i.test(ua);
const pc = !mobile;
const qqBrowser = has('qqbrowser');
const firefox = has('firefox');
const macos = has('macintosh');
Expand All @@ -114,14 +116,31 @@ export function initIS () {
const iosChrome = has('crios');
const iosEdge = has('edgios');
const chrome = has('chrome') || iosChrome;
const seoBot = /(googlebot|baiduspider|bingbot|applebot|petalbot|yandexbot|bytespider|chrome\-lighthouse)/i.test(ua);
const seoBot = !mobile && /(googlebot|baiduspider|bingbot|applebot|petalbot|yandexbot|bytespider|chrome\-lighthouse)/i.test(ua);

Object.assign(IS, {
iframe, pc, qqBrowser, firefox, macos, edge, oldEdge,
ie, iosChrome, iosEdge, chrome, seoBot,
ie, iosChrome, iosEdge, chrome, seoBot, mobile,
});
}

function isMobileByUa () {
return /(iphone|ipad|ipod|ios|android)/i.test(navigator.userAgent.toLowerCase());
}

function isMobile () {
const {platform, maxTouchPoints} = navigator;
if (typeof maxTouchPoints === 'number') {
return maxTouchPoints > 1;
}
if (typeof platform === 'string') {
const v = platform.toLowerCase();
if (/(mac|win)/.test(v)) return false;
else if (/(android|iphone|ipad|ipod|arch)/.test(v)) return true;
}
return isMobileByUa();
}

function createLargeObject () {
const largeObject: Record<string, string> = {};
for (let i = 0; i < 500; i++) {
Expand All @@ -139,4 +158,4 @@ export function createLargeObjectArray () {
}

return largeObjectArray;
}
}

0 comments on commit 6838d55

Please sign in to comment.