diff --git a/background.html b/background.html index 0d9c53d..47fa497 100644 --- a/background.html +++ b/background.html @@ -25,19 +25,19 @@
- - + + Go Back

Change the Habit


-
- - +
+ + -

Code in a new language

+

Make/Look at your to-do list

@@ -45,11 +45,30 @@

Learn new mathematics and sciences

- +
+
+ +

Speak a new language, forever

+
+ + + +

Code in a new language, forever

+
+ +
diff --git a/background.js b/background.js index ae5b3af..ede6033 100644 --- a/background.js +++ b/background.js @@ -1,8 +1,22 @@ +var blockChecker, + blockList, + blockService; + +blockService = BlockListFactory.getBlockList(); +blockService.set(DefaultList); +blockList = blockService.get(); +console.log(blockList); + +console.log("did background.js load properly"); +blockChecker = new BlockCheck(DefaultList); + +var prevSite = ""; chrome.webRequest.onBeforeRequest.addListener( function(details) { - console.log("Is this evenf ucking working details.url: " + details.url); - console.log(details); - return {redirectUrl: "http://google.com"}; + // console.log("Is this evenf ucking working details.url: " + details.url); + // console.log(details); + prevSite = blockChecker.getUrl(); + return blockChecker.redirectOnMatch(details); }, { urls: [""] diff --git a/img/codeacad.png b/img/codeacad.png deleted file mode 100644 index 7e44e37..0000000 Binary files a/img/codeacad.png and /dev/null differ diff --git a/img/duolingo.png b/img/duolingo.png deleted file mode 100644 index 440512d..0000000 Binary files a/img/duolingo.png and /dev/null differ diff --git a/img/gkeep.jpg b/img/gkeep.jpg new file mode 100644 index 0000000..4583179 Binary files /dev/null and b/img/gkeep.jpg differ diff --git a/js/.block.js.swp b/js/.block.js.swp deleted file mode 100644 index f336505..0000000 Binary files a/js/.block.js.swp and /dev/null differ diff --git a/js/.checkerino.js.swp b/js/.checkerino.js.swp deleted file mode 100644 index 5abf528..0000000 Binary files a/js/.checkerino.js.swp and /dev/null differ diff --git a/js/.unblock.js.swp b/js/.unblock.js.swp deleted file mode 100644 index 6da551f..0000000 Binary files a/js/.unblock.js.swp and /dev/null differ diff --git a/js/.verify.js.swp b/js/.verify.js.swp deleted file mode 100644 index 1295052..0000000 Binary files a/js/.verify.js.swp and /dev/null differ diff --git a/js/checkerino.js b/js/checkerino.js index 6dd2b28..da47585 100644 --- a/js/checkerino.js +++ b/js/checkerino.js @@ -1,5 +1,69 @@ -chrome.browserAction.onClicked.addListener(function(tab) { - chrome.tabs.executeScript({ - code: 'document.body.style.backgroundColor="red"' - }); -}); + +var DefaultList = [ + "facebook", + "youtube", + "twitter", + "tumblr", + "pinterest", + "myspace", + "livejournal", + "digg", + "stumbleupon", + "reddit", + "kongregate", + "newgrounds", + "addictinggames", + "hulu", + "pornhub" + ]; +var regexMatching = function(list, target){ + var start = '^(http|https)://(www\\.)?('; + var end = '\\.(be|com|org|net)/[\\W\\w]*$'; + var middle = ""; + for (var i = 0; i < list.length-1; i++){ + middle = middle+list[i]+'|'; + } + middle = middle+list[list.length-1]+')'; + var x = new RegExp(start+middle+end); + //console.log("what is target: " + target); + //console.log("what is xtesttarget: " + x.test(target)); + return x.test(target); +} + + +var BlockCheck = function(blocklist){ + var storedUrl=""; + var prevTabId; + // TODO include timestamps check var prevTimeStamp=0; + this.blocklist = blocklist; + + this.redirectOnMatch = function(req){ + console.log(req); + var blocked = regexMatching(blocklist, req.url) && (req.tabId!==prevTabId) ; + if (blocked){ + storedUrl = req.url; + prevTabId= req.tabId; + return { + redirectUrl : chrome.extension.getURL("background.html") + }; + } + }; + this.getUrl = function(){ + return storedUrl; + }; +}; + +var BlockList = function (){ + this.get = function(){ + return JSON.parse(localStorage['blocklist']); + }; + this.set = function(data){ + localStorage['blocklist'] = JSON.stringify(data); + }; +}; + +var BlockListFactory = { + getBlockList: function(){ + return new BlockList(); + } +}; diff --git a/js/verify.js b/js/verify.js index bf906b2..8f56f1c 100644 --- a/js/verify.js +++ b/js/verify.js @@ -1,9 +1,3 @@ -/* A convenience function to reverse a string, and - * one to set the content of an element. - */ - -function reverse(s){return s.split('').reverse().join('')} - function set(el,text){ while(el.firstChild)el.removeChild(el.firstChild); el.appendChild(document.createTextNode(text)) @@ -11,10 +5,11 @@ function set(el,text){ var sayings = [ "I am in control over what I am doing. I am not distracted", - "I am as aware of my tongue as much as I am aware of how distracted the site I am going to can make me", "I have done all my goals today and am focused", + "I can totally type to 10 and still choose not to go to an alternative site. 1 2 3 4 5 6 7 8 9 10.", "I am not habitually going to this site after creating a new tab. I have good reasons for going to this site", - "I can always go to this site later in the day and there is no urgency to visit this site, but I am going anyways" + "There are so many better things to do. I'll still go through typing this to experience this banal web site.", + "I can always go to this site later in the day and there is no urgency to visit this site, but I am going anyways despite what's best for me" ] /* setupUpdater will be called once, on page load. */ @@ -29,8 +24,10 @@ window.onload = function setupUpdater(){ , oldText=input , timeout=null; - set(target, targetText); -/* handleChange is called 50ms after the user stops + set(target, targetText); + + +/* handleChange is called 200ms after the user stops typing. */ function handleChange(){ var newText=input.value; @@ -44,24 +41,23 @@ window.onload = function setupUpdater(){ set(orig, 'Debug: Score:' + score); } -/* eventHandler is called on keyboard and mouse events. - If there is a pending timeout, it cancels it. - It sets a timeout to call handleChange in 50ms. */ function eventHandler(){ if(timeout) clearTimeout(timeout); - timeout=setTimeout(handleChange, 200); + timeout=setTimeout(handleChange, 130); } input.onkeydown=input.onkeyup=onClick=eventHandler; }; //Button Listener function $(function(){ - $(".btn").click(function(){ + $(".btn-primary").click(function(){ if (passed){ - $("strong").text("Debug: YOU PASSED"); + $(".btn-success").removeAttr("disabled"); + console.log(chrome.extension.getBackgroundPage()); + $(".btn-success").attr("href", chrome.extension.getBackgroundPage().prevSite); } else - $("strong").text("Debug: YOU FAILED"); + $("strong").text("You failed! (typos are allowed)"); }); }); diff --git a/manifest.json b/manifest.json index bb2544f..0d424ae 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "description": "This addon will help you be less distracted", "version": "1.0", "background": { - "scripts": ["background.js"], + "scripts": ["js/checkerino.js","background.js"], "pages": ["background.html"] },