From 39467472b0179eae8ecfdc985f72535cb33d0167 Mon Sep 17 00:00:00 2001 From: Florian Gambert Date: Thu, 21 Mar 2019 16:14:40 +0100 Subject: [PATCH 1/2] Display index when in array --- background.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/background.js b/background.js index 4d30e8e..f54e5dd 100644 --- a/background.js +++ b/background.js @@ -111,6 +111,9 @@ function readConf(next) { ';color:' + opts.infoHover + ';content:" // " attr(data-c)}' : '' ) + + ':not(i).Y', ':before{content:attr(data-i);margin-left:-1em;font-style:normal;color:' + opts.info + '}' + + 'i.Y', '{font-style:normal}' + + 'i.Y', ':after{content:attr(data-i);color:' + opts.info + '}' + '.B', '{color:' + opts.bool + '}' + '.K', '{color:' + opts.property + '}' + '.E', '{color:' + opts.error + '}' + @@ -285,6 +288,7 @@ function init(exports, rand, opts) { , STR = "S" + rand , BOOL = "B" + rand , NUM = "N" + rand + , INDEX= "Y" + rand , NULL = "O" + rand , ERR = "E" + rand , COLL = "C" + rand @@ -318,7 +322,10 @@ function init(exports, rand, opts) { function fragment(a, b) { var frag = document.createDocumentFragment() - frag.appendChild(document.createTextNode(a)) + var aElement = document.createElement("i") + aElement.classList.add("Y" + rand) + aElement.appendChild(document.createTextNode(a)) + frag.appendChild(aElement) frag.appendChild(document.createElement("i")).classList.add("I" + rand) frag.appendChild(div.cloneNode()) frag.appendChild(document.createTextNode(b)) @@ -416,6 +423,7 @@ function init(exports, rand, opts) { node = node.lastChild.previousSibling node.len = 1 node.start = re.lastIndex + node.isArray = val == "[" } else if ((val == "}" || val == "]") && node.len) { if (node.childNodes.length) { tmp = node.previousElementSibling @@ -428,6 +436,10 @@ function init(exports, rand, opts) { tmp.dataset.k = (val = tmp.previousElementSibling) && val.classList.contains(KEY) ? val.textContent.replace(/'/, "\\'") : node.parentNode.len + + if (tmp.previousElementSibling && node.parentNode.len && node.parentNode.isArray) { + tmp.previousElementSibling.dataset.i= "[" + (node.parentNode.len - 1) + "]" + } } else { node.parentNode.removeChild(node.previousSibling) node.parentNode.removeChild(node) @@ -460,6 +472,12 @@ function init(exports, rand, opts) { tmp.dataset.c = d[opts.showDateFn]() } } + if (node.isArray) { + tmp.dataset.i = "[" + (node.len - 1) + "]" + tmp.classList.add(INDEX) + } + + val = match[1] ? (unesc ? '"' + JSON.parse(match[1]) + '"' : match[1]) : val len = match[3] ? 140 : 1400 if (val.length > len) { @@ -474,6 +492,7 @@ function init(exports, rand, opts) { tmp.classList.add("D" + rand) } tmp.textContent = val + node.appendChild(tmp) if (match[3]) { node.appendChild(colon.cloneNode()) @@ -541,5 +560,3 @@ function rewriteHeader(e) { return {responseHeaders: headers} } //*/ - - From ee316ea406dc447cb320369f1df98ff0b5fa8b4b Mon Sep 17 00:00:00 2001 From: Florian Gambert Date: Thu, 21 Mar 2019 16:45:29 +0100 Subject: [PATCH 2/2] add showIndex option --- background.js | 11 ++++++++--- options.html | 2 +- options.js | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/background.js b/background.js index f54e5dd..35ce79d 100644 --- a/background.js +++ b/background.js @@ -26,6 +26,7 @@ var css, opts showDate: "hover", showDateFn: "toString", showSize: "collapsed", + showIndex: true, newtab: false } , cssVar = { @@ -111,9 +112,13 @@ function readConf(next) { ';color:' + opts.infoHover + ';content:" // " attr(data-c)}' : '' ) + - ':not(i).Y', ':before{content:attr(data-i);margin-left:-1em;font-style:normal;color:' + opts.info + '}' + - 'i.Y', '{font-style:normal}' + - 'i.Y', ':after{content:attr(data-i);color:' + opts.info + '}' + + 'i.Y' + rand + '{font-style:normal}' + + ( + opts.showIndex ? + ':not(i).Y' + rand + ':before{content:attr(data-i);margin-left:-1em;font-style:normal;color:' + opts.info + '}' + + 'i.Y' + rand + ':after{content:attr(data-i);color:' + opts.info + '}' : + '' + ) + '.B', '{color:' + opts.bool + '}' + '.K', '{color:' + opts.property + '}' + '.E', '{color:' + opts.error + '}' + diff --git a/options.html b/options.html index 68077f4..0672af8 100644 --- a/options.html +++ b/options.html @@ -71,10 +71,10 @@ + - diff --git a/options.js b/options.js index b95c2c1..719f1fb 100644 --- a/options.js +++ b/options.js @@ -15,6 +15,7 @@ var chrome = this.chrome || this.browser showDate: "hover", showDateFn: "toString", showSize: "collapsed", + showIndex: true, newtab: false } , themes = { @@ -88,4 +89,3 @@ theme.addEventListener("change", function() { showDate.addEventListener("change", function() { updateForm() }) -