mirror of
https://github.com/wassname/mad.git
synced 2026-06-30 16:40:22 +08:00
infiinite redirect loops hopefully fixed
This commit is contained in:
@@ -10,7 +10,9 @@ console.log(blockList);
|
||||
console.log("did background.js load properly");
|
||||
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);
|
||||
|
||||
+29
-4
@@ -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){
|
||||
console.log(req);
|
||||
var blocked = regexMatching(blocklist, req.url) && (req.tabId!==prevTabId) ;
|
||||
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;
|
||||
prevTabId= req.tabId;
|
||||
// prevTabId= req.tabId;
|
||||
return {
|
||||
redirectUrl : chrome.extension.getURL("background.html")
|
||||
};
|
||||
|
||||
+32
-7
@@ -45,14 +45,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)");
|
||||
@@ -64,9 +91,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)");
|
||||
|
||||
+2
-2
@@ -2,9 +2,9 @@
|
||||
"manifest_version": 2,
|
||||
"name": "MAD - Mindfulness Anti Distraction",
|
||||
"description": "This extension will hopefully help you be less distracted (untested)",
|
||||
"version": "0.1.0.2",
|
||||
"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"]
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user