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> </div>
</template> </template>
<template data-id="styleHomepage">
<a target="_blank">
<img src="world_go.png" alt="*">
</a>
</template>
<script src="localization.js"></script> <script src="localization.js"></script>
<script src="health.js"></script> <script src="health.js"></script>
<script src="storage.js"></script> <script src="storage.js"></script>

View File

@ -44,13 +44,8 @@ function createStyleElement(style) {
var styleName = e.querySelector(".style-name"); var styleName = e.querySelector(".style-name");
styleName.appendChild(document.createTextNode(style.name)); styleName.appendChild(document.createTextNode(style.name));
if (style.url) { if (style.url) {
var homepage = document.createElement("a"); var homepage = template.styleHomepage.cloneNode(true)
homepage.setAttribute("href", style.url); 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(document.createTextNode(" " ));
styleName.appendChild(homepage); styleName.appendChild(homepage);
} }

View File

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