diff --git a/README.md b/README.md index ce2157d..83815b7 100644 --- a/README.md +++ b/README.md @@ -26,5 +26,11 @@ The goal is to aid the rewiring of wanting long-term goals (short-term happiness Monitoring my process. Started at HackWestern.
v0.1 29/03/2015 - Knowledge basis: code academy javascript, stack overflow, github files of other chrome extensions, chrome extension api and docs. -- Heavily inspired by other anti distraction extensions, e.g. StayFocusd or ColdTurkey. Meant to be an alternative long term method to ween one self from short term reward systems. +- Heavily inspired by other anti distraction extensions, e.g. StayFocusd or ColdTurkey. +- Wanted to manipulate myself into not being distracted, by criticizing and causing cognitive dissonance. - Knowledge gained: Negative, or annoyingly long to type guilt messages are draining. Hard to be productive when you're feeling shitty. Going to try to use inspiring, or user-empowering quotes that also make you think, but aren't depressing amongst other additional features in next vers. + +v0.1.0.3 30/03/2015 +- Changed UI so the alternatives are upfront, more immediate and relatively bigger. Intuitively that should be the focus, not the typing to unlock/go to the website. +- Learned a bit more jquery syntax. It's much nicer for manipulating html elements =D. +- The more positive focused thoughts seem better for now... Blind optimism doesn't seem appropriate here though. diff --git a/background.js b/background.js index 14e433e..2bc7237 100644 --- a/background.js +++ b/background.js @@ -8,7 +8,9 @@ blockService.set(DefaultList); blockList = blockService.get(); blockChecker = new BlockCheck(DefaultList); +var currTabs = []; //TODO bugfix var prevSite = ""; + chrome.webRequest.onBeforeRequest.addListener( function(details) { // console.log("Is this evenf ucking working details.url: " + details.url); diff --git a/js/checkerino.js b/js/checkerino.js index dd30025..d8cbd91 100644 --- a/js/checkerino.js +++ b/js/checkerino.js @@ -30,19 +30,44 @@ var regexMatching = function(list, target){ return x.test(target); } +function TabObject (tabId, origUrl, blockedStatus){ + this.tabId = tabId; + this.currStatus = blockedStatus; + this.origUrl = origUrl; + + this.changeStatus = function(newStatus){ + this.currStatus = newStatus; + }; +} + var BlockCheck = function(blocklist){ var storedUrl=""; var prevTabId; // TODO include timestamps check var prevTimeStamp=0; this.blocklist = blocklist; - this.redirectOnMatch = function(req){ - var blocked = regexMatching(blocklist, req.url) && (req.tabId!==prevTabId) ; - if (blocked && req.method=="GET"){ - console.log(req); + + var tabBlock; + var blocked = regexMatching(blocklist, req.url) + var result = $.grep(currTabs, function(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; + } + } + blocked = blocked && !tabBlock; + if (blocked){ + var toInsert = new TabObject(req.tabId, req.url, false); + currTabs.push(toInsert); storedUrl = req.url; - if (req.tabId!==chrome.extension.getURL) prevTabId= req.tabId; return { redirectUrl : chrome.extension.getURL("background.html") }; diff --git a/js/verify.js b/js/verify.js index 30a80fd..46cfbe8 100644 --- a/js/verify.js +++ b/js/verify.js @@ -44,14 +44,41 @@ window.onload = function setupUpdater(){ input.onkeydown=input.onkeyup=onClick=eventHandler; }; +var activate = function(){ + var currTabs = chrome.extension.getBackgroundPage().currTabs; + chrome.tabs.query({ + active: true, + windowId: window.id + }, function (tabs, req){ + /* console.log("GPS CWGC tabs"); + console.log(tabs); + console.log("GPS CWGC tabs[0]"); + console.log(tabs[0]); + console.log("GPS CWGC currTabs"); + console.log(currTabs);*/ + result = $.grep(currTabs, function(e){ + return e.tabId == tabs[0].id; + }); +/* console.log("result"); + console.log(result);*/ + req = result; + if (req.length==0){ + return ""; + } + else{ + $("#message").text("You've Unlocked The Button...\nI hope you don't regret this"); + $(".btn-success").removeAttr("disabled"); + $(".btn-success").attr("href", req[0].origUrl); + } + }); + +} + //Button Listener function yeah yeah its jquery and the rest of this wasnt, I am learning! $(function(){ $(".btn-primary").click(function(){ if (passed){ - $("#message").text("You've Unlocked The Button...\nI hope you don't regret this"); - $(".btn-success").removeAttr("disabled"); - console.log(chrome.extension.getBackgroundPage()); - $(".btn-success").attr("href", chrome.extension.getBackgroundPage().prevSite); + activate(); } else $("#message").text("You failed! (typos are allowed)"); @@ -63,9 +90,7 @@ $(function(){ $('#input-a').keydown(function(e) { if (e.keyCode == 13){ if (passed){ - $("#message").text("You've Unlocked The Button...\nI hope you don't regret this"); - $(".btn-success").removeAttr("disabled"); - $(".btn-success").attr("href", chrome.extension.getBackgroundPage().prevSite); + activate(); } else $("#message").text("You failed! (typos are allowed)"); diff --git a/manifest.json b/manifest.json index ecc9dfb..756973f 100644 --- a/manifest.json +++ b/manifest.json @@ -2,9 +2,9 @@ "manifest_version": 2, "name": "MAD - Mindful Anti Distraction", "description": "This extension will hopefully help you be less distracted (untested)", - "version": "0.1.0.4", + "version": "0.1.0.5", "background": { - "scripts": ["js/checkerino.js","background.js"], + "scripts": ["js/jquery.min.js","js/checkerino.js","background.js"], "pages": ["background.html"] },