New message styleReplaceAll

`styleReplaceAll` removes all existing user styles, then applies the styles in the message payload.
This commit is contained in:
hideheader 2015-02-23 00:14:22 -05:00
parent 99968395d9
commit c67c9d3f54

View File

@ -17,6 +17,10 @@ chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
for (var styleId in request.styles) { for (var styleId in request.styles) {
applySections(styleId, request.styles[styleId]); applySections(styleId, request.styles[styleId]);
} }
break;
case "styleReplaceAll":
replaceAll(request.styles);
break;
} }
}); });
@ -54,3 +58,10 @@ function applySections(styleId, sections) {
}).join("\n"))); }).join("\n")));
document.documentElement.appendChild(styleElement); document.documentElement.appendChild(styleElement);
} }
function replaceAll(newStyles) {
Array.prototype.forEach.call(document.querySelectorAll("STYLE.stylish"), function(style) {
style.parentNode.removeChild(style);
});
applyStyles(newStyles);
}