Giter VIP home page Giter VIP logo

console-ban's Introduction

console-ban

禁止F12 / 审查开启控制台,保护站点资源、减少爬虫和攻击的轻量方案,支持重定向、重写、自定义多种策略。

version: 2.2

Usage

直接引入:

<head>
  <!-- ... -->
  <script src="https://cdn.jsdelivr.net/gh/fz6m/[email protected]/dist/console-ban.min.js"></script>
  <script>
    // default options
    ConsoleBan.init()
    // custom options
    ConsoleBan.init({
      redirect: '/404'
    })
  </script>
</head>

在项目中使用:

  yarn add console-ban
  import { init as ConsoleBan } from 'console-ban'

  ConsoleBan()

Strategy

重定向

  ConsoleBan.init({
    // 重定向至 /404 相对地址
    redirect: '/404',
    // 重定向至绝对地址
    redirect: 'http://domain.com/path'
  })

使用重定向策略可以将用户指引到友好的相关信息地址(如网站介绍),亦或是纯静态 404 页面,高防的边缘计算或验证码等页面。

注:若重定向后的地址可以通过 SPA 路由切换或 pjax 局部加载技术等进行非真正意义上的页面切换,则切换后的控制台监测将不会再次生效,对于 SPA 你可以在路由卫士处重新注册本实例,其他情况请引导至真正的其他页面。

重写

  var div = document.createElement('div')
  div.innerHTML = '不要偷看啦~'

  ConsoleBan.init({
    // 重写 body 为字符串
    write: '<h1> 不要偷看啦~ </h1>',
    // 可传入节点对象
    write: div
  })

重写策略可以完全阻断对网站内容的审查,但较不友好,不推荐使用。

回调函数

  ConsoleBan.init({
    callback: () => {
      // ...
    }
  })

回调函数支持自定义打开控制台后的策略。

Options

name required type default description
clear no boolean true 禁用 console.clear 函数,防止脚本清屏阻断监测
debug no boolean true 是否开启定时 debugger 反爬虫审查
debugTime no number 3000 定时 debugger 时间间隔(毫秒)
redirect no string - 开启控制台后重定向地址
write no string | Element - 开启控制台后重写 document.body 内容,支持传入节点或字符串
callback no Function - 开启控制台后的回调函数

注:redirectwritecallback 三种策略只能取其一,优先使用回调函数。

Support

browser core support
chrome
firefox
safari

How

Find out whether Chrome console is open

console-ban's People

Contributors

fz6m avatar lionad-morotar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.