From c67c9d3f54b5cc7a0cccedbc79f865336f7fb390 Mon Sep 17 00:00:00 2001 From: hideheader Date: Mon, 23 Feb 2015 00:14:22 -0500 Subject: [PATCH] New message `styleReplaceAll` `styleReplaceAll` removes all existing user styles, then applies the styles in the message payload. --- apply.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apply.js b/apply.js index cba52c65..cd8bf82c 100644 --- a/apply.js +++ b/apply.js @@ -17,6 +17,10 @@ chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { for (var styleId in request.styles) { applySections(styleId, request.styles[styleId]); } + break; + case "styleReplaceAll": + replaceAll(request.styles); + break; } }); @@ -54,3 +58,10 @@ function applySections(styleId, sections) { }).join("\n"))); document.documentElement.appendChild(styleElement); } + +function replaceAll(newStyles) { + Array.prototype.forEach.call(document.querySelectorAll("STYLE.stylish"), function(style) { + style.parentNode.removeChild(style); + }); + applyStyles(newStyles); +}