Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project C.A.T.S. #82

Merged
merged 12 commits into from
Sep 15, 2016
Next Next commit
Initial work on Project CATS feature
Signed-off-by: Tomáš Taro <tomas@getadblock.com>
  • Loading branch information
tomasko126 committed Aug 21, 2016
commit 7be9a546842a6adc71a5820d739d90700bbc6dc2
1 change: 1 addition & 0 deletions background.html
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
<script type="text/javascript" src="filtering/myfilters.js"></script>
<script type="text/javascript" src="filtering/filternormalizer.js"></script>
<script type="text/javascript" src="js/idlehandler.js"></script>
<script type="text/javascript" src="js/cats.js"></script>
<script type="text/javascript" src="catblock/channels.js"></script>
<script type="text/javascript" src="js/edge-updates.js"></script>
<script type="text/javascript" src="js/background.js"></script>
1 change: 1 addition & 0 deletions js/adblock_start_common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//cache a reference to window.confirm
//so that web sites can not clobber the default implementation
var abConfirm = window.confirm;

// Return the ElementType element type of the given element.
function typeForElement(el) {
// TODO: handle background images that aren't just the BODY.
6 changes: 5 additions & 1 deletion js/background.js
Original file line number Diff line number Diff line change
@@ -1481,7 +1481,11 @@ makeReport = function() {
};

// CatBlock specific code
channels = new Channels();

// Init "Project CATS"
CATS.init();

var channels = new Channels();

var addChannel = function(args) {
return channels.add(args);
12 changes: 12 additions & 0 deletions js/cats-cs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Run "CATS" detection code just on the dedicated page
// cez execute script
(function() {
var shouldEnableCats = localStorage.getItem("project-cats");
console.log("should enable? ", shouldEnableCats);

if (shouldEnableCats) {
chrome.runtime.sendMessage({ command: "allowprojectcats" });
} else {
chrome.runtime.sendMessage({ command: "disallowprojectcats" });
}
})();
46 changes: 46 additions & 0 deletions js/cats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var CATS = {
init: function(callback) {
var self = this;

// First-time running code after installation, set "CATS" to disabled by default
if (self.isEnabled() === undefined) {
//var installURL = "http://catblock.tk/project-cats.html";
var installURL = "https://catblock.tk/";
chrome.tabs.create({ url: installURL }, function(data) {
var tabId = data.id;
var fileToInject = "js/cats-cs.js";
chrome.tabs.executeScript(tabId, { file: fileToInject });
});
//self.disable(); todo
// When "CATS" is enabled,
// we don't need to have our listener running
} else if (self.isEnabled()) {
return callback();
}

// Wait for a message from a content script,
// which tells us to enable "CATS"
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.command !== "allowprojectcats" &&
request.command !== "disallowprojectcats") {
return;
}
if (request.command === "allowprojectcats") {
//self.enable();
console.log("allowing cats");
} else {
//self.disable();
console.log("disabling cats");
}
});
},
enable: function() {
storage_set("project_cats", true);
},
disable: function() {
storage_set("project_cats", false);
},
isEnabled: function() {
return storage_get("project_cats");
}
}