From 07d3cdda403fc21a609ad51b4054d591663126d1 Mon Sep 17 00:00:00 2001 From: Jason Barnabe Date: Thu, 29 Jan 2015 21:32:14 -0600 Subject: [PATCH] Switch to Linux line endings --- apply.js | 110 +++++++++++++++++++++++++++---------------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/apply.js b/apply.js index 6f788a09..f4fb52a0 100644 --- a/apply.js +++ b/apply.js @@ -1,55 +1,55 @@ -chrome.extension.sendMessage({method: "getStyles", matchUrl: location.href, enabled: true, updateBadge: window == window.top}, function(response) { - response.forEach(applyStyle); -}); - -chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { - switch(request.name) { - case "styleDeleted": - removeStyle(request.id); - break; - case "styleUpdated": - removeStyle(request.style.id); - //fallthrough - case "styleAdded": - if (request.style.enabled == "true") { - applyStyle(request.style); - } - } -}); - -function removeStyle(id) { - var e = document.getElementById("stylish-" + id); - if (e) { - e.parentNode.removeChild(e); - } -} - -function applyStyle(s) { - chrome.extension.sendMessage({method: "getStyleApplies", style: s, url: location.href}, function(response) { - if (response && response.length > 0) { - applySections(s, response); - } - }); -} - -function applySections(style, sections) { - var styleElement; - if (document.documentElement instanceof SVGSVGElement) { - // SVG document, make an SVG style element. - styleElement = document.createElementNS("http://www.w3.org/2000/svg", "style"); - } else { - // This will make an HTML style element. If there's SVG embedded in an HTML document, this works on the SVG too. - styleElement = document.createElement("style"); - } - styleElement.setAttribute("id", "stylish-" + style.id); - styleElement.setAttribute("class", "stylish"); - styleElement.setAttribute("type", "text/css"); - styleElement.appendChild(document.createTextNode(sections.map(function(section) { - return section.code; - }).join("\n"))); - if (document.head) { - document.head.appendChild(styleElement); - } else { - document.documentElement.appendChild(styleElement); - } -} +chrome.extension.sendMessage({method: "getStyles", matchUrl: location.href, enabled: true, updateBadge: window == window.top}, function(response) { + response.forEach(applyStyle); +}); + +chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { + switch(request.name) { + case "styleDeleted": + removeStyle(request.id); + break; + case "styleUpdated": + removeStyle(request.style.id); + //fallthrough + case "styleAdded": + if (request.style.enabled == "true") { + applyStyle(request.style); + } + } +}); + +function removeStyle(id) { + var e = document.getElementById("stylish-" + id); + if (e) { + e.parentNode.removeChild(e); + } +} + +function applyStyle(s) { + chrome.extension.sendMessage({method: "getStyleApplies", style: s, url: location.href}, function(response) { + if (response && response.length > 0) { + applySections(s, response); + } + }); +} + +function applySections(style, sections) { + var styleElement; + if (document.documentElement instanceof SVGSVGElement) { + // SVG document, make an SVG style element. + styleElement = document.createElementNS("http://www.w3.org/2000/svg", "style"); + } else { + // This will make an HTML style element. If there's SVG embedded in an HTML document, this works on the SVG too. + styleElement = document.createElement("style"); + } + styleElement.setAttribute("id", "stylish-" + style.id); + styleElement.setAttribute("class", "stylish"); + styleElement.setAttribute("type", "text/css"); + styleElement.appendChild(document.createTextNode(sections.map(function(section) { + return section.code; + }).join("\n"))); + if (document.head) { + document.head.appendChild(styleElement); + } else { + document.documentElement.appendChild(styleElement); + } +}