Skip to content
Snippets Groups Projects
Commit 370e26b6 authored by BERTHAUT Florent's avatar BERTHAUT Florent
Browse files

First working CSS changes

parent a572ffc3
No related branches found
No related tags found
No related merge requests found
// background.js
let css = "";
//Initialize the CSS storage on startup
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.sync.set({css});
});
......@@ -5,6 +5,8 @@ editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/css");
//When the CSS editor changes, store it in the shared storage
//and call the background parseCSS script
editor.getSession().on('change', function() {
chrome.tabs.query({ active: true, currentWindow: true },
function(tabs) {
......@@ -20,25 +22,32 @@ editor.getSession().on('change', function() {
function parseCSS() {
console.log("Parsing CSS");
//get access to the main document
//Get access to the css written in the popup
chrome.storage.sync.get("css", function(cssObj) {
//Split the rules
let rules = cssObj.css.split("}");
for(let r of rules) {
console.log(r);
//Test if not empty
if(r.search(/[\w]+/i)>=0) {
//Retrieve the selector
let sel = r.split("{")[0];
if(sel.search(/ */i)<0) {
console.log("Selector ", sel);
//Retrieve the corresponding elements
let els = document.querySelectorAll(sel);
for(let e of els) {
console.log(e.innerHTML);
//Apply the properties to each
//TEMP, just put the background color in blue
e.style["background-color"] = "blue";
}
}
}
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment