Create a chrome extension that reminds you

Tram Ho

Introduce

The purpose is to test the extension on chrome, it is responsible for displaying a popup prompt to write the correct formmat commit when sending pull in github, for “forgetful” members: v. Now let’s get started!

Code

First we create the manifest.json file

Inside:

name : This is the name of the extension.

description : Description for the extension.

version : The version of extenssion.

browser_action : Used to customize the icon, popup, tooltip, this article I only use the icon .. see more Browser Action

permissions : list the permissions that your extension wants to use, declare the website urls that it wants to run and the permissions. See also permissions

manifest_version : is the chrome extension you use (currently version 2). You can see here manifest_version

content_scripts : used to list the files that will be injected into the chrome browser, when visiting websites that match the addresses declared in matches, as here are all pages. Content Scripts

Create the index.js file

/https://github.com(.*compare)/ This is a regex check if it is on the github page and the url contains compare or pull , we show popup

htmlToElement function to create html element from string

follow simply go to the page to create a popup in the hidden state check url in the right condition for display

Create app.css file

Create css file to style popup:

Setting

That’s enough for our extension to work already. To install it, we can enter the chrome://extensions/ url in chrome://extensions/ address bar, enable Chế độ dành cho nhà phát triển , then select Tải tiện ích đã giải nén . Next, select the folder containing the code and press the Ok button.

summary

because github is written in SPA style, we should detect when the url changes, show popup

One way is to use setInterval () to check

Source : https://github.com/trangianhuan/reminder Demo when visiting github:

You notice your extension after installation is a small yellow bell icon in the address bar

Share the news now

Source : Viblo