diff --git a/content.js b/content.js
index 62db428fa881d6921730007619e448f988a0a3b8..66716a24d7a1b62ff166eb999d2ca8fb5ad17564 100644
--- a/content.js
+++ b/content.js
@@ -538,6 +538,21 @@ function audioEvent() {
}
}
+function pureCss() {
+ chrome.storage.sync.get(['all'], function (result) {
+ result.all.forEach(element => {
+ element.templates.forEach(template => {
+ if (template.type == 'pure') {
+ let els = document.querySelectorAll(element.element);
+ els.forEach(e => {
+ e.style[element.property] = element.value;
+ });
+ }
+ });
+ });
+ });
+}
+
/**
* Function trigger when new message received.
* @param {type, data} message parameters
@@ -546,16 +561,13 @@ function onMessage({ type, data }) {
console.info('Message received from CSSLSD back :', type);
switch (type) {
case 'update': {
- const css = data.cssStr;
- audioEvents = [];
- midiEvents = [];
- // parseCSS(css)
+ pureCss();
break;
}
case 'start': {
chrome.storage.sync.get(['activate'], function (result) {
if (result.activate) {
- // zzz
+ pureCss();
}
else {
audioApi();
diff --git a/main.js b/main.js
index 621a9b959d611cf4a0708583e89937a853e51be7..6f8f1269f6e41a36f59dbf380d71f502544f7438 100644
--- a/main.js
+++ b/main.js
@@ -99,7 +99,7 @@ function initUi() {
tbl_row += "<td contenteditable>" + p[index] + "</td>";
}
- tbl_body += "<tr class=\"" + (odd_even ? "odd" : "even") + "\"><td>" + icon + plus + minus+"</td>" + tbl_row + "</tr>";
+ tbl_body += "<tr class=\"" + (odd_even ? "odd" : "even") + "\"><td>" + icon + plus + minus + "</td>" + tbl_row + "</tr>";
odd_even = !odd_even;
});
$("#parameters").html('');
@@ -137,82 +137,96 @@ function analyseAll() {
var all = [];
var parser = new CSSParser();
var sheet = parser.parse(result.css, false, false);
- console.log(sheet.cssRules);
sheet.cssRules.forEach(element => {
element.declarations.forEach(css => {
var templates = [];
cssValue = css.valueText;
- for (let index = 0; index < css.valueText.split("[").length - 1; index++) {
- template = cssValue.substring(
- cssValue.indexOf("[") + 1,
- cssValue.indexOf("]")
- );
- cssValue = cssValue.replace("[" + template + "]", "");
- var parameters = JSON.parse(result.parameters);
- parameters.forEach(p => {
- templateSplited = template.split(' ');
- if (p[1] == templateSplited[0]) {
- if (p[4] != "") {
- p[4].split(' ').forEach(midiE => {
- var obj = {
- type: '',
- name: templateSplited[0],
- templateFull: template,
- eventType: '',
- eventName: '',
- options: '',
- array: templateSplited.length > 1 ? (templateSplited[1].includes(';') ? templateSplited[1].split(';') : '') : '',
- min: templateSplited.length > 1 ? (templateSplited[1].includes(':') ? templateSplited[1].split(':')[0] : '') : '',
- max: templateSplited.length > 1 ? (templateSplited[1].includes(':') ? templateSplited[1].split(':')[1] : '') : '',
- }
- obj.type = 'midi';
- if (midiE.includes(':')) {
- obj.eventType = midiE.split(':')[0];
- obj.eventName = midiE.split(':')[1];
- }
- else {
- obj.eventType = midiE;
- obj.eventName = '';
- }
- obj.options = p[3];
- obj.array = ((obj.array == '') ? (p[2].includes(';') ? p[2].split(';') : '') : obj.array);
- obj.min = ((obj.min == '') ? (p[2].includes(':') ? p[2].split(':')[0] : 0) : obj.min);
- obj.max = ((obj.max == '') ? (p[2].includes(':') ? p[2].split(':')[1] : 1) : obj.max);
- templates.push(obj);
- });
+ count = css.valueText.split("[").length;
+ if (count > 1) {
+ for (let index = 0; index < count - 1; index++) {
+ template = cssValue.substring(
+ cssValue.indexOf("[") + 1,
+ cssValue.indexOf("]")
+ );
+ cssValue = cssValue.replace("[" + template + "]", "");
+ var parameters = JSON.parse(result.parameters);
+ parameters.forEach(p => {
+ templateSplited = template.split(' ');
+ if (p[1] == templateSplited[0]) {
+ if (p[4] != "") {
+ p[4].split(' ').forEach(midiE => {
+ var obj = {
+ type: '',
+ name: templateSplited[0],
+ templateFull: template,
+ eventType: '',
+ eventName: '',
+ options: '',
+ array: templateSplited.length > 1 ? (templateSplited[1].includes(';') ? templateSplited[1].split(';') : '') : '',
+ min: templateSplited.length > 1 ? (templateSplited[1].includes(':') ? templateSplited[1].split(':')[0] : '') : '',
+ max: templateSplited.length > 1 ? (templateSplited[1].includes(':') ? templateSplited[1].split(':')[1] : '') : '',
+ }
+ obj.type = 'midi';
+ if (midiE.includes(':')) {
+ obj.eventType = midiE.split(':')[0];
+ obj.eventName = midiE.split(':')[1];
+ }
+ else {
+ obj.eventType = midiE;
+ obj.eventName = '';
+ }
+ obj.options = p[3];
+ obj.array = ((obj.array == '') ? (p[2].includes(';') ? p[2].split(';') : '') : obj.array);
+ obj.min = ((obj.min == '') ? (p[2].includes(':') ? p[2].split(':')[0] : 0) : obj.min);
+ obj.max = ((obj.max == '') ? (p[2].includes(':') ? p[2].split(':')[1] : 1) : obj.max);
+ templates.push(obj);
+ });
+ }
+ if (p[5] != "") {
+ p[5].split(' ').forEach(audioE => {
+ var obj = {
+ type: '',
+ name: templateSplited[0],
+ templateFull: template,
+ eventType: '',
+ eventName: '',
+ options: '',
+ array: templateSplited.length > 1 ? (templateSplited[1].includes(';') ? templateSplited[1].split(';') : '') : '',
+ min: templateSplited.length > 1 ? (templateSplited[1].includes(':') ? templateSplited[1].split(':')[0] : '') : '',
+ max: templateSplited.length > 1 ? (templateSplited[1].includes(':') ? templateSplited[1].split(':')[1] : '') : '',
+ }
+ obj.type = 'audio';
+ if (audioE.includes(':')) {
+ obj.eventType = audioE.split(':')[0];
+ obj.eventName = audioE.split(':')[1];
+ }
+ else {
+ obj.eventType = audioE;
+ obj.eventName = '';
+ }
+ obj.options = p[3];
+ obj.array = ((obj.array == '') ? (p[2].includes(';') ? p[2].split(';') : '') : obj.array);
+ obj.min = ((obj.min == '') ? (p[2].includes(':') ? p[2].split(':')[0] : 0) : obj.min);
+ obj.max = ((obj.max == '') ? (p[2].includes(':') ? p[2].split(':')[1] : 1) : obj.max);
+ templates.push(obj);
+ });
+ }
}
- if (p[5] != "") {
- p[5].split(' ').forEach(audioE => {
- var obj = {
- type: '',
- name: templateSplited[0],
- templateFull: template,
- eventType: '',
- eventName: '',
- options: '',
- array: templateSplited.length > 1 ? (templateSplited[1].includes(';') ? templateSplited[1].split(';') : '') : '',
- min: templateSplited.length > 1 ? (templateSplited[1].includes(':') ? templateSplited[1].split(':')[0] : '') : '',
- max: templateSplited.length > 1 ? (templateSplited[1].includes(':') ? templateSplited[1].split(':')[1] : '') : '',
- }
- obj.type = 'audio';
- if (audioE.includes(':')) {
- obj.eventType = audioE.split(':')[0];
- obj.eventName = audioE.split(':')[1];
- }
- else {
- obj.eventType = audioE;
- obj.eventName = '';
- }
- obj.options = p[3];
- obj.array = ((obj.array == '') ? (p[2].includes(';') ? p[2].split(';') : '') : obj.array);
- obj.min = ((obj.min == '') ? (p[2].includes(':') ? p[2].split(':')[0] : 0) : obj.min);
- obj.max = ((obj.max == '') ? (p[2].includes(':') ? p[2].split(':')[1] : 1) : obj.max);
- templates.push(obj);
- });
- }
- }
- });
+ });
+ }
+ } else {
+ templates.push({
+ type: 'pure',
+ name: '',
+ templateFull: '',
+ eventType: '',
+ eventName: '',
+ options: '',
+ array: '',
+ min: '',
+ max: '',
+ });
}
all.push({
element: element.mSelectorText,
@@ -235,6 +249,11 @@ function updateCss() {
let cssStr = editor.getValue();
chrome.storage.sync.set({ css: cssStr });
analyseAll();
+ chrome.tabs.query({ active: true, currentWindow: true },
+ function (tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, { type: 'update', data: false });
+ }
+ );
}
$('#download').on('click', function () {