issue 31 some small perf improvements
This commit is contained in:
parent
ed8abc7cc4
commit
7df28a58db
57
apply.js
57
apply.js
|
@ -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) {
|
||||||
|
|
|
@ -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":
|
||||||
|
|
Loading…
Reference in New Issue
Block a user