[Pkg-mozext-commits] [adblock-plus-element-hiding-helper] 163/483: Always use raw CSS for generated expressions

David Prévot taffit at moszumanska.debian.org
Thu Jan 22 21:41:37 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository adblock-plus-element-hiding-helper.

commit a082132958bc79c7b239c6655d04d44782cc8433
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Wed Apr 29 09:46:07 2009 +0200

    Always use raw CSS for generated expressions
    
    --HG--
    extra : rebase_source : 1ea9b68d9a489c667ace8d6ba298e56ca20d20c4
---
 chrome/content/composer.js | 154 +++++++++++++++++++--------------------------
 1 file changed, 65 insertions(+), 89 deletions(-)

diff --git a/chrome/content/composer.js b/chrome/content/composer.js
index 54c2577..b485668 100644
--- a/chrome/content/composer.js
+++ b/chrome/content/composer.js
@@ -133,7 +133,7 @@ function TreeView_getRowProperties(row, properties) {
     properties.AppendElement(selectedAtom);
 
   var item = this.getItemAtIndex(row);
-  if (item && (item.nodeData.expressionRaw != "*" || item.nodeData == nodeData))
+  if (item && (item.nodeData.expression != "*" || item.nodeData == nodeData))
     properties.AppendElement(anchorAtom);
 }
 
@@ -217,10 +217,8 @@ function init() {
 
 function updateExpression() {
   var curNode = nodeData;
-  var simpleMode = true;
   while (curNode) {
-    var expressionSimple = (curNode.tagName.checked ? curNode.tagName.value : "*");
-    var expressionRaw = expressionSimple;
+    let expression = (curNode.tagName.checked ? curNode.tagName.value : "*");
 
     for (var i = 0; i < curNode.attributes.length; i++) {
       var attr = curNode.attributes[i];
@@ -238,58 +236,43 @@ function updateExpression() {
           else if (attr.value.substr(attr.value.length - attr.selected.length) == attr.selected)
             op = "$=";
   
-          if (/[^\w\-]/.test(attr.name) || /[()"]/.test(attr.selected))
-            expressionSimple = null;
-  
-          if (expressionSimple != null)
-            expressionSimple += "(" + attr.name + op + attr.selected + ")";
-  
           if (attr.name == "id" && op == "=" && !/[^\w\-]/.test(attr.selected))
-            expressionRaw += "#" + attr.selected;
+            expression += "#" + attr.selected;
           else if (attr.name == "class" && op == "=" && !/[^\w\-\s]/.test(attr.selected) && /\S/.test(attr.selected)) {
             var classes = attr.selected.split(/\s+/);
             for (var j = 0; j < classes.length; j++) {
               if (classes[j] == "")
                 continue;
 
-              expressionRaw += "." + classes[j];
+              expression += "." + classes[j];
             }
           }
           else {
             var escapedValue = attr.selected.replace(/"/g, '\\"')
                                             .replace(/\{/, "\\7B ")
                                             .replace(/\}/, "\\7D ");
-            expressionRaw += "[" + escapedName + op + '"' + escapedValue + '"' + "]";
+            expression += "[" + escapedName + op + '"' + escapedValue + '"' + "]";
           }
         }
         else {
-          expressionSimple = null;
-          expressionRaw += "[" + escapedName + "]";
+          expression += "[" + escapedName + "]";
         }
       }
     }
 
-    if (curNode.customCSS.checked && curNode.customCSS.selected != "") {
-      expressionSimple = null;
-      expressionRaw += curNode.customCSS.selected
+    if (curNode.customCSS.checked && curNode.customCSS.selected != "")
+    {
+      expression += curNode.customCSS.selected
                                         .replace(/\{/, "\\7B ")
                                         .replace(/\}/, "\\7D ");
     }
 
-    if ("firstChild" in curNode && curNode.firstChild.checked) {
-      expressionSimple = null;
-      expressionRaw += ":first-child";
-    }
-    if ("lastChild" in curNode && curNode.lastChild.checked) {
-      expressionSimple = null;
-      expressionRaw += ":last-child";
-    }
-
-    curNode.expressionSimple = expressionSimple;
-    curNode.expressionRaw = expressionRaw;
+    if ("firstChild" in curNode && curNode.firstChild.checked)
+      expression += ":first-child";
+    if ("lastChild" in curNode && curNode.lastChild.checked)
+      expression += ":last-child";
 
-    if (expressionSimple == null || (expressionRaw != "*" && curNode != nodeData))
-      simpleMode = false;
+    curNode.expression = expression;
 
     if (curNode.prevSibling)
       curNode = curNode.prevSibling;
@@ -297,69 +280,62 @@ function updateExpression() {
       curNode = curNode.parentNode;
   }
 
-  var expression;
-  if (simpleMode) {
-    expression = domainData.selected + "#" + nodeData.expressionSimple;
-    stylesheetURL = "data:text/css," + encodeURIComponent(nodeData.expressionRaw + "{display: none !important;}");
-  }
-  else {
-    expression = nodeData.expressionRaw;
-
-    var isParent = false;
-    var isRemoteParent = false;
-    var siblingCount = 0;
-    var firstRun = true;
-
-    var curData = nodeData;
-    while (curData) {
-      if (!firstRun && curData.expressionRaw != "*") {
-        var parentRelation = "";
-        if (isRemoteParent)
-          parentRelation = " ";
-        else if (isParent)
-          parentRelation = " > ";
-
-        var siblingRelation = "";
-        for (var i = 0; i < siblingCount; i++)
-          siblingRelation += "* + ";
-        siblingRelation = siblingRelation.replace(/^\*/, '');
-
-        var relation;
-        if (parentRelation != "" && siblingRelation != "")
-          relation = siblingRelation + "*" + parentRelation;
-        else if (parentRelation != "")
-          relation = parentRelation;
-        else
-          relation = siblingRelation;
-
-        expression = curData.expressionRaw + relation + expression;
-
-        isParent = false;
-        isRemoteParent = false;
-        siblingCount = 0;
-      }
-      firstRun = false;
-
-      if (curData.prevSibling) {
-        siblingCount++;
-        curData = curData.prevSibling;
-      }
-      else if (curData.parentNode) {
-        siblingCount = 0;
-        if (isParent)
-          isRemoteParent = true;
-        else
-          isParent = true;
-        curData = curData.parentNode;
-      }
+  let expression = nodeData.expression;
+
+  var isParent = false;
+  var isRemoteParent = false;
+  var siblingCount = 0;
+  var firstRun = true;
+
+  var curData = nodeData;
+  while (curData) {
+    if (!firstRun && curData.expression != "*") {
+      var parentRelation = "";
+      if (isRemoteParent)
+        parentRelation = " ";
+      else if (isParent)
+        parentRelation = " > ";
+
+      var siblingRelation = "";
+      for (var i = 0; i < siblingCount; i++)
+        siblingRelation += "* + ";
+      siblingRelation = siblingRelation.replace(/^\*/, '');
+
+      var relation;
+      if (parentRelation != "" && siblingRelation != "")
+        relation = siblingRelation + "*" + parentRelation;
+      else if (parentRelation != "")
+        relation = parentRelation;
       else
-        curData = null;
+        relation = siblingRelation;
+
+      expression = curData.expression + relation + expression;
+
+      isParent = false;
+      isRemoteParent = false;
+      siblingCount = 0;
     }
+    firstRun = false;
 
-    stylesheetURL = "data:text/css," + encodeURIComponent(expression + "{display: none !important;}");
-    expression = domainData.selected + "##" + expression;
+    if (curData.prevSibling) {
+      siblingCount++;
+      curData = curData.prevSibling;
+    }
+    else if (curData.parentNode) {
+      siblingCount = 0;
+      if (isParent)
+        isRemoteParent = true;
+      else
+        isParent = true;
+      curData = curData.parentNode;
+    }
+    else
+      curData = null;
   }
 
+  stylesheetURL = "data:text/css," + encodeURIComponent(expression + "{display: none !important;}");
+  expression = domainData.selected + "##" + expression;
+
   document.getElementById("expression").value = expression;
 
   var tree = document.getElementById("nodes-tree");

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus-element-hiding-helper.git



More information about the Pkg-mozext-commits mailing list