filterStyles: code cosmetics and a bug fix

This commit is contained in:
tophf 2017-09-03 18:16:00 +03:00
parent e69b6482b7
commit d843b4e23f

View File

@ -160,15 +160,16 @@ function filterStyles({
) {
return cachedStyles.list;
}
const blankHash = asHash && {
disableAll: prefs.get('disableAll'),
exposeIframes: prefs.get('exposeIframes'),
};
if (matchUrl && !URLS.supported(matchUrl)) {
return asHash ? {} : [];
}
const blankHash = asHash && {
disableAll: prefs.get('disableAll'),
exposeIframes: prefs.get('exposeIframes'),
};
// add \t after url to prevent collisions (not sure it can actually happen though)
const cacheKey = ' ' + enabled + url + '\t' + id + matchUrl + '\t' + asHash + strictRegexp;
const cached = cachedStyles.filters.get(cacheKey);
@ -216,8 +217,8 @@ function filterStylesInternal({
const styles = id === null
? cachedStyles.list
: [cachedStyles.byId.get(id)];
const filtered = asHash ? {} : [];
if (!styles) {
const filtered = asHash ? blankHash : [];
if (!styles[0]) {
// may happen when users [accidentally] reopen an old URL
// of edit.html with a non-existent style id parameter
return filtered;
@ -259,9 +260,7 @@ function filterStylesInternal({
cleanupCachedFilters();
}
return asHash
? Object.assign(blankHash, filtered)
: filtered;
return filtered;
}