Browse Source

fix(Background): fix rule tester

close #42
Gerald 9 years ago
parent
commit
455ce503e4
1 changed files with 9 additions and 11 deletions
  1. 9 11
      src/background/utils.js

+ 9 - 11
src/background/utils.js

@@ -99,25 +99,23 @@ var tester = function () {
     var custom = script.custom;
     var meta = script.meta;
     var inc = [], exc = [], mat = [];
-    var ok = true;
     if (custom._match !== false && meta.match) mat = mat.concat(meta.match);
     if (custom.match) mat = mat.concat(custom.match);
     if (custom._include !== false && meta.include) inc = inc.concat(meta.include);
     if (custom.include) inc = inc.concat(custom.include);
     if (custom._exclude !== false && meta.exclude) exc = exc.concat(meta.exclude);
     if (custom.exclude) exc = exc.concat(custom.exclude);
-    if (mat.length) {
-      // @match
-      var urlParts = url.match(match_reg);
-      ok = mat.some(function (str) {
+    var ok = !mat.length && !inc.length;
+    // @match
+    ok = ok || mat.length && function (urlParts) {
+      return mat.some(function (str) {
         return matchTest(str, urlParts);
       });
-    } else {
-      // @include
-      ok = !inc.length || inc.some(function (str) {
-        return autoReg(str).test(url);
-      });
-    }
+    }(url.match(match_reg));
+    // @include
+    ok = ok || inc.some(function (str) {
+      return autoReg(str).test(url);
+    });
     // exclude
     ok = ok && !exc.some(function (str) {
       return autoReg(str).test(url);