Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hljs Theme Support #147

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ Installation

**Some URLs to try it on:**

* http://feeds.delicious.com/v2/json/popular?callback=hello
* http://gdata.youtube.com/feeds/api/standardfeeds/most_popular?alt=json&v=2
* http://twitter.com/statuses/public_timeline.json
* https://jsonplaceholder.typicode.com/users
* https://jsonplaceholder.typicode.com/posts/1

FAQ
---
Expand Down
2 changes: 1 addition & 1 deletion extension/css/content.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 36 additions & 8 deletions extension/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@
baseSpan = document.createElement('span') ;

function getSpanBoth(innerText,className) {
var span = baseSpan.cloneNode(false) ;
span.className = className ;
var span = getSpanClass(className);
span.innerText = innerText ;
return span ;
}
Expand All @@ -164,8 +163,35 @@
return span ;
}
function getSpanClass(className) {
var span = baseSpan.cloneNode(false) ;
span.className = className ;
var span = baseSpan.cloneNode(false);
span.className = className;
switch(className)
{
default:
break;

case 'k':
span.className += " hljs-attr";
break;

case 's':
span.className += " hljs-string";
break;

case 'n':
span.className += " hljs-number";
break;

//case 'e':
// span.className += " hljs-comment";
// break;

case 'nl':
case 'bl':
span.className += " hljs-literal";
break;
}

return span ;
}

Expand Down Expand Up @@ -238,14 +264,16 @@
// If there's a key, add that before the value
if (keyName !== false) { // NB: "" is a legal keyname in JSON
// This kvov must be an object property
kvov.classList.add('objProp') ;
kvov.classList.add('objProp');

// Create a span for the key name
keySpan = templates.t_key.cloneNode(false) ;
keySpan.textContent = JSON.stringify(keyName).slice(1,-1) ; // remove quotes
//keySpan.textContent = JSON.stringify(keyName).slice(1,-1) ; // remove quotes
keySpan.textContent = JSON.stringify(keyName);
// Add it to kvov, with quote marks
kvov.appendChild(templates.t_dblqText.cloneNode(false)) ;
//kvov.appendChild(templates.t_dblqText.cloneNode(false)) ;
kvov.appendChild( keySpan ) ;
kvov.appendChild(templates.t_dblqText.cloneNode(false)) ;
//kvov.appendChild(templates.t_dblqText.cloneNode(false)) ;
// Also add ": " (colon and non-breaking space)
kvov.appendChild( templates.t_colonAndSpace.cloneNode(false) ) ;
}
Expand Down
18 changes: 16 additions & 2 deletions extension/js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
/*jshint eqeqeq:true, forin:true, strict:true */
/*global chrome, console */


(function() {

"use strict" ;

var jfContent,
pre,
jfStyleEl,
jfThemeEl,
slowAnalysisTimeout,
port,
startTime = +(new Date()),
Expand Down Expand Up @@ -81,7 +83,8 @@

jfStyleEl.insertAdjacentHTML(
'beforeend',
'body{-webkit-user-select:text;overflow-y:scroll !important;margin:0;position:relative}#optionBar{-webkit-user-select:none;display:block;position:absolute;top:9px;right:17px}#buttonFormatted,#buttonPlain{-webkit-border-radius:2px;-webkit-box-shadow:0px 1px 3px rgba(0,0,0,0.1);-webkit-user-select:none;background:-webkit-linear-gradient(#fafafa, #f4f4f4 40%, #e5e5e5);border:1px solid #aaa;color:#444;font-size:12px;margin-bottom:0px;min-width:4em;padding:3px 0;position:relative;z-index:10;display:inline-block;width:80px;text-shadow:1px 1px rgba(255,255,255,0.3)}#buttonFormatted{margin-left:0;border-top-left-radius:0;border-bottom-left-radius:0}#buttonPlain{margin-right:0;border-top-right-radius:0;border-bottom-right-radius:0;border-right:none}#buttonFormatted:hover,#buttonPlain:hover{-webkit-box-shadow:0px 1px 3px rgba(0,0,0,0.2);background:#ebebeb -webkit-linear-gradient(#fefefe, #f8f8f8 40%, #e9e9e9);border-color:#999;color:#222}#buttonFormatted:active,#buttonPlain:active{-webkit-box-shadow:inset 0px 1px 3px rgba(0,0,0,0.2);background:#ebebeb -webkit-linear-gradient(#f4f4f4, #efefef 40%, #dcdcdc);color:#333}#buttonFormatted.selected,#buttonPlain.selected{-webkit-box-shadow:inset 0px 1px 5px rgba(0,0,0,0.2);background:#ebebeb -webkit-linear-gradient(#e4e4e4, #dfdfdf 40%, #dcdcdc);color:#333}#buttonFormatted:focus,#buttonPlain:focus{outline:0}#jsonpOpener,#jsonpCloser{padding:4px 0 0 8px;color:#000;margin-bottom:-6px}#jsonpCloser{margin-top:0}#formattedJson{padding-left:28px;padding-top:6px}pre{padding:36px 5px 5px 5px}.kvov{display:block;padding-left:20px;margin-left:-20px;position:relative}.collapsed{white-space:nowrap}.collapsed>.blockInner{display:none}.collapsed>.ell:after{content:"…";font-weight:bold}.collapsed>.ell{margin:0 4px;color:#888}.collapsed .kvov{display:inline}.e{width:20px;height:18px;display:block;position:absolute;left:-2px;top:1px;z-index:5;background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAD1JREFUeNpiYGBgOADE%2F3Hgw0DM4IRHgSsDFOzFInmMAQnY49ONzZRjDFiADT7dMLALiE8y4AGW6LoBAgwAuIkf%2F%2FB7O9sAAAAASUVORK5CYII%3D");background-repeat:no-repeat;background-position:center center;display:block;opacity:0.15}.collapsed>.e{-webkit-transform:rotate(-90deg);width:18px;height:20px;left:0px;top:0px}.e:hover{opacity:0.35}.e:active{opacity:0.5}.collapsed .kvov .e{display:none}.blockInner{display:block;padding-left:24px;border-left:1px dotted #bbb;margin-left:2px}#formattedJson,#jsonpOpener,#jsonpCloser{color:#333;font:13px/18px monospace}#formattedJson{color:#444}.b{font-weight:bold}.s{color:#0B7500;word-wrap:break-word}a:link,a:visited{text-decoration:none;color:inherit}a:hover,a:active{text-decoration:underline;color:#050}.bl,.nl,.n{font-weight:bold;color:#1A01CC}.k{color:#000}#formattingMsg{font:13px "Lucida Grande","Segoe UI","Tahoma";padding:10px 0 0 8px;margin:0;color:#333}#formattingMsg>svg{margin:0 7px;position:relative;top:1px}[hidden]{display:none !important}span{white-space:pre-wrap}@-webkit-keyframes spin{from{-webkit-transform:rotate(0deg)}to{-webkit-transform:rotate(360deg)}}#spinner{-webkit-animation:spin 2s 0 infinite}*{-webkit-font-smoothing:antialiased}'
'body{-webkit-user-select:text;overflow-y:scroll !important;margin:0;position:relative}#optionBar{-webkit-user-select:none;display:block;position:absolute;top:9px;right:17px}#buttonFormatted,#buttonPlain{-webkit-border-radius:2px;-webkit-box-shadow:0px 1px 3px rgba(0,0,0,0.1);-webkit-user-select:none;background:-webkit-linear-gradient(#fafafa, #f4f4f4 40%, #e5e5e5);border:1px solid #aaa;color:#444;font-size:12px;margin-bottom:0px;min-width:4em;padding:3px 0;position:relative;z-index:10;display:inline-block;width:80px;text-shadow:1px 1px rgba(255,255,255,0.3)}#buttonFormatted{margin-left:0;border-top-left-radius:0;border-bottom-left-radius:0}#buttonPlain{margin-right:0;border-top-right-radius:0;border-bottom-right-radius:0;border-right:none}#buttonFormatted:hover,#buttonPlain:hover{-webkit-box-shadow:0px 1px 3px rgba(0,0,0,0.2);background:#ebebeb -webkit-linear-gradient(#fefefe, #f8f8f8 40%, #e9e9e9);border-color:#999;color:#222}#buttonFormatted:active,#buttonPlain:active{-webkit-box-shadow:inset 0px 1px 3px rgba(0,0,0,0.2);background:#ebebeb -webkit-linear-gradient(#f4f4f4, #efefef 40%, #dcdcdc);color:#333}#buttonFormatted.selected,#buttonPlain.selected{-webkit-box-shadow:inset 0px 1px 5px rgba(0,0,0,0.2);background:#ebebeb -webkit-linear-gradient(#e4e4e4, #dfdfdf 40%, #dcdcdc);color:#333}#buttonFormatted:focus,#buttonPlain:focus{outline:0}#jsonpOpener,#jsonpCloser{padding:4px 0 0 8px;color:#000;margin-bottom:-6px}#jsonpCloser{margin-top:0}#formattedJson{padding-left:28px;padding-top:6px}pre{padding:36px 5px 5px 5px}.kvov{display:block;padding-left:20px;margin-left:-20px;position:relative}.collapsed{white-space:nowrap}.collapsed>.blockInner{display:none}.collapsed>.ell:after{content:"…";font-weight:bold}.collapsed>.ell{margin:0 4px;color:#888}.collapsed .kvov{display:inline}.e{-webkit-transform:rotate(90deg);width:20px;height:18px;display:block;position:absolute;left:-2px;top:1px;z-index:5;display:block;opacity:1}.collapsed>.e{-webkit-transform:rotate(0deg);width:18px;height:20px;left:0px;top:0px}.e:hover{opacity:0.75}.e:active{opacity:1}.collapsed .kvov .e{display:none}.blockInner{display:block;padding-left:24px;border-left:1px dotted #bbb;margin-left:2px}#formattedJson,#jsonpOpener,#jsonpCloser{font:13px/18px monospace}.b{font-weight:bold}.s{color:#0B7500;word-wrap:break-word}a:link,a:visited{text-decoration:none;color:inherit}a:hover,a:active{text-decoration:underline;color:#050}.bl,.nl,.n{font-weight:bold;color:#1A01CC}#formattingMsg{font:13px "Lucida Grande","Segoe UI","Tahoma";padding:10px 0 0 8px;margin:0;color:#333}#formattingMsg>svg{margin:0 7px;position:relative;top:1px}[hidden]{display:none !important}span{white-space:pre-wrap}@-webkit-keyframes spin{from{-webkit-transform:rotate(0deg)}to{-webkit-transform:rotate(360deg)}}#spinner{-webkit-animation:spin 2s 0 infinite}*{-webkit-font-smoothing:antialiased}' +
'.e::before { content: "⯈"; cursor:pointer; }'
) ;

// Add custom font name if set - FROM FUTURE
Expand All @@ -92,6 +95,17 @@
// ) ;
// }

//Insert the custom styling
//jfThemeEl = document.head.insertAdjacentHTML('beforeend', '<link rel="stylesheet" href="'+chrome.runtime.getURL("styles/default.css")+'">');
//document.body.className = "hljs";

//Load the theme in the background
chrome.storage.sync.get("theme", function(value) {
jfThemeEl = document.head.insertAdjacentHTML('beforeend', '<link rel="stylesheet" href="'+chrome.runtime.getURL("styles/" + value.theme + ".css")+'">');
document.body.className = "hljs";
});


// Show 'Formatting...' spinner
// jfContent.innerHTML = '<p id="formattingMsg"><img src="data:image/gif;base64,R0lGODlhEAALAPQAAP%2F%2F%2FwAAANra2tDQ0Orq6gYGBgAAAC4uLoKCgmBgYLq6uiIiIkpKSoqKimRkZL6%2BviYmJgQEBE5OTubm5tjY2PT09Dg4ONzc3PLy8ra2tqCgoMrKyu7u7gAAAAAAAAAAACH%2BGkNyZWF0ZWQgd2l0aCBhamF4bG9hZC5pbmZvACH5BAALAAAAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAEAALAAAFLSAgjmRpnqSgCuLKAq5AEIM4zDVw03ve27ifDgfkEYe04kDIDC5zrtYKRa2WQgAh%2BQQACwABACwAAAAAEAALAAAFJGBhGAVgnqhpHIeRvsDawqns0qeN5%2By967tYLyicBYE7EYkYAgAh%2BQQACwACACwAAAAAEAALAAAFNiAgjothLOOIJAkiGgxjpGKiKMkbz7SN6zIawJcDwIK9W%2FHISxGBzdHTuBNOmcJVCyoUlk7CEAAh%2BQQACwADACwAAAAAEAALAAAFNSAgjqQIRRFUAo3jNGIkSdHqPI8Tz3V55zuaDacDyIQ%2BYrBH%2BhWPzJFzOQQaeavWi7oqnVIhACH5BAALAAQALAAAAAAQAAsAAAUyICCOZGme1rJY5kRRk7hI0mJSVUXJtF3iOl7tltsBZsNfUegjAY3I5sgFY55KqdX1GgIAIfkEAAsABQAsAAAAABAACwAABTcgII5kaZ4kcV2EqLJipmnZhWGXaOOitm2aXQ4g7P2Ct2ER4AMul00kj5g0Al8tADY2y6C%2B4FIIACH5BAALAAYALAAAAAAQAAsAAAUvICCOZGme5ERRk6iy7qpyHCVStA3gNa%2F7txxwlwv2isSacYUc%2Bl4tADQGQ1mvpBAAIfkEAAsABwAsAAAAABAACwAABS8gII5kaZ7kRFGTqLLuqnIcJVK0DeA1r%2Fu3HHCXC%2FaKxJpxhRz6Xi0ANAZDWa%2BkEAA7AAAAAAAAAAAA"> Formatting...</p>' ;
// jfContent.innerHTML = '<p id="formattingMsg">Formatting...<br><progress/></p>' ;
Expand Down Expand Up @@ -329,7 +343,7 @@
if (ev.which === 1) {
var elem = ev.target ;

if (elem.className === 'e') {
if (elem.className.startsWith('e')) {
// It's a click on an expander.

ev.preventDefault() ;
Expand Down
13 changes: 11 additions & 2 deletions extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@
"scripts": ["js/background.js"]
},
"content_scripts": [
{ "matches": ["<all_urls>"], "js": ["js/content.js"], "run_at": "document_start" }
{
"matches": ["<all_urls>"],
"js": ["js/content.js"],
"run_at": "document_start"
}
],
"permissions":["*://*/*", "<all_urls>"]
"web_accessible_resources": ["styles/*"],
"permissions":["*://*/*", "<all_urls>", "storage"],
"browser_action":
{
"default_popup": "options.html"
}
}
Loading