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
31 changes: 29 additions & 2 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@
return {mime: mime, file: file};
};

var handleRequest = function(requestUrl, tabUrl, tabId) {
var handleRequest = function(requestUrl, tabUrl, tabId, statusCode) {
for (var key in ruleDomains) {
var domainObj = ruleDomains[key];
if (domainObj.on && match(domainObj.matchUrl, tabUrl).matched) {
var rules = domainObj.rules || [];
for (var x = 0, len = rules.length; x < len; ++x) {
var ruleObj = rules[x];
if (ruleObj.on) {
if (ruleObj.type === "normalOverride") {
if (ruleObj.type === "normalOverride" && (typeof ruleObj.all === "undefined" || ruleObj.all === true || (statusCode === 404))) {
var matchedObj = match(ruleObj.match, requestUrl);
var newUrl = matchReplace(matchedObj, ruleObj.replace, requestUrl);
if (matchedObj.matched) {
Expand Down Expand Up @@ -469,6 +469,7 @@
}
if (tabUrl) {
var result = handleRequest(details.url, tabUrl, details.tabId);
//If result (obj), if has a redirect url key within it
if (result) {
// make sure we don't try to redirect again.
requestIdTracker.push(details.requestId);
Expand All @@ -489,6 +490,32 @@
urls: ["<all_urls>"]
}, ["blocking", "requestHeaders"]);

chrome.webRequest.onHeadersReceived.addListener(
function(details){
if(details.statusCode===404){
if (!requestIdTracker.has(details.requestId)) {
if (details.tabId > -1) {
var tabUrl = tabUrlTracker.getUrlFromId(details.tabId);
if (details.type === "main_frame") {
// a new tab must have just been created.
tabUrl = details.url;
}
if (tabUrl) {
var result = handleRequest(details.url, tabUrl, details.tabId, details.statusCode);
//If result (obj), if has a redirect url key within it
if (result) {
// make sure we don't try to redirect again.
requestIdTracker.push(details.requestId);
}
return result;
}
}
}
}
}, {
urls: ["<all_urls>"]
}, ["blocking", "responseHeaders"]);

//init settings
if (localStorage.devTools === undefined) {
localStorage.devTools = "true";
Expand Down
4 changes: 2 additions & 2 deletions src/ui/css/on-off-switch.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ https://proto.io/freebies/onoff/
background: #FFFFFF;
border: 2px solid #999999; border-radius: 5px;
position: absolute; top: 0; bottom: 0; right: 46px;
-moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
-moz-transition: all .3s ease-in 0s; -webkit-transition: all .3s ease-in 0s;
-o-transition: all .3s ease-in 0s; transition: all .3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
Expand Down
5 changes: 4 additions & 1 deletion src/ui/devtoolstab.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
</label>
</div>
</template>

<template id="domainTemplate">
<div class="domainContainer">
<div class="domainHeader">
Expand Down Expand Up @@ -64,9 +63,13 @@
<div class="rule">
<input type="input" class="replaceInput" placeholder="Replace URL">
</div>
<div class="switch">
<on-off-switch class="allOr404Only" onText="All" offText="404s"></on-off-switch>
</div>
<div class="switch">
<on-off-switch class="ruleOnOff"></on-off-switch>
</div>

<div class="delete">
<button class="btn sym-btn">&#215</button>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/ui/onOffSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
document.registerElement("on-off-switch", {
prototype: Object.create(HTMLElement.prototype, {
createdCallback: {

value: function() {
this.createShadowRoot().appendChild(document.importNode(
ui.onOffSwitchTemplate[0].content, true));
Expand Down
3 changes: 2 additions & 1 deletion src/ui/tabGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
type: "normalOverride",
match: $el.find(".matchInput").val(),
replace: $el.find(".replaceInput").val(),
on: $el.find(".ruleOnOff")[0].isOn
on: $el.find(".ruleOnOff")[0].isOn,
all:$el.find(".allOr404Only")[0].isOn
});
} else if ($el.hasClass("fileOverride")) {
rules.push({
Expand Down
6 changes: 6 additions & 0 deletions src/ui/webRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
const matchInput = override.find(".matchInput");
const replaceInput = override.find(".replaceInput");
const ruleOnOff = override.find(".ruleOnOff");
const allOr404Only = override.find(".allOr404Only");
const deleteBtn = override.find(".sym-btn");

matchInput.val(savedData.match || "");
replaceInput.val(savedData.replace || "");
util.makeFieldRequired(matchInput);
util.makeFieldRequired(replaceInput);
ruleOnOff[0].isOn = savedData.on === false ? false : true;
allOr404Only[0].isOn = savedData.all === false ? false : true;

if (savedData.on === false) {
override.addClass("disabled");
Expand Down Expand Up @@ -49,6 +51,10 @@
override.toggleClass("disabled", !ruleOnOff[0].isOn);
saveFunc();
});
allOr404Only.on("click change", function() {
override.toggleClass("disabled", !allOr404Only[0].isOn);
saveFunc();
});

return override;
}
Expand Down