Giter Club home page Giter Club logo

xtensio's Introduction

A javascript framework for building browser extensions. It takes away all the tedious configurations away from you and lowers the barrier to extension development.

๐Ÿคท๐Ÿฝโ€โ™‚๏ธ How does it work?

xtensio provides you with a folder structure that comes with configurations already baked in. Hence, no configuration is needed to get started with your new extension project. Currently, it mainly supports React for development.

๐Ÿš€ Creating a new Extension Project

To create a new extension project using xtensio, you can use the create command below which will then ask for your project name.

# npm
npx create-xtensio-app

# yarn
yarn create xtensio-app

OR

# npm
npx create-extension-app

# yarn
yarn create extension-app

๐Ÿ—‚๏ธ Folder Structure

Below is what the project structure with xtensio looks like and we'll be focusing on the folders.

.
โ”œโ”€โ”€ ๐Ÿ“‚ popup
โ”‚   โ””โ”€โ”€ popup.tsx
โ”œโ”€โ”€ ๐Ÿ“‚ contents
โ”‚   โ”œโ”€โ”€ content_one.tsx
โ”‚   โ””โ”€โ”€ content_two.tsx
โ”œโ”€โ”€ ๐Ÿ“‚ pages
โ”‚   โ””โ”€โ”€ options.tsx
โ”œโ”€โ”€ ๐Ÿ“‚ background
โ”‚   โ””โ”€โ”€ index.ts
โ”œโ”€โ”€ manifest.ts
โ”œโ”€โ”€ index.d.ts
โ””โ”€โ”€ tsconfig.json

๐Ÿ“‚ Popup

Inside the popup folder is a file popup.tsx which exports a React component. This is the single entry point for your extension popup. The extension popup is the view that is rendered when you click on an extension icon. Just like seen in the image below.

In case your extension requires no popup then you can just delete or get rid of this file located at /popup/popup.tsx

๐Ÿ“‚ Contents

The heart of extension development โค๏ธ

The primary goal of a browser extension is to change the user experience in the browser. This could mean changing the looks or adding some weird functionalities to websites rendered in the browser. All that great magic is handled in this contents directory.

Here is an example of a contentscript that renders a simple box modal at the right bottom corner whenever a user is on the google.com website.

// filename: /contents/googleGPT.tsx
import React from "react";
import styles from "./googleGPT.modules.css";

// export a function called getConfig - This is required
// matches is an array of URL's where the code in this file should execute - required
export function getConfig() {
  return {
    matches: ["*://*.google.com"],
  };
}

// This code will be logged whenever the user is
// on the websites specified in matches above
console.log("I'm on the google page!");

const BoxModal: React.FC = () => {
  return (
    <div className={styles.boxModal}>
      <button>Search with GPT</button>
    </div>
  );
};

// If your default export is a React component we'll mount it on
// the websites specified in matches above
export default BoxModal;

As you can see above, you're required to export a function getConfig which specifies where the content file should be executed. Then, any code written in the file will be executed once the user is on the websites specified in getConfig.

Also, if your default export is a React component, then it'll be nicely mounted into the website for you.

NOTE: you can give any name to the files you create in this directory. They just need to export the getConfig function specifying the websites.

๐Ÿ“‚ Pages

Any file created in here is turned into an extension page. An extension page is a webpage that is hosted locally by your extension. This can be used to build stuff like the options or settings page for your extension. These pages can be reached by using the utility function visitPage that comes with the xtensio package.

Example: If you create a file called settings.tsx in the pages directory that exports a react component, an extension page will be generated from that and you can navigate to that page using the code below.

import { visitPage } from "xtensio";
...
const buttonClickHandler = () => {
    visitPage("settings"); // navigates to the settings.tsx page
}

return <button onClick={buttonClickHandler}>Visit Settings Page</button>

๐Ÿ“‚ Background

Inside the background folder is an index.ts file which serves as your single entry point for your extension's service worker or background script.

You can freely create other files in the background directory and use them or import them into the index.ts file.

๐Ÿ“œ Manifest.ts

This is the main file that handles most of the configurations related to a browser extension. It exports a JavaScript object as default which is used in generating the manifest.json which is required when creating a browser extension.

Even though this configuration can be extended, some parts of it may be overwritten by xtensio. Mainly the content_scripts background action.

xtensio's People

Contributors

doc-han avatar

Stargazers

Arnav Anand avatar c.j.c avatar MK avatar Noman Dhoni avatar  avatar Elvis Opoku Amoako avatar muqsit avatar Reginald Nyarko avatar Mathias Boampong avatar Anuebunwa ifeanyi avatar Anthony Alaribe avatar Arslan avatar Akinyele Oluwatosin Akintayo avatar Aikins Laryea avatar Mike Attara avatar Kelvin Amoaba avatar Ephraim Duncan avatar ISICHEI PHELIM avatar Abdullah Anwar avatar  avatar olostep avatar Benjamin Chavez avatar Vincent Arlou avatar Dimah Snisarenko avatar Pierre Beitz avatar  avatar JongHak Seo avatar  avatar Ronny Polle avatar Barnabas Nomo avatar Ronny Amarante avatar Prince Ofori avatar  avatar Brian Newton avatar David Dennison avatar Amo Mensah Isaiah avatar Emmanuel Awuah avatar Konlan Mikpekoah avatar FLACE avatar  avatar  avatar Shester Gueuwou avatar Alfred avatar Amos Aidoo avatar  avatar collins avatar

Watchers

Emmanuel Awuah avatar  avatar Alfred avatar collins avatar Elvis Opoku Amoako 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.