<file_sep>import '../img/icon-34.png';
import '../img/icon-128.png';

//  Blocked urls
var urls = [];

//  Handle incoming connections
chrome.extension.onConnect.addListener(port => {
  //  Listen for a domain to block
  port.onMessage.addListener(url => {
    urls.push("*://*." + url + "/*")
    updateBlocks();
  });
});

function updateBlocks() {
  if (urls.length > 0)
    chrome.webRequest.onBeforeRequest.addListener(() => ({cancel: true}), {urls: urls}, ['blocking']);
}
<file_sep><p align="center">
  <img src="src/img/icon-128.png">
  <h1 align="center">Blocker</h1>
</p>

> Website blocking Google Chrome extension

- :no_entry_sign: harmful sites
- :no_entry_sign: procrastination

- :heavy_check_mark: focused
- :heavy_check_mark: productivity

## Installation
> Install yarn packages
```
yarn install
```

## Clone
- Clone this repo to your local machine using `https://github.com/gurveerdhindsa/blocker.git`

## Development
```
yarn start
```
To load extension in Chrome:
- Go to chrome://extensions/
- Check 'Developer mode'
- Click 'Load unpacked extension'
- Select the build folder of this repo

##  Support
- Website at <a href="https://gurveerdhindsa.github.io/portfolio/" target="_blank">`gurveerdhindsa.github.io`</a>
<file_sep>import "../css/popup.css";
var $ = require('jQuery');

/*
  Use Chrome background page to store HTML session
*/
chrome.runtime.getBackgroundPage(bg => {
  //  Get previous session
  if(bg.sessionDataHTML){
    document.body.innerHTML = bg.sessionDataHTML;
  }
  //  Update the session to include changes
  setInterval(function(){
    bg.sessionDataHTML = document.body.innerHTML
  },1000);

  /*
    Adding a blocked site
  */
  $(".input").change(() => {
    $('.blocked-list').append('<li class="blocked-item"><p class="blocked-item--website">' + $(".input").val() + '</p></li>')
    // $('.blocked-list').append('<i class="blocked-item--delete fas fa-times" onclick=""></i></li>')

    //  Validate the domain input is correct
    //  ""
    //  ""
    //  ""

    //  Clear the input field
    //  $(".input").val('')

    //  Establish connection with extension to send messages
    var port = chrome.extension.connect({
      name: "Content script"
    })

    //  Pass the blocked domain to extension
    port.postMessage($(".input").val());
  });

  /*
    Removing a blocked site
  */
  $(".blocked-item--delete").click(function() {
    console.log("item is being deleted...")
  })

})
