Skip to content

Commit

Permalink
Merge pull request #1 from WesleyBranton/Version-1.0
Browse files Browse the repository at this point in the history
Version 1.0
  • Loading branch information
WesleyBranton committed Jun 27, 2019
2 parents 524a496 + df8aa08 commit 949686d
Show file tree
Hide file tree
Showing 15 changed files with 735 additions and 1 deletion.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# Website-Blocker
# Website Blocker
The Website Blocker browser extension for Firefox is a utility that allows you to easily block access to specific websites. It's useful for blocking annoying popups, inappropriate websites and websites that you just want to avoid.

**PRODUCT PAGE:** [View Now](https://addons.mozilla.org/firefox/addon/the-website-blocker/)

## Development
This repository contains all of the required source code files to make changes to this extension. The "master" branch contains the source code for the latest stable release. If you want to test that version, you can view the release section to download the XPI file or visit the add-on listing on Mozilla.

If you want to make changes to this extension, you are welcome to do so. All files for the extension are located in the "firefox" folder. The source code of upcoming versions (if any) will be located in another branch.

To develop and test the extension, you need to open the "about:debugging" page in Firefox and select "Load Temporary Add-on". Then you can select any file within the "firefox" folder of this repository.

Further documentation about developing Firefox extensions can be found [here](https://developer.mozilla.org/docs/Mozilla/Add-ons/WebExtensions/Your_first_WebExtension).

## Release Notes
Binary file added assets/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions firefox/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

// Create block handler
async function createBlocker() {
// Remove previous listener
browser.webRequest.onBeforeRequest.removeListener(block);

// Load URLs from storage
let urls = await browser.storage.sync.get();

// Check if there are URLs to load
if (urls.urlList) {
// Create URL fliter list
filter = [];
for (i = 0; i < urls.urlList.length; i++) {
filter.push(urls.urlList[i]);
}

// Create listener
browser.webRequest.onBeforeRequest.addListener(block, {urls: filter}, ["blocking"]);
}
}

// Handle blocked URL
function block(requestDetails) {
return {redirectUrl: browser.runtime.getURL('/blocked/blockpage.html')};
}

// Handles missing data
async function checkData() {
// Load URLs from storage
let data = await browser.storage.sync.get();

// Create blank URL list in storage if required
if (!data.urlList) {
browser.storage.sync.set({urlList:[]});
}
}

var filter = [];
createBlocker();
browser.storage.onChanged.addListener(createBlocker);
checkData();
23 changes: 23 additions & 0 deletions firefox/blocked/blockpage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at https://mozilla.org/MPL/2.0/. -->
<!DOCTYPE html>
<html>
<head>
<title>Website blocked!</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="../icons/icon-96.png">
<link rel="stylesheet" href="theme.css">
<script src="script.js"></script>
</head>
<body>
<div class="spacer"></div>
<div class="content">
<span>Website</span>
<img src="logo.png">
<span>Blocked</span>
</div>
<div class="spacer"></div>
</body>
</html>
Binary file added firefox/blocked/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions firefox/blocked/theme.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

/* Set cursor and disable text selection */
* {
cursor: default;
-moz-user-select: none;
}

/* Body */
body {
background: #FF950E;
display: flex;
flex-direction: column;
height: 100vh;
margin: 0px;
padding: 0px;
}

/* Center everything */
div {
margin: auto;
}

/* Spacers */
.spacer,
.content * {
flex: 1;
}

/* Content container */
.content {
display: flex;
flex-direction: column;
text-align: center;
}

/* Text */
.content span {
color: white;
font: bold 4vh sans-serif;
text-transform: uppercase;
}

/* Logo */
img {
margin: auto;
width: 20vh;
}
Binary file added firefox/icons/icon-128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox/icons/icon-32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox/icons/icon-48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox/icons/icon-64.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added firefox/icons/icon-96.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions firefox/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"manifest_version": 2,
"name": "Website Blocker",
"version": "1.0",
"description": "Block websites with ease!",
"author": "Wesley Branton",

"developer": {
"name": "Wesley Branton",
"url": "http://addons.wesleybranton.com"
},

"icons": {
"32": "icons/icon-32.png",
"48": "icons/icon-48.png",
"64": "icons/icon-64.png",
"96": "icons/icon-96.png",
"128": "icons/icon-128.png"
},

"browser_specific_settings": {
"gecko": {
"id": "websiteblocker@wesleybranton.com",
"strict_min_version": "57.0"
}
},

"options_ui": {
"open_in_tab": true,
"browser_style": false,
"page": "options/options.html"
},

"background": {
"scripts": ["background.js"]
},

"web_accessible_resources": ["/blocked/blockpage.html"],

"permissions": ["storage","webRequest","webRequestBlocking","<all_urls>"]
}
79 changes: 79 additions & 0 deletions firefox/options/options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at https://mozilla.org/MPL/2.0/. -->
<!DOCTYPE html>
<html>
<head>
<title>Website Blocker Options</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="../icons/icon-96.png">
<link rel="stylesheet" href="theme.css">
<script src="script.js"></script>
</head>
<body>
<!-- Page selection buttons -->
<header class="container">
<div id="selected" class="add">Add</div>
<div class="remove">Remove</div>
<div class="backup">Backup/Restore</div>
</header>

<!-- Content container -->
<section id="main" class="page add">

<!-- Add page -->
<section id="add" class="group">
<section id="add-advanced" class="container">
<select id="add-mode">
<option value="domain" selected>Block domain (Default)</option>
<option value="subdomain">Block domain & all subdomains</option>
<option value="page">Block a specific page</option>
<option value="custom">Fully custom (Advanced only)</option>
</select>
</section>
<section id="add-dialog" class="container">
<input type="text" id="add-url" placeholder="*.example.com">
<button id="add-button">+</button>
</section>
<section class="note">
To select all subdomains or all subpages, using an asterisk. For example, <u>*.example.com</u> will block all subdomains of example.com and <u>example.com/blog/*</u> will block all subpages of blog.
<a id="wildcardInfo">Learn more</a>
</section>
</section>

<!-- Remove page -->
<section id="search" class="group">
<section id="search-dialog" class="container">
<input type="text" id="search-box" placeholder="Search for a URL">
<button id="search-button">></button>
</section>
</section>

<!-- URL list table -->
<section id="list" class="group">
<h3>Blocked Websites</h3>
<section id="url-list"></section>
<div id="url-list-none">No websites blocked</div>
</section>

<!-- Backup/Restore page -->
<section id="backup" class="group">
<h3>Backup</h3>
<section class="container">
<textarea id="backuptext" readonly></textarea>
</section>
<button id="copytext">Copy To Clipboard</button>
<hr>
<h3>Restore</h3>
<section class="container">
<textarea id="restoretext"></textarea>
</section>
<input type="checkbox" name="overwrite" id="overwrite">
<label for="overwrite">Overwrite existing websites</label>
<br>
<button id="restore">Restore Website List</button>
</section>
</section>
</body>
</html>

0 comments on commit 949686d

Please sign in to comment.