v0.0.7

Change-Id: I8a3a3e91c13f437454d3ae83751a59f511e39042
diff --git a/release-notes.md b/release-notes.md
index 42540dd..55a73cb 100644
--- a/release-notes.md
+++ b/release-notes.md
@@ -1,3 +1,14 @@
+#### v0.0.7
+
+- Fix the issue when multiple rule matches one url for onBeforeRequest
+  - Block will always take the highest priority
+  - Then Redirect
+  - Ignore the rest
+- Add a new operator as `injectJsModule`, with plugins moving to polymer 3, certain plugins will be written in modules, and to inject moduled js plugins, use this rule
+  - This will basically add a `type="module"` to the script tag when load the script so we can use `import` inside
+  - With `type="module"`, `document.currentScript` will become `null` so we won't be able to infer the plugin url, to workaround this, make sure you call `Gerrit.install` with the third parameter: `Gerrit.install(() => {}, undefined, 'the_url')` so Gerrit can treat it as a legit plugin
+  - Keep using `injectJsPlugin` if its a single bundled js file
+
 #### v0.0.6
 
 - Add two new operators:
diff --git a/src/background.ts b/src/background.ts
index aa605b7..420f99f 100644
--- a/src/background.ts
+++ b/src/background.ts
@@ -114,22 +114,28 @@
     return {cancel: false};
   }
 
-  const match = rules.filter(isValidRule)
-                    .find(
+  const matches = rules.filter(isValidRule)
+                    .filter(
                         rule => !isInjectRule(rule) && !rule.disabled &&
                             new RegExp(rule.target).test(details.url));
-  if (match) {
-    if (match.operator === Operator.BLOCK) {
-      return {cancel: true};
-    }
 
-    if (match.operator === Operator.REDIRECT) {
-      return {
-        redirectUrl:
-            details.url.replace(new RegExp(match.target), match.destination),
-      };
-    }
+  const blockMatch = matches.find(rule => rule.operator === Operator.BLOCK);
+  const redirectMatch = matches.find(rule => rule.operator === Operator.REDIRECT);
+
+  // block match takes highest priority
+  if (blockMatch) {
+    return {cancel: true};
   }
+
+  // then redirect
+  if (redirectMatch) {
+    return {
+        redirectUrl:
+            details.url.replace(new RegExp(redirectMatch.target), redirectMatch.destination),
+      };
+  }
+
+  // otherwise, don't do anything
   return {cancel: false};
 }
 
diff --git a/src/content_script.ts b/src/content_script.ts
index dc7dbf6..5d196dc 100644
--- a/src/content_script.ts
+++ b/src/content_script.ts
@@ -68,6 +68,14 @@
           link.setAttribute('crossorigin', 'anonymous');
           document.head.appendChild(link);
         });
+      } else if (rule.operator === Operator.INJECT_JS_MODULE_PLUGIN) {
+        onGerritReady().then(() => {
+          const link = document.createElement('script');
+          link.setAttribute('type', 'module');
+          link.setAttribute('src', rule.destination);
+          link.setAttribute('crossorigin', 'anonymous');
+          document.head.appendChild(link);
+        });
       } else if (rule.operator === Operator.INJECT_JS_CODE) {
         const link = document.createElement('script');
         link.innerHTML = rule.destination;
diff --git a/src/manifest.json b/src/manifest.json
index 96ac1d6..978245c 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -2,7 +2,7 @@
   "manifest_version": 2,
   "name": "Gerrit FE Dev Helper",
   "description": "This extension can help you development on gerrit sites, frontend specifically",
-  "version": "0.0.6",
+  "version": "0.0.7",
   "browser_action": {
     "default_icon": "gray-32.png",
     "default_title": "Gerrit FE Dev Helper"
diff --git a/src/popup.ts b/src/popup.ts
index 4e5e473..1928597 100644
--- a/src/popup.ts
+++ b/src/popup.ts
@@ -279,6 +279,7 @@
     Operator.INJECT_HTML_PLUGIN,
     Operator.INJECT_HTML_CODE,
     Operator.INJECT_JS_PLUGIN,
+    Operator.INJECT_JS_MODULE_PLUGIN,
     Operator.INJECT_JS_CODE,
     Operator.ADD_REQUEST_HEADER,
     Operator.ADD_RESPONSE_HEADER,
diff --git a/src/utils.ts b/src/utils.ts
index 9283268..7cb4475 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -39,7 +39,7 @@
  */
 export function isInjectRule(rule: Rule) {
   return [
-    Operator.INJECT_JS_PLUGIN, Operator.INJECT_HTML_CODE,
+    Operator.INJECT_JS_MODULE_PLUGIN, Operator.INJECT_JS_PLUGIN, Operator.INJECT_HTML_CODE,
     Operator.INJECT_HTML_PLUGIN, Operator.INJECT_JS_CODE
   ].some(op => op === rule.operator);
 }
@@ -53,6 +53,7 @@
   INJECT_HTML_PLUGIN = 'injectHtmlPlugin',
   INJECT_HTML_CODE = 'injectHtmlCode',
   INJECT_JS_PLUGIN = 'injectJSPlugin',
+  INJECT_JS_MODULE_PLUGIN = 'injectJSModule',
   INJECT_JS_CODE = 'injectJSCode',
   REMOVE_RESPONSE_HEADER = 'rRespHeader',
   ADD_RESPONSE_HEADER = 'addRespHeader',