Various performance improvements

This commit is contained in:
Jason 2016-03-19 16:58:01 -05:00
parent 6dcbf1bef8
commit fa97a94494
3 changed files with 39 additions and 31 deletions

View File

@ -153,6 +153,12 @@
</div>
</template>
<template data-id="styleHomepage">
<a target="_blank">
<img src="world_go.png" alt="*">
</a>
</template>
<script src="localization.js"></script>
<script src="health.js"></script>
<script src="storage.js"></script>

View File

@ -44,13 +44,8 @@ function createStyleElement(style) {
var styleName = e.querySelector(".style-name");
styleName.appendChild(document.createTextNode(style.name));
if (style.url) {
var homepage = document.createElement("a");
var homepage = template.styleHomepage.cloneNode(true)
homepage.setAttribute("href", style.url);
homepage.setAttribute("target", "_blank");
var homepageImg = document.createElement("img");
homepageImg.src = "world_go.png";
homepageImg.alt = "*";
homepage.appendChild(homepageImg);
styleName.appendChild(document.createTextNode(" " ));
styleName.appendChild(homepage);
}

View File

@ -36,38 +36,45 @@ function getStyles(options, callback) {
}, null);
}
function filterStyles(unfilteredStyles, options) {
function filterStyles(styles, options) {
var enabled = fixBoolean(options.enabled);
var url = "url" in options ? options.url : null;
var id = "id" in options ? Number(options.id) : null;
var matchUrl = "matchUrl" in options ? options.matchUrl : null;
// Return as a hash from style to applicable sections? Can only be used with matchUrl.
var asHash = "asHash" in options ? options.asHash : false;
var styles = asHash ? {disableAll: prefs.get("disableAll", false)} : [];
unfilteredStyles.forEach(function(style) {
if (enabled != null && style.enabled != enabled) {
return;
if (enabled != null) {
styles = styles.filter(function(style) {
return style.enabled != enabled;
});
}
if (url != null && style.url != url) {
return;
if (url != null) {
styles = styles.filter(function(style) {
return style.url != url;
});
}
if (id != null && style.id != id) {
return;
if (id != null) {
styles = styles.filter(function(style) {
return style.id != id;
});
}
if (matchUrl != null) {
// Return as a hash from style to applicable sections? Can only be used with matchUrl.
var asHash = "asHash" in options ? options.asHash : false;
if (asHash) {
var h = {disableAll: prefs.get("disableAll", false)};
styles.forEach(function(style) {
var applicableSections = getApplicableSections(style, matchUrl);
if (applicableSections.length > 0) {
if (asHash) {
styles[style.id] = applicableSections;
} else {
styles.push(style)
}
}
} else {
styles.push(style);
h[style.id] = applicableSections;
}
});
return h;
}
styles = styles.filter(function(style) {
var applicableSections = getApplicableSections(style, matchUrl);
return applicableSections.length > 0;
});
}
return styles;
}