Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle multiple matches #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
17 changes: 10 additions & 7 deletions chrome/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,26 @@ function getServers() {
* @return Object
*/
function getBackend(request) {
var routes = getRoutes();
var matches = [],
routes = getRoutes();

for (var i = 0; i < routes.length; i++) {
var route = routes[i];
if (!route.match.test(request.url)) {
continue;
}
var servers = getServers();
for (i = 0; i < servers.length; i++) {
if (servers[i].id === route.id) {
return {
serverURL: servers[i].url,
for (var j = 0; j < servers.length; j++) {
if (servers[j].id === route.id) {
matches.push({
serverURL: servers[j].url,
savePath: urlToPath(request.url.replace(route.match, route.savePath))
};
});
}
}
}
return null;

return (matches.length === 0 ? null : {matches: matches});
}

/**
Expand Down
31 changes: 20 additions & 11 deletions chrome/devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ chrome.devtools.inspectedWindow.onResourceContentCommitted.addListener(function(

function sendToBackgroundPage() {
var patch;

if (isNewlyAdded(event)) {
console.info('New CSS rules added. Appending them to', lastStylesheetURL);
var oldAddedCSS = addedCSS;
Expand All @@ -99,17 +100,25 @@ chrome.devtools.inspectedWindow.onResourceContentCommitted.addListener(function(
return;
}

chrome.extension.sendRequest({
method: 'send',
content: JSON.stringify(patch),
url: response.serverURL,
headers: {
'Content-Type': 'application/json',
'X-URL': url,
'X-Path': response.savePath,
'X-Type': event.type
}
});
if(!response.matches) {
response.matches = [];
response.matches.push(response);
}

for (var i=0; i<response.matches.length; i++) {
var match = response.matches[i];
chrome.extension.sendRequest({
method: 'send',
content: JSON.stringify(patch),
url: match.serverURL,
headers: {
'Content-Type': 'application/json',
'X-URL': url,
'X-Path': match.savePath,
'X-Type': event.type
}
});
}
}
});
}
Expand Down
4 changes: 3 additions & 1 deletion chrome/manifest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"name": "DevTools Autosave",
"version": "1.2.2",
"version": "1.2.3",
"description": "Saves changes in CSS and JS that was made via Chrome DevTools",

"devtools_page": "devtools.html",

"background": {
"scripts": ["background.js"]
},

"options_page": "options.html",

"icons": {
Expand Down