Blockable items: Show filter source

Everything about using Adblock Plus on Mozilla Firefox, Thunderbird and SeaMonkey
Post Reply
User avatar
Hubird
Posts: 2850
Joined: Thu Oct 26, 2006 2:59 pm
Location: Australia
Contact:

Blockable items: Show filter source

Post by Hubird »

Image


The following code will enable an extra column in the ABP blockable items list that displays the filter source. Perhaps this feature can be included in a future version:

Code: Select all

diff -r 185115c73365 chrome/content/ui/sidebar.js
--- a/chrome/content/ui/sidebar.js	Fri Apr 15 16:46:17 2011 +0200
+++ b/chrome/content/ui/sidebar.js	Mon Apr 25 13:21:07 2011 +1000



@@ -657,16 +657,43 @@ function compareDocDomain(item1, item2)
   else if (item1.thirdParty && !item2.thirdParty)
     return -1;
   else if (!item1.thirdParty && item2.thirdParty)
     return 1;
   else
     return 0;
 }
 
+function compareFilterSource(item1, item2) {
+  if (item1.filter==null && item2.filter==null)
+    return 0;
+  else if (item1.filter==null && item2.filter!=null)
+    return -1;
+  else if (item1.filter!=null && item2.filter==null)
+    return 1;
+	
+  var subs1 = item1.filter.subscriptions;
+  var subs2 = item2.filter.subscriptions;
+	
+  for (var i=0; i<subs1.length && i<subs2.length; ++i) {
+	if (subs1[i].title < subs2[i].title)
+	  return -1;
+	else if (subs1[i].title > subs2[i].title)
+	  return 1;
+  }
+  
+  var diff = subs1.length - subs2.length;
+  if (diff < 0)
+    return -1;
+  else if (diff > 0)
+    return 1;
+  else
+    return 0;
+}
+
 function createSortWithFallback(cmpFunc, fallbackFunc, desc) {
   var factor = (desc ? -1 : 1);
 
   return function(item1, item2) {
     var ret = cmpFunc(item1, item2);
     if (ret == 0)
       return fallbackFunc(item1, item2);
     else
@@ -709,17 +736,17 @@ var treeView = {
   setTree: function(boxObject) {
     if (!boxObject)
       return;
 
     this.boxObject = boxObject;
     this.itemsDummy = boxObject.treeBody.getAttribute("noitemslabel");
     this.whitelistDummy = boxObject.treeBody.getAttribute("whitelistedlabel");
 
-    var stringAtoms = ["col-address", "col-type", "col-filter", "col-state", "col-size", "col-docDomain", "state-regular", "state-filtered", "state-whitelisted", "state-hidden"];
+    var stringAtoms = ["col-address", "col-type", "col-filter", "col-state", "col-size", "col-docDomain", "col-filterSource", "state-regular", "state-filtered", "state-whitelisted", "state-hidden"];
     var boolAtoms = ["selected", "dummy", "filter-disabled"];
     var atomService = Cc["@mozilla.org/atom-service;1"].getService(Ci.nsIAtomService);
 
     this.atoms = {};
     for each (let atom in stringAtoms)
       this.atoms[atom] = atomService.getAtom(atom);
     for each (let atom in boolAtoms)
     {
@@ -773,17 +800,17 @@ var treeView = {
 
   get rowCount() {
     return (this.data && this.data.length ? this.data.length : 1);
   },
 
   getCellText: function(row, col) {
     col = col.id;
 
-    if (col != "type" && col != "address" && col != "filter" && col != "size" && col != "docDomain")
+    if (col != "type" && col != "address" && col != "filter" && col != "size" && col != "docDomain" && col != "filterSource")
       return "";
 
     if (this.data && this.data.length) {
       if (row >= this.data.length)
         return "";
 
       if (col == "type")
         return this.data[row].localizedDescr;
@@ -791,16 +818,28 @@ var treeView = {
         return (this.data[row].filter ? this.data[row].filter.text : "");
       else if (col == "size")
       {
         let size = getItemSize(this.data[row]);
         return (size ? size.join(" x ") : "");
       }
       else if (col == "docDomain")
         return this.data[row].docDomain + " " + (this.data[row].thirdParty ? docDomainThirdParty : docDomainFirstParty);
+      else if (col == "filterSource") {
+        if (!this.data[row].filter)
+          return "";
+        var subs = this.data[row].filter.subscriptions;
+        if (subs.length == 0)
+          return "";
+
+        var val = subs[0].title;
+        for (var idx=1; idx<subs.length; ++idx)
+          val += (", "  + subs[idx].title);
+        return val;
+	  }
       else
         return this.data[row].location;
     }
     else {
       // Empty list, show dummy
       if (row > 0 || (col != "address" && col != "filter"))
         return "";
 
@@ -946,17 +985,19 @@ var treeView = {
     typeDesc: createSortWithFallback(compareType, sortByAddress, true),
     filter: createSortWithFallback(compareFilter, sortByAddress, false),
     filterDesc: createSortWithFallback(compareFilter, sortByAddress, true),
     state: createSortWithFallback(compareState, sortByAddress, false),
     stateDesc: createSortWithFallback(compareState, sortByAddress, true),
     size: createSortWithFallback(compareSize, sortByAddress, false),
     sizeDesc: createSortWithFallback(compareSize, sortByAddress, true),
     docDomain: createSortWithFallback(compareDocDomain, sortByAddress, false),
-    docDomainDesc: createSortWithFallback(compareDocDomain, sortByAddress, true)
+    docDomainDesc: createSortWithFallback(compareDocDomain, sortByAddress, true),
+    filterSource: createSortWithFallback(compareFilterSource, sortByAddress, false),
+    filterSourceDesc: createSortWithFallback(compareFilterSource, sortByAddress, true)
   },
 
   clearData: function(data) {
     var oldRows = this.rowCount;
 
     this.allData = [];
     this.dataMap = {__proto__: null};
     this.refilter();
diff -r 185115c73365 chrome/content/ui/sidebar.xul
--- a/chrome/content/ui/sidebar.xul	Fri Apr 15 16:46:17 2011 +0200
+++ b/chrome/content/ui/sidebar.xul	Mon Apr 25 13:21:07 2011 +1000
@@ -128,16 +128,18 @@
       <splitter class="tree-splitter"/>
       <treecol id="type" label="&type.label;" width="80" persist="width ordinal sortDirection hidden"/>
       <splitter class="tree-splitter"/>
       <treecol id="state" label="&state.label;" width="16" persist="width ordinal sortDirection hidden"/>
       <splitter class="tree-splitter"/>
       <treecol id="size" label="&size.label;" width="60" hidden="true" persist="width ordinal sortDirection hidden"/>
       <splitter class="tree-splitter"/>
       <treecol id="docDomain" label="&docDomain.label;" width="100" hidden="true" persist="width ordinal sortDirection hidden"/>
+      <splitter class="tree-splitter"/>
+      <treecol id="filterSource" label="&filterSource.label;" width="100" hidden="true" persist="width ordinal sortDirection hidden"/>
     </treecols>
 
     <treechildren id="treechildren"
                   tooltip="tooltip"
                   onclick="handleClick(event)"
                   ondblclick="handleDblClick(event)"
                   noitemslabel="&noitems.label;"
                   whitelistedlabel="&whitelisted.label;"/>
diff -r 185115c73365 chrome/locale/en-GB/sidebar.dtd
--- a/chrome/locale/en-GB/sidebar.dtd	Fri Apr 15 16:46:17 2011 +0200
+++ b/chrome/locale/en-GB/sidebar.dtd	Mon Apr 25 13:21:07 2011 +1000
@@ -4,16 +4,17 @@
 <!ENTITY search.label "Search:">
 <!ENTITY search.accesskey "S">
 <!ENTITY type.label "Type">
 <!ENTITY address.label "Address">
 <!ENTITY filter.label "Filter">
 <!ENTITY state.label "State">
 <!ENTITY size.label "Size">
 <!ENTITY docDomain.label "Document source">
+<!ENTITY filterSource.label "List">
 <!ENTITY docDomain.thirdParty "(third party)">
 <!ENTITY docDomain.firstParty "(first party)">
 <!ENTITY noitems.label "No blockable items">
 <!ENTITY whitelisted.label "Whitelisted page">
 <!ENTITY tooltip.address.label "Address:">
 <!ENTITY tooltip.type.label "Type:">
 <!ENTITY tooltip.type.blocked "(blocked)">
 <!ENTITY tooltip.type.whitelisted "(whitelisted)">
diff -r 185115c73365 chrome/locale/en-US/sidebar.dtd
--- a/chrome/locale/en-US/sidebar.dtd	Fri Apr 15 16:46:17 2011 +0200
+++ b/chrome/locale/en-US/sidebar.dtd	Mon Apr 25 13:21:07 2011 +1000
@@ -6,16 +6,17 @@
 <!ENTITY search.label             "Search:">
 <!ENTITY search.accesskey         "S">
 
 <!ENTITY type.label               "Type">
 <!ENTITY address.label            "Address">
 <!ENTITY filter.label             "Filter">
 <!ENTITY state.label              "State">
 <!ENTITY size.label               "Size">
+<!ENTITY filterSource.label       "Source">
 <!ENTITY docDomain.label          "Document source">
 <!ENTITY docDomain.thirdParty     "(third party)">
 <!ENTITY docDomain.firstParty     "(first party)">
 
 <!ENTITY noitems.label            "No blockable items">
 <!ENTITY whitelisted.label        "Whitelisted page">
 
 <!ENTITY tooltip.address.label    "Address:">
anonymous74100
Posts: 213
Joined: Sat Mar 19, 2011 3:45 pm
Contact:

Re: Blockable items: Show filter source

Post by anonymous74100 »

What's the benefit of this feature?

P.S. Next time use imgur instead of Imageshack.
User avatar
fanboy
Posts: 3446
Joined: Sun Jun 17, 2007 4:45 am
Contact:

Re: Blockable items: Show filter source

Post by fanboy »

How well does it work with some subscriptions using the same rules?
User avatar
Hubird
Posts: 2850
Joined: Thu Oct 26, 2006 2:59 pm
Location: Australia
Contact:

Re: Blockable items: Show filter source

Post by Hubird »

anonymous74100 wrote:What's the benefit of this feature?
My original thinking was that it would help me make sure rules are in the correct list. For example if I saw a generic rule out of my adult list active on a news site it could be moved. It is just an extra (user selectable) column (we already have several to choose from). If it not a ground breaking feature, rather just a little nicety (the the tool tips) . :)
fanboy wrote:How well does it work with some subscriptions using the same rules?


Seems to handle them fine (same as the tooltips) It displays both.
anonymous74100 wrote:P.S. Next time use imgur instead of Imageshack.
What's the benefit of this site over imageshack :D :?:



I have uploaded a English GB version of the current dev build at:

http://adversity.uk.to/stuff/

adblockplus-1.3.7a.2973-en-GB.xpi

If anyone feels like testing it.


**** File removed... Get yourself a dev build :!: ****
Last edited by Hubird on Thu Apr 28, 2011 10:14 am, edited 1 time in total.
Reason: file removed
Guest

Re: Blockable items: Show filter source

Post by Guest »

Hubird wrote:Perhaps this feature can be included in a future version
Wladimir said this feature would possibly be included in Adblock Plus 1.4.0.
(Roadmap) Add "Filter source" column to blockable items
User avatar
Hubird
Posts: 2850
Joined: Thu Oct 26, 2006 2:59 pm
Location: Australia
Contact:

Re: Blockable items: Show filter source

Post by Hubird »

Oh...

I forgot about that :oops:

At least we know it can be done easily and seems to work as expected.
Wladimir Palant

Re: Blockable items: Show filter source

Post by Wladimir Palant »

The change has been pushed, thanks a lot!
https://hg.adblockplus.org/adblockplus/rev/d8618d5dcd31
https://hg.adblockplus.org/adblockplus/rev/162cf2a2a2fe

Will be part of the next development build (in 15 minutes).
User avatar
Hubird
Posts: 2850
Joined: Thu Oct 26, 2006 2:59 pm
Location: Australia
Contact:

Re: Blockable items: Show filter source

Post by Hubird »

Looks good, thanks.
Pillow

Re: Blockable items: Show filter source

Post by Pillow »

I was looking forward to this, but I don't see it in the 1.3.7 release (which is working GREAT, by the way). Did it get pushed to be released with a later version?

Thanks to everyone involved!
Wladimir Palant

Re: Blockable items: Show filter source

Post by Wladimir Palant »

It's a string change - meaning that it doesn't go onto the stable branch. It will be in Adblock Plus 1.4, until then only in the development builds.
Pillow

Re: Blockable items: Show filter source

Post by Pillow »

Thanks for the info!
Post Reply