-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28584de
commit adbcec5
Showing
10 changed files
with
316 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
var active = false; | ||
|
||
|
||
|
||
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { | ||
console.log("onUpdated"); | ||
refresh(); | ||
}); | ||
|
||
chrome.tabs.onActivated.addListener(function(activeInfo) { | ||
//console.log("onActivated"); | ||
// refresh(); | ||
}); | ||
|
||
function init() { | ||
|
||
refresh(); | ||
} | ||
|
||
function refreshIcon() { | ||
console.log("background.refreshIcon()"); | ||
|
||
var icon = active ? "icon-active.png" : "icon-inactive.png"; | ||
|
||
console.log("active=%s, icon=%s", active, icon); | ||
chrome.browserAction.setIcon({ | ||
path: icon | ||
}); | ||
} | ||
|
||
function refresh() { | ||
console.log("background.refresh()"); | ||
|
||
active = localStorage['status'] === "true"; | ||
|
||
|
||
console.log("active=%s", active); | ||
|
||
refreshIcon(); | ||
|
||
if (!active) { | ||
return; | ||
} | ||
|
||
chrome.tabs.query({currentWindow : true}, function(tabs){ | ||
|
||
var tabIds = []; | ||
|
||
if (localStorage['blocklist']) { | ||
var terms = JSON.parse(localStorage['blocklist']); | ||
|
||
for (var j=0; j < tabs.length; j++) { | ||
var tab = tabs[j]; | ||
for (var i=0; i<terms.length; i++) { | ||
var term = terms[i]; | ||
var url = tab.url; | ||
var regex = new RegExp(term, "ig"); | ||
var match = tab.url.match(regex); | ||
|
||
console.log("term=%s, url=%s, regex=%s, match=%s", term, url, regex, match); | ||
|
||
if (match) { | ||
tabIds.push(tab.id); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
chrome.tabs.remove(tabIds, function() { | ||
console.log("Removed tabIds=%s", tabIds); | ||
}); | ||
|
||
}); | ||
|
||
|
||
} | ||
|
||
init(); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"manifest_version": 2, | ||
|
||
"name": "Productivity Enforcer", | ||
"description": "A simple Chrome Extension that prevents the browser from launching websites, which you specify.", | ||
"version": "3.2", | ||
|
||
"permissions": [ | ||
"activeTab", | ||
"tabs" | ||
], | ||
|
||
"browser_action": { | ||
"default_icon": "icon.png", | ||
"default_popup": "popup.html" | ||
}, | ||
|
||
"icons": { | ||
"16":"icon-16.png", | ||
"48":"icon-48.png", | ||
"128":"icon-128.png" | ||
}, | ||
|
||
"background": { | ||
"scripts": ["background.js"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Productivity Enforcer Extension Popup</title> | ||
<style> | ||
body { | ||
min-width: 320px; | ||
overflow-x: hidden; | ||
font-family: verdana; | ||
} | ||
|
||
.blocklist_section { | ||
font-size: 8pt; | ||
} | ||
|
||
#blockedlist_listing_select { | ||
width: 100%; | ||
} | ||
|
||
#blocklist_status_label { | ||
padding-right: 2px; | ||
width: 100px; | ||
display: inline; | ||
} | ||
|
||
.inactive { | ||
color: red; | ||
} | ||
|
||
.active { | ||
color: green; | ||
} | ||
|
||
.scrollable{ | ||
overflow: auto; | ||
width: 100%; /* adjust this width depending to amount of text to display */ | ||
height: 70px; /* adjust height depending on number of options to display */ | ||
border: 1px silver solid; | ||
} | ||
.scrollable select{ | ||
border: none; | ||
} | ||
|
||
</style> | ||
|
||
</head> | ||
<body> | ||
|
||
<div id="blocklist_status" class="blocklist_section"> | ||
<h3>Status</h3> | ||
|
||
<div id="blocklist_status_label" class="inactive">Inactive</div><button id="blocklist_status_button"></button> | ||
|
||
</div> | ||
<div id="blocklist_listing" class="blocklist_section"> | ||
<h3>Blocked Terms</h3> | ||
<p> | ||
The following list contains terms that are blocked. If any of the following terms appears in the browser's URL/search bar, the corresponding tab will be closed or blocked from opening. | ||
</p> | ||
<div class="scrollable"> | ||
<select multiple="muliple" size="5" id="blockedlist_listing_select"> | ||
</select> | ||
</div> | ||
<button id="blocklist_listing_button">Remove Selected</button> | ||
</div> | ||
|
||
<div id="blocklist_add" class="blocklist_section"> | ||
<h3>Add New Term</h3> | ||
<p> | ||
Specify a term that, if it appears in any form in the browser's URL/search bar, will cause the tab to close. | ||
</p> | ||
<input type="text" id="blocklist_add_input"></input> | ||
<button id="blocklist_add_button">Add</button> | ||
</div> | ||
|
||
|
||
|
||
|
||
</body> | ||
<script src="popup.js"></script> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
var app=this; | ||
var active=true; | ||
|
||
// Init function | ||
function init() { | ||
console.log("init()"); | ||
|
||
var addButton = document.getElementById('blocklist_add_button'); | ||
var addButtonCallback = this.onBlocklistAdd; | ||
addButton.addEventListener('click', addButtonCallback, false); | ||
|
||
var removeButton = document.getElementById('blocklist_listing_button'); | ||
var removeButtonCallback = this.onBlocklistRemove; | ||
removeButton.addEventListener('click', removeButtonCallback, false); | ||
|
||
var statusButton = document.getElementById("blocklist_status_button"); | ||
var statusButtonCallback = this.onStatusButtonClick; | ||
statusButton.addEventListener('click', statusButtonCallback, false); | ||
|
||
app.loadBlocklist(); | ||
app.loadStatus(); | ||
app.refresh(); | ||
} | ||
|
||
function loadStatus() { | ||
console.log("loadStatus()"); | ||
if (localStorage['status']) { | ||
active = localStorage['status'] === "true"; | ||
} | ||
else { | ||
active = false; | ||
} | ||
} | ||
|
||
function refresh() { | ||
console.log("refresh()"); | ||
|
||
var statusLabel = document.getElementById("blocklist_status_label"); | ||
statusLabel.setAttribute("class",active ? "active" : "inactive"); | ||
statusLabel.innerHTML = active ? "Active" : "Inactive"; | ||
|
||
var statusButton = document.getElementById("blocklist_status_button"); | ||
statusButton.innerHTML = active ? "Turn Off" : "Turn On"; | ||
|
||
refreshBackgroundPage(); | ||
} | ||
|
||
function onStatusButtonClick() { | ||
app.active = !active; | ||
localStorage['status'] = active; | ||
|
||
app.refresh(); | ||
} | ||
|
||
function refreshBackgroundPage() { | ||
console.log("refreshBackgroundPage()"); | ||
var bgPage = chrome.extension.getBackgroundPage(); | ||
bgPage.refresh(); | ||
} | ||
|
||
// Add a term to the blocked list. | ||
function addTermToBlocklist(term) { | ||
console.log("addTermToBlocklist(), term=%s", term); | ||
|
||
var select = document.getElementById("blockedlist_listing_select"); | ||
select.add(new Option(term, term)); | ||
} | ||
|
||
function onBlocklistAdd(e) { | ||
console.log("onBlocklistAdd(%o)", e); | ||
|
||
var input = document.getElementById("blocklist_add_input"); | ||
var term = input.value; | ||
if (term.length > 0) { | ||
app.addTermToBlocklist(term); | ||
} | ||
|
||
input.value = ""; | ||
|
||
app.saveBlocklist(); | ||
app.refreshBackgroundPage(); | ||
} | ||
|
||
function onBlocklistRemove(e) { | ||
console.log("onBlocklistRemove(%o", e); | ||
|
||
var select = document.getElementById("blockedlist_listing_select"); | ||
|
||
for (i = select.length - 1; i>=0; i--) { | ||
if (select.options[i].selected) { | ||
select.remove(i); | ||
} | ||
} | ||
|
||
app.saveBlocklist(); | ||
} | ||
|
||
function saveBlocklist() { | ||
console.log("saveBlocklist()"); | ||
|
||
var select = document.getElementById("blockedlist_listing_select"); | ||
var options = select.options; | ||
|
||
var terms = []; | ||
for (var i=0; i<options.length; i++){ | ||
terms.push(options[i].value); | ||
} | ||
|
||
localStorage['blocklist'] = JSON.stringify(terms); | ||
|
||
} | ||
|
||
function loadBlocklist() { | ||
console.log("loadBlocklist()"); | ||
|
||
if (localStorage['blocklist']) { | ||
var terms = JSON.parse(localStorage['blocklist']); | ||
for (var i=0; i<terms.length; i++) { | ||
app.addTermToBlocklist(terms[i]); | ||
} | ||
} | ||
} | ||
|
||
// Methods to be run upon loading of DOM content. | ||
document.addEventListener('DOMContentLoaded', function () { | ||
init(); | ||
|
||
}); |