issue 31 some small perf improvements

This commit is contained in:
Jason Barnabe 2012-06-01 23:11:32 -05:00
parent ed8abc7cc4
commit 7df28a58db
2 changed files with 16 additions and 45 deletions

View File

@ -29,7 +29,7 @@ function removeStyle(id) {
e.parentNode.removeChild(e); e.parentNode.removeChild(e);
} }
} }
function applyStyle(s) { function applyStyle(s) {
var style = document.createElement("style"); var style = document.createElement("style");
style.setAttribute("id", "stylish-" + s.id); style.setAttribute("id", "stylish-" + s.id);
@ -50,56 +50,27 @@ function filterSection(section) {
if (!section.urls && !section.urlPrefixes && !section.domains && !section.regexps) { if (!section.urls && !section.urlPrefixes && !section.domains && !section.regexps) {
return true; return true;
} }
if (section.urls) { if (section.urls && section.urls.some(function(url) {
var found = false; return url == location.href;
section.urls.forEach(function(url) { })) {
if (url == location.href) { return true;
found = true;
return;
}
});
if (found) {
return true;
}
} }
if (section.urlPrefixes) { if (section.urlPrefixes && section.urlPrefixes.some(function(urlPrefix) {
var found = false; return location.href.indexOf(urlPrefix) == 0;
section.urlPrefixes.forEach(function(urlPrefix) { })) {
if (location.href.indexOf(urlPrefix) == 0) { return true;
found = true;
return;
}
});
if (found) {
return true;
}
} }
if (section.domains) { if (section.domains) {
var found = false;
var currentDomains = getDomains(location.href); var currentDomains = getDomains(location.href);
section.domains.forEach(function(domain) { if (section.domains.some(function(domain) {
if (currentDomains.indexOf(domain) >= 0) { return currentDomains.indexOf(domain) >= 0;
found = true; })) {
return;
}
});
if (found) {
return true; return true;
} }
} }
if (section.regexps) { return section.regexps && section.regexps.some(function(regexp) {
var found = false; return (new RegExp(regexp)).test(location.href);
section.regexps.forEach(function(regexp) { });
if ((new RegExp(regexp)).test(location.href)) {
found = true;
return;
}
});
if (found) {
return true;
}
}
return false;
} }
function getDomains(url) { function getDomains(url) {

View File

@ -2,8 +2,8 @@ chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
switch (request.name) { switch (request.name) {
case "getStylesToApply": case "getStylesToApply":
getStyles({matchUrl: sender.tab.url, enabled: true}, function(r) { getStyles({matchUrl: sender.tab.url, enabled: true}, function(r) {
chrome.browserAction.setBadgeText({text: getBadgeText(r), tabId: sender.tab.id});
sendResponse(r); sendResponse(r);
chrome.browserAction.setBadgeText({text: getBadgeText(r), tabId: sender.tab.id});
}); });
break; break;
case "getStylesForUrl": case "getStylesForUrl":