diff --git a/conf.js b/conf.js deleted file mode 100644 index 1f8b014..0000000 --- a/conf.js +++ /dev/null @@ -1,5 +0,0 @@ -exports.config = { - seleniumAddress: 'http://localhost:4444/wd/hub', - specs: ['test/mad-spec.js'] -} - diff --git a/icon.png b/icon.png deleted file mode 100644 index 4ebf148..0000000 Binary files a/icon.png and /dev/null differ diff --git a/img/128.png b/img/128.png deleted file mode 100644 index 4a0d547..0000000 Binary files a/img/128.png and /dev/null differ diff --git a/img/16.png b/img/16.png deleted file mode 100644 index 3de3496..0000000 Binary files a/img/16.png and /dev/null differ diff --git a/img/48.png b/img/48.png deleted file mode 100644 index 6f6e9ce..0000000 Binary files a/img/48.png and /dev/null differ diff --git a/img/default/happy3.png b/img/default/happy3.png index 9bbfc10..50f7f58 100644 Binary files a/img/default/happy3.png and b/img/default/happy3.png differ diff --git a/img/default/happy4.png b/img/default/happy4.png index aca6d50..0cba9e2 100644 Binary files a/img/default/happy4.png and b/img/default/happy4.png differ diff --git a/img/default/happy5.png b/img/default/happy5.png index 68a014b..8704103 100644 Binary files a/img/default/happy5.png and b/img/default/happy5.png differ diff --git a/img/default/template.xcf b/img/default/template.xcf deleted file mode 100644 index fdc8cb8..0000000 Binary files a/img/default/template.xcf and /dev/null differ diff --git a/js/checkerino.js b/js/checkerino.js index 9d45049..8ec9ab0 100644 --- a/js/checkerino.js +++ b/js/checkerino.js @@ -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) + " "+ 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{ diff --git a/js/controllers/headerController.js b/js/controllers/headerController.js index 70bb330..5e62a4d 100644 --- a/js/controllers/headerController.js +++ b/js/controllers/headerController.js @@ -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{ diff --git a/js/verify.js b/js/verify.js index a16030e..de8ff96 100644 --- a/js/verify.js +++ b/js/verify.js @@ -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'; diff --git a/manifest.json b/manifest.json index 82788d7..f85304f 100644 --- a/manifest.json +++ b/manifest.json @@ -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"] diff --git a/test/mad-spec.js b/test/mad-spec.js deleted file mode 100644 index 9bc5231..0000000 --- a/test/mad-spec.js +++ /dev/null @@ -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'); - - }); -});