Various performance improvements
This commit is contained in:
parent
6dcbf1bef8
commit
fa97a94494
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
57
storage.js
57
storage.js
|
@ -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 (url != null && style.url != url) {
|
||||
return;
|
||||
}
|
||||
if (id != null && style.id != id) {
|
||||
return;
|
||||
}
|
||||
if (matchUrl != null) {
|
||||
var applicableSections = getApplicableSections(style, matchUrl);
|
||||
if (applicableSections.length > 0) {
|
||||
if (asHash) {
|
||||
styles[style.id] = applicableSections;
|
||||
} else {
|
||||
styles.push(style)
|
||||
if (enabled != null) {
|
||||
styles = styles.filter(function(style) {
|
||||
return style.enabled != enabled;
|
||||
});
|
||||
}
|
||||
if (url != null) {
|
||||
styles = styles.filter(function(style) {
|
||||
return style.url != url;
|
||||
});
|
||||
}
|
||||
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) {
|
||||
h[style.id] = applicableSections;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
styles.push(style);
|
||||
});
|
||||
return h;
|
||||
}
|
||||
});
|
||||
styles = styles.filter(function(style) {
|
||||
var applicableSections = getApplicableSections(style, matchUrl);
|
||||
return applicableSections.length > 0;
|
||||
});
|
||||
}
|
||||
return styles;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user