Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,31 @@ function rewriteResponseHeader(e) {
if (config.debug_mode) log("cookie_delete.resp delete_header : name=" + to_modify.header_name + " for url " + e.url);
}
}
else if (to_modify.action === "replace_value") {
for (let header of e.responseHeaders) {
if (header.name.toLowerCase() === to_modify.header_name.toLowerCase()) {
let replacePattern = to_modify.header_value;
let originalValue = header.value;

let match = replacePattern.match(/\((.*?)\)\((.*?)\)/);
let searchString = match[1]; // What to search for in the original value
let replaceString = match[2]; // What to replace with in the original value, to create the new value

let regex = new RegExp(searchString, "g");
let newValue = originalValue.replace(regex, replaceString);

if (config.debug_mode) log(
"Replace value in response header : name= " + to_modify.header_name +
",old value=" + originalValue +
",replace pattern=" + replacePattern +
",new value=" + newValue +
" for url " + e.url
);

header.value = newValue;
}
}
}
}
}
if (config.debug_mode) log("End modify response headers for url " + e.url);
Expand Down
1 change: 1 addition & 0 deletions popup/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function appendLine(url_contains,action,header_name,header_value,comment,apply_o
<option value="delete">Delete</option>
<option value="cookie_add_or_modify">Cookie Add/Modify</option>
<option value="cookie_delete">Cookie Delete</option>
<option value="replace_value">Replace String In Response Value</option>
</select>
</td>
<td>
Expand Down