Giter Site home page Giter Site logo

amandakelake / chrome-extension-react-antd-template Goto Github PK

View Code? Open in Web Editor NEW

This project forked from raojinlin/chrome-extension-react-antd-template

0.0 1.0 0.0 553 KB

🚀 这是一个Chrome插件的React和Antd模板,封装了常用的基础库,如消息通信和日志采集。支持环境配置,并使用Promise发送和等待消息响应。可以快速构建React的Chrome插件,同时提供了一些通用的React组件和浏览器接口相关的函数。

JavaScript 96.71% CSS 0.49% HTML 2.80%

chrome-extension-react-antd-template's Introduction

Chrome Extension React Antd Template

这是一个基于React和Ant Desigin UI库的Chrome插件模板项目。该模板封装了一些常见的基础库,如日志和消息通信,可用于快速构建React插件。

版本信息:

  1. Ant design: 5.8.2
  2. React: 18.2.0

特性

  • 代码实时构建
  • 支持react
  • 支持less
  • 支持ts
  • 封装了通用的消息通信
  • 支持日志采集
  • 快速搭建项目
  • 支持环境配置(development/production)
  • 使用promise发送/等待消息响应

使用

node版本在10以上。

  1. 克隆本项目
git clone https://github.com/raojinlin/chrome-extension-react-antd-template.git
cd chrome-extension-react-antd-template
  1. 构建插件
npm install
npm run build
  1. 构建后会在extension生成相应的文件。在浏览器加载插件就可以运行了。

截图

Popup

./screenshot/popup.png

配置页

内容脚本注入

项目布局

/src/backgorund.js

后台脚本入口

/src/content-scripts.js

内容脚本入口

/src/content-options.js

插件配置入口

/src/components/

一些通用的react组件

/src/lib

一些通用的库,如日志、消息通信、浏览器接口相关的函数

/src/lib/message.js

消息类

监听消息:

const message = new Message();

message.addListener('ping', function (request, sender, sendResponse) {
  sendResponse('pong');
});

import { dispatchMessage } from "./brower";


// 分发消息
dispatchMessage(message);

发送消息:

const message = new Message();
message.sendMessage('ping').then(response => {
    console.log('pong');
});

/src/lib/logger.js

日志类,支持console和http方式记录日志。

import { Logger, HttpHandler, ConsoleHandler } from "./lib/logger";

// 使用HTTP记录日志到服务器
const logger = new Logger('HTTP', new HttpHandler('https://log.youdomain.com/collect/'));
logger.info('some message from client');

// 记录日志到控制台
const consoleLogger = new Logger('CONSOLE', new ConsoleHandler());
consoleLogger.info('message to console');

在content-script使用插件内的资源(文件、html、css等)

import { getURL } from "./brower";

getURL('/images/chrome-icon.png');

chrome-extension-react-antd-template's People

Contributors

raojinlin 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.