3-4 bug fixes and some small optimizations
@@ -1,5 +0,0 @@
|
||||
exports.config = {
|
||||
seleniumAddress: 'http://localhost:4444/wd/hub',
|
||||
specs: ['test/mad-spec.js']
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 9.8 KiB |
|
Before Width: | Height: | Size: 501 B |
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 9.3 KiB After Width: | Height: | Size: 9.9 KiB |
|
Before Width: | Height: | Size: 9.3 KiB After Width: | Height: | Size: 9.5 KiB |
@@ -2,17 +2,7 @@ var globalOptions,
|
||||
blockChecker,
|
||||
blockList,
|
||||
blockService;
|
||||
var DefaultBlockList = [
|
||||
"facebook",
|
||||
"youtube",
|
||||
"twitter",
|
||||
"tumblr",
|
||||
"pinterest",
|
||||
"reddit",
|
||||
"instagram",
|
||||
"netflix",
|
||||
"twitch"
|
||||
];
|
||||
|
||||
|
||||
var saveblockList= function(){
|
||||
chrome.storage.sync.set({'blocklist': blockList}, function(){
|
||||
@@ -22,23 +12,55 @@ var saveblockList= function(){
|
||||
|
||||
|
||||
var regexMatching = function(list, target){
|
||||
var domainsArray = [
|
||||
"be",
|
||||
"com",
|
||||
"org",
|
||||
"net",
|
||||
"tv"
|
||||
];
|
||||
|
||||
var redirSites = [
|
||||
"facebook.com/l.php"
|
||||
];
|
||||
var simpleSiteRegex,
|
||||
generalRegex,
|
||||
redirRegex;
|
||||
|
||||
var domains = '(' + domainsArray[0];
|
||||
|
||||
var start = '^(http|https)://(www\\.)?';
|
||||
var end = '\\.(be|com|org|net)/[\\W\\w]*$';
|
||||
var simpleSiteRegex = new RegExp(start+'.*$');
|
||||
for (var j=1; j < domainsArray.length; j++){
|
||||
domains = domains + '|' + domainsArray[j];
|
||||
}
|
||||
domains = domains + ')'
|
||||
var end = '\\.'+ domains + '/[\\W\\w]*$';
|
||||
redirRegex = new RegExp(start + redirSites[0] + '.*$');
|
||||
simpleSiteRegex = new RegExp(start+'.*$');
|
||||
var middle = "";
|
||||
var toBlockOrNotToBlock = false;
|
||||
var exactsiesBlock = false;
|
||||
for (var i = 0; i < list.length-1; i++){
|
||||
if (!simpleSiteRegex.test(list[i])){
|
||||
middle = middle+list[i]+'|';
|
||||
middle = middle+filterSimple(list[i])+'|';
|
||||
}
|
||||
}
|
||||
middle = '('+middle+list[list.length-1]+')';
|
||||
var generalRegex = new RegExp(start+middle+end);
|
||||
if (list.indexOf(target)!==-1) toBlockOrNotToBlock = true;
|
||||
toBlockOrNotToBlock = generalRegex.test(target) || toBlockOrNotToBlock;
|
||||
middle = '('+filterSimple(middle+list[list.length-1])+')';
|
||||
generalRegex = new RegExp(start+middle+end);
|
||||
if (list.indexOf(target)!==-1) exactsiesBlock = true;
|
||||
if (generalRegex.test(target) == true){
|
||||
/* console.log(start+middle+end);
|
||||
console.log(target);
|
||||
console.log(generalRegex.test(target) + " <GR TBONTB>"+ exactsiesBlock);*/
|
||||
}
|
||||
|
||||
var ifRedirUrlBlockCheck = redirRegex.test(target);
|
||||
var toBlockOrNotToBlock = (generalRegex.test(target) || exactsiesBlock ) && !ifRedirUrlBlockCheck;
|
||||
return toBlockOrNotToBlock;
|
||||
}
|
||||
|
||||
var filterSimple = function(urlText){
|
||||
return urlText.replace('.','\\.');
|
||||
}
|
||||
|
||||
function TabObject (tabId, origUrl, blockedStatus){
|
||||
this.tabId = tabId;
|
||||
@@ -62,41 +84,75 @@ var BlockCheck = function(){
|
||||
var tabBlock;
|
||||
/* console.log('in ROM');
|
||||
console.log(blockList);*/
|
||||
var blocked = regexMatching(blockList, req.url)
|
||||
var regexBlockCheck = regexMatching(blockList, req.url)
|
||||
|
||||
var result = $.grep(currTabs, function(e){
|
||||
//console.log('e:');
|
||||
//console.log(e);
|
||||
return e.tabId == req.tabId;
|
||||
});
|
||||
if (result.length==0)
|
||||
tabBlock= false;
|
||||
else {
|
||||
//validate if tab should be blocked again or not
|
||||
//TODO ADD time functionality here
|
||||
var resultStatus = result[0].currStatus;
|
||||
if (resultStatus == false){
|
||||
tabBlock = true;
|
||||
//console.log('e:');
|
||||
//console.log(e);
|
||||
return e.tabId == req.tabId;
|
||||
});
|
||||
// console.log(result[0]);
|
||||
if (result.length==0)
|
||||
tabBlock= false;
|
||||
else {
|
||||
//validate if tab should be blocked again or not
|
||||
//TODO ADD time functionality here
|
||||
var resultStatus = result[0].currStatus;
|
||||
if (resultStatus == false){
|
||||
tabBlock = true;
|
||||
}
|
||||
}
|
||||
var subOrMain = req.type == 'sub_frame';
|
||||
regexBlockCheck = regexBlockCheck && !tabBlock && !subOrMain;
|
||||
if (regexBlockCheck){
|
||||
// console.log(req);
|
||||
/* var toInsert = new TabObject(req.tabId, req.url, true);
|
||||
currTabs.push(toInsert);*/
|
||||
InsertOrEditTabObject(req.tabId, req.url);
|
||||
storedUrl = req.url;
|
||||
return {
|
||||
redirectUrl : chrome.extension.getURL("background.html")
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
function InsertOrEditTabObject(tabId, url){
|
||||
var found = false;
|
||||
var result = $.grep(currTabs, function(e){
|
||||
if (e.tabId == tabId){
|
||||
// console.log('changed e.origUrl from: ' + e.origUrl + ' to: ' + url);
|
||||
e.origUrl = url;
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
if (!found){
|
||||
currTabs.push(new TabObject(tabId, url, true));
|
||||
}
|
||||
blocked = blocked && !tabBlock;
|
||||
if (blocked){
|
||||
var toInsert = new TabObject(req.tabId, req.url, false);
|
||||
currTabs.push(toInsert);
|
||||
storedUrl = req.url;
|
||||
return {
|
||||
redirectUrl : chrome.extension.getURL("background.html")
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
this.getUrl = function(){
|
||||
return storedUrl;
|
||||
};
|
||||
};
|
||||
|
||||
var BlockList = function (){
|
||||
|
||||
var DefaultBlockList = [
|
||||
"facebook",
|
||||
"youtube",
|
||||
"twitter",
|
||||
"tumblr",
|
||||
"pinterest",
|
||||
"reddit",
|
||||
"instagram",
|
||||
"netflix",
|
||||
"twitch"
|
||||
];
|
||||
|
||||
this.get = function(){
|
||||
chrome.storage.sync.get('blocklist', function(items){
|
||||
if (items.blocklist == undefined){
|
||||
|
||||
blockList = DefaultBlockList;
|
||||
blockChecker = new BlockCheck(blockList);
|
||||
} else{
|
||||
|
||||
@@ -6,6 +6,9 @@ var ModalInstanceCtrl = function($scope, $modalInstance) {
|
||||
//for each action keep type and what was done
|
||||
//redo in queue like fashion?
|
||||
$scope.undoBool = true;
|
||||
chrome.storage.sync.set({'alternatives': $scope.alternatives}, function(){
|
||||
console.log('saved');
|
||||
});
|
||||
$scope.undoHistoryQueue = [];
|
||||
|
||||
$scope.undo = function(){
|
||||
@@ -22,17 +25,26 @@ var ModalInstanceCtrl = function($scope, $modalInstance) {
|
||||
$scope.undoBool = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$scope.deleteSpree = false;
|
||||
|
||||
chrome.storage.sync.get('firstTimeDelete', function(item){
|
||||
if (item.firstTimeDelete == undefined){
|
||||
$scope.firstTimeDelete = false;
|
||||
} else{
|
||||
$scope.firstTimeDelete = item.firstTimeDelete;
|
||||
}
|
||||
$scope.$apply();
|
||||
});
|
||||
|
||||
$scope.deleteBlock = function(index) {
|
||||
if (!$scope.deleteSpree){
|
||||
if (!$scope.firstTimeDelete){
|
||||
if (confirm('Hey! You can still go to this site. You just gotta type a tiny message. (psst press cancel)')){
|
||||
if (confirm("You're probably a cool person. Cool people don't care about a lil typing every now and then")){
|
||||
if (confirm("Let's just assume you're doing this for good reasons (you can still press cancel if you realize you aren't)")){
|
||||
$scope.deleteSpree = true;
|
||||
if (confirm("You can delete from now on if you press OK. But I can't even think of a scenario in which deleting will help in the long run")){
|
||||
$scope.firstTimeDelete = true;
|
||||
chrome.storage.sync.set({'firstTimeDelete': $scope.firstTimeDelete}, function(){
|
||||
console.log('firstTimeDelete saved');
|
||||
});
|
||||
$scope.deleteBlock(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else{
|
||||
|
||||
@@ -49,18 +49,21 @@ var activate = function(){
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
windowId: chrome.windows.WINDOW_ID_CURRENT
|
||||
}, function (tabs, req){
|
||||
}, function (tabs){
|
||||
result = $.grep(currTabs, function(e){
|
||||
console.log(currTabs);
|
||||
e.currStatus = false;
|
||||
return e.tabId == tabs[0].id;
|
||||
});
|
||||
req = result;
|
||||
if (req.length==0){
|
||||
console.log(result[0]);
|
||||
if (result.length==0){
|
||||
return "";
|
||||
}
|
||||
else{
|
||||
$("#message").text("You've Unlocked The Button...\nI hope you don't regret this");
|
||||
console.log(result[0]);
|
||||
$(".btn-success").removeAttr("disabled");
|
||||
$(".btn-success").attr("href", req[0].origUrl);
|
||||
$(".btn-success").attr("href", result[0].origUrl);
|
||||
}
|
||||
});
|
||||
return 'poop';
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"name": "MAD - Mindful Anti Distraction",
|
||||
"short_name": "MAD BETA",
|
||||
"description": "This extension will hopefully help you be less distracted",
|
||||
"version": "0.2.0.0",
|
||||
"version": "0.2.1.1",
|
||||
"background": {
|
||||
"scripts": ["js/shared/jquery.min.js","js/checkerino.js","background.js"],
|
||||
"pages": ["background.html"]
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
describe('angularjs chrome', function() {
|
||||
it('should block site', function() {
|
||||
browser.get('http://www.reddit.com');
|
||||
expect(browser.getLocationAbsUrl()).not.toBe('http://www.reddit.com');
|
||||
|
||||
});
|
||||
});
|
||||