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
1 change: 1 addition & 0 deletions background.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
21 changes: 18 additions & 3 deletions catblock/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,16 @@ Channels.prototype = {
var entries = storage_get("channels");
if (!entries || (entries.length > 0 && !entries[0].name)) {
// Default set of channels
this.add({name: "TheCatsOfCatBlockUsersChannel", param: undefined,
enabled: true});
this.add({name: "AprilFoolsCatsChannel", param: undefined, enabled: false});
if (CATS.isEnabled()) {
this.add({ name: "TheCatsOfProjectCATS", param: undefined, enabled: true });
this.add({ name: "TheCatsOfCatBlockUsersChannel", param: undefined,
enabled: false });
this.add({ name: "AprilFoolsCatsChannel", param: undefined, enabled: false });
} else {
this.add({ name: "TheCatsOfCatBlockUsersChannel", param: undefined,
enabled: true });
this.add({ name: "AprilFoolsCatsChannel", param: undefined, enabled: true });
}
}
else {
for (var i=0; i < entries.length; i++) {
Expand Down Expand Up @@ -338,3 +345,11 @@ function TheCatsOfCatBlockUsersChannel() {
TheCatsOfCatBlockUsersChannel.prototype = {
__proto__: FlickrPhotosetChannel.prototype
};

function TheCatsOfProjectCATS() {
FlickrPhotosetChannel.call(this, "72157672535515292");
}

TheCatsOfProjectCATS.prototype = {
__proto__: FlickrPhotosetChannel.prototype
};
10 changes: 3 additions & 7 deletions catblock/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,10 @@ var picinjection = {

// "getAttribute" property of an element might be undefined,
// see github:CatBlock/catblock#65
if (typeof el.getAttribute === "function") {
return intFor(el.getAttribute(prop));
if (typeof el.getAttribute !== "function") {
return intFor(window.getComputedStyle(el)[prop]);
} else {
try {
return intFor(window.getComputedStyle(el)[prop]);
} catch(e) {
return undefined;
}
return intFor(el.getAttribute(prop) || window.getComputedStyle(el)[prop]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not part of another PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kpeckett This was changed as part of a merge commit from master to project-cats branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try rebasing next time: https://www.atlassian.com/git/tutorials/merging-vs-rebasing/ avoids extra commits appearing.

}
},

Expand Down
13 changes: 7 additions & 6 deletions catblock/options/catblock.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// TODO: Star and remove photos in a channel

function mayDelete(channelData) {
if (channelData.name === "AprilFoolsCatsChannel") {
return false;
}
if (channelData.name === "TheCatsOfCatBlockUsersChannel") {
return false;
switch (channelData.name) {
case "AprilFoolsCatsChannel":
case "TheCatsOfCatBlockUsersChannel":
case "TheCatsOfProjectCATS":
return false;
default:
return true;
}
return true;
}

function displayName(channelData) {
Expand Down
16 changes: 14 additions & 2 deletions js/adblock_start_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,23 @@ function block_list_via_css(selectors) {

function debug_print_selector_matches(data) {
var selectors = data.selectors;

// An array containing elements,
// which should be hidden and replaced by pictures
// see github:CatBlock/catblock#34
var elements = [];

selectors.
filter(function(selector) { return document.querySelector(selector); }).
forEach(function(selector) {
if (!SAFARI) {
augmentHiddenElements(selector);
var elem = document.querySelector(selector);
// Augment any new element, which should be replaced
// by picture of cats (or anything else...)
if (elements.indexOf(elem) === -1) {
elements.push(elem);
augmentHiddenElements(selector);
}
}
if (data.settings && data.settings.debug_logging) {
var matches = "";
Expand Down Expand Up @@ -241,4 +253,4 @@ function adblock_begin(inputs) {
inputs.success();
}
});
}
}
9 changes: 8 additions & 1 deletion js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ if (!SAFARI) {
}
if (data.start === undefined) {
data.start = Date.now();
sessionstorage_set("installed", true);
}
if (data.total === undefined) {
data.total = 0;
Expand Down Expand Up @@ -1525,8 +1526,14 @@ function makeReport() {
return out;
}

var channels = null;

// Init "Project CATS"
CATS.init(function() {
channels = new Channels();
});

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

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

if (shouldEnableCats) {
chrome.runtime.sendMessage({ command: "enableprojectcats" });
} else {
chrome.runtime.sendMessage({ command: "disableprojectcats" });
}

// Remove the key from a local storage
localStorage.removeItem(key);
})();
54 changes: 54 additions & 0 deletions js/cats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var CATS = {
init: function(callback) {
var self = this;

// First-time running code after installation, set "CATS" to disabled by default
// Opening up installed page, which will determine,
// whether CATS should be enabled or not
if (self.isEnabled() === undefined && sessionstorage_get("installed")) {
sessionstorage_set("installed"); // present with a new user

var installedURL = "https://catblock.tk/installed.html";
chrome.tabs.create({ url: installedURL }, function(data) {
var tabId = data.id;
var fileToInject = "js/cats-cs.js";

// 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 !== "enableprojectcats" &&
request.command !== "disableprojectcats") {
return;
}
if (request.command === "enableprojectcats") {
self.enable();
callback();
} else {
self.disable();
callback();
}
});

// Inject cats-cs content script, which determines,
// whether Project CATS should be allowed or not
chrome.tabs.executeScript(tabId, { file: fileToInject });
});
// When "CATS" is enabled,
// we don't need to have our listener running
} else if (self.isEnabled()) {
return callback();
} else if (self.isEnabled() === false) {
return callback();
}
},
enable: function() {
storage_set("project_cats", true);
},
disable: function() {
storage_set("project_cats", false);
},
isEnabled: function() {
//return true;
return storage_get("project_cats");
}
}
2 changes: 1 addition & 1 deletion tools/make_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def prepareManifestFile():
"applications": {
"gecko": {
"id": "catblock@catblock.tk",
"strict_min_version": "48.*"
"strict_min_version": "48.0"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion uiscripts/blacklisting/blacklistui.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ BlacklistUi.prototype._preview = function(selector) {
// Inputs: value:string - value to truncate
// size?:int - max size above which to truncate, defaults to 50
BlacklistUi._ellipsis = function(value, size) {
if (value === null) {
if (!value) {
return value;
}

Expand Down