v0.0.8
Change-Id: Ifaf25aebb399c286c5857a799b1ff87de6649784
diff --git a/release-notes.md b/release-notes.md
index 6f06654..4a17cf3 100644
--- a/release-notes.md
+++ b/release-notes.md
@@ -1,6 +1,8 @@
-#### next release
+#### v0.0.8
-- Add addRespHeader operator, thanks to Edward <ehmaldonado@google.com>
+- **BREAKING CHNAGE**: Gerrit is moving to `gr-app.js` only, so `gr-app.html` will no longer exists, we have updated default rules to forward to `gr-app.js` as well, in case you are still using `gr-app.html`, please modify that redirect rule by changing `gr-app.js` to `gr-app.html`
+- Add `addRespHeader` operator, thanks to Edward <ehmaldonado@google.com>
+- Add `injectExp` operator, as gerrit now supports experiments, this is a quick way to force enabling certain experiments, experiments should be separated by `,`
#### v0.0.7
diff --git a/src/content_script.ts b/src/content_script.ts
index 5d196dc..7e3071a 100644
--- a/src/content_script.ts
+++ b/src/content_script.ts
@@ -1,4 +1,10 @@
-import { isInjectRule, Operator, Rule } from './utils';
+import { isInjectRule, Operator, Rule, getUrlParameter } from './utils';
+
+declare global {
+ interface Window {
+ ENABLED_EXPERIMENGTS?: string[];
+ }
+}
function nextTick(ts: number) {
return new Promise(resolve => {
@@ -80,16 +86,24 @@
const link = document.createElement('script');
link.innerHTML = rule.destination;
document.head.appendChild(link);
+ } else if (rule.operator === Operator.INJECT_EXP) {
+ const exps = getUrlParameter('experiment');
+ const hasSeachString = !!window.location.search;
+ const injectedExpNotInExps = new Set(rule.destination.trim().split(',').filter(exp => !exps.includes(exp.trim())));
+ if (injectedExpNotInExps.size) {
+ const addedParams = [...injectedExpNotInExps].reduce((str, exp) => str += `experiment=${exp}&`, '');
+ window.location.href += hasSeachString ? `&${addedParams}` : `?${addedParams}`;
+ }
}
});
// test redirect rules
rules.filter(rule => !isInjectRule(rule)).forEach(rule => {
if (rule.operator === Operator.REDIRECT
- && !rule.disabled
- // only test for js/html
- && /\.(js|html)+$/.test(rule.destination)
- ) {
+ && !rule.disabled
+ // only test for js/html
+ && /\.(js|html)+$/.test(rule.destination)
+ ) {
fetch(rule.destination).then(res => {
if (res.status < 200 || res.status >= 300) throw new Error("Resource not found");
}).catch(e => {
diff --git a/src/manifest.json b/src/manifest.json
index 978245c..ab7599d 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.7",
+ "version": "0.0.8",
"browser_action": {
"default_icon": "gray-32.png",
"default_title": "Gerrit FE Dev Helper"
diff --git a/src/popup.ts b/src/popup.ts
index 1928597..653c049 100644
--- a/src/popup.ts
+++ b/src/popup.ts
@@ -281,6 +281,7 @@
Operator.INJECT_JS_PLUGIN,
Operator.INJECT_JS_MODULE_PLUGIN,
Operator.INJECT_JS_CODE,
+ Operator.INJECT_EXP,
Operator.ADD_REQUEST_HEADER,
Operator.ADD_RESPONSE_HEADER,
Operator.REMOVE_RESPONSE_HEADER,
diff --git a/src/utils.ts b/src/utils.ts
index 7cb4475..9d3ff96 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -40,7 +40,7 @@
export function isInjectRule(rule: Rule) {
return [
Operator.INJECT_JS_MODULE_PLUGIN, Operator.INJECT_JS_PLUGIN, Operator.INJECT_HTML_CODE,
- Operator.INJECT_HTML_PLUGIN, Operator.INJECT_JS_CODE
+ Operator.INJECT_HTML_PLUGIN, Operator.INJECT_JS_CODE, Operator.INJECT_EXP
].some(op => op === rule.operator);
}
@@ -58,6 +58,7 @@
REMOVE_RESPONSE_HEADER = 'rRespHeader',
ADD_RESPONSE_HEADER = 'addRespHeader',
ADD_REQUEST_HEADER = 'addReqHeader',
+ INJECT_EXP = 'injectExp',
}
/**
@@ -69,4 +70,20 @@
operator: Operator;
destination: string;
isNew?: boolean;
+}
+
+/**
+ * Util to get url parameters
+ */
+export function getUrlParameter(param: string) {
+ const qs = window.location.search.substring(1);
+ const partials = qs.split('&');
+ const res = [];
+ for (let i = 0; i < partials.length; i++) {
+ const name = partials[i].split('=');
+ if (name[0] == param) {
+ res.push(name[1]);
+ }
+ }
+ return res;
}
\ No newline at end of file