Switch to Linux line endings

This commit is contained in:
Jason Barnabe 2015-01-29 21:32:14 -06:00
parent 89c1dc6bf9
commit 07d3cdda40

110
apply.js
View File

@ -1,55 +1,55 @@
chrome.extension.sendMessage({method: "getStyles", matchUrl: location.href, enabled: true, updateBadge: window == window.top}, function(response) { chrome.extension.sendMessage({method: "getStyles", matchUrl: location.href, enabled: true, updateBadge: window == window.top}, function(response) {
response.forEach(applyStyle); response.forEach(applyStyle);
}); });
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
switch(request.name) { switch(request.name) {
case "styleDeleted": case "styleDeleted":
removeStyle(request.id); removeStyle(request.id);
break; break;
case "styleUpdated": case "styleUpdated":
removeStyle(request.style.id); removeStyle(request.style.id);
//fallthrough //fallthrough
case "styleAdded": case "styleAdded":
if (request.style.enabled == "true") { if (request.style.enabled == "true") {
applyStyle(request.style); applyStyle(request.style);
} }
} }
}); });
function removeStyle(id) { function removeStyle(id) {
var e = document.getElementById("stylish-" + id); var e = document.getElementById("stylish-" + id);
if (e) { if (e) {
e.parentNode.removeChild(e); e.parentNode.removeChild(e);
} }
} }
function applyStyle(s) { function applyStyle(s) {
chrome.extension.sendMessage({method: "getStyleApplies", style: s, url: location.href}, function(response) { chrome.extension.sendMessage({method: "getStyleApplies", style: s, url: location.href}, function(response) {
if (response && response.length > 0) { if (response && response.length > 0) {
applySections(s, response); applySections(s, response);
} }
}); });
} }
function applySections(style, sections) { function applySections(style, sections) {
var styleElement; var styleElement;
if (document.documentElement instanceof SVGSVGElement) { if (document.documentElement instanceof SVGSVGElement) {
// SVG document, make an SVG style element. // SVG document, make an SVG style element.
styleElement = document.createElementNS("http://www.w3.org/2000/svg", "style"); styleElement = document.createElementNS("http://www.w3.org/2000/svg", "style");
} else { } else {
// This will make an HTML style element. If there's SVG embedded in an HTML document, this works on the SVG too. // 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 = document.createElement("style");
} }
styleElement.setAttribute("id", "stylish-" + style.id); styleElement.setAttribute("id", "stylish-" + style.id);
styleElement.setAttribute("class", "stylish"); styleElement.setAttribute("class", "stylish");
styleElement.setAttribute("type", "text/css"); styleElement.setAttribute("type", "text/css");
styleElement.appendChild(document.createTextNode(sections.map(function(section) { styleElement.appendChild(document.createTextNode(sections.map(function(section) {
return section.code; return section.code;
}).join("\n"))); }).join("\n")));
if (document.head) { if (document.head) {
document.head.appendChild(styleElement); document.head.appendChild(styleElement);
} else { } else {
document.documentElement.appendChild(styleElement); document.documentElement.appendChild(styleElement);
} }
} }