-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize repo, make things mostly work in Chrome
- Loading branch information
Showing
41 changed files
with
183 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
*.xpi | ||
*.zip | ||
.tern-port | ||
/ts-out | ||
/build | ||
/main.js | ||
/node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh -e | ||
|
||
tsc | ||
|
||
mkdir -p build | ||
|
||
rollup ts-out/background.js --format iife --name 'background' --file build/background.js | ||
rollup ts-out/content.js --format iife --name 'background' --file build/content.js | ||
rollup ts-out/viewer.js --format iife --name 'background' --file build/viewer.js | ||
cp src/viewer.css build/viewer.css | ||
cp src/manifest.json build/manifest.json | ||
cp license.txt build/license.txt | ||
cp -r src/_locales build | ||
cp src/icon*.png build | ||
|
||
rm jsonview.zip | ||
pushd build | ||
zip -r ../jsonview.zip * | ||
popd |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
/** | ||
* Add event handlers that allow for collapsing and expanding JSON structures, with the mouse or keyboard. | ||
*/ | ||
export function installCollapseEventListeners() { | ||
// Click handler for collapsing and expanding objects and arrays | ||
function collapse(evt: Event) { | ||
let collapser = evt.target as any; | ||
|
||
while (collapser && (!collapser.classList || !collapser.classList.contains('collapser'))) { | ||
collapser = collapser.nextSibling; | ||
} | ||
if (!collapser || !collapser.classList || !collapser.classList.contains('collapser')) { | ||
return; | ||
} | ||
|
||
evt.stopPropagation(); | ||
|
||
collapser.classList.toggle('collapsed'); | ||
|
||
let collapsible = collapser; | ||
while (collapsible && (!collapsible.classList || !collapsible.classList.contains('collapsible'))) { | ||
collapsible = collapsible.nextSibling; | ||
} | ||
collapsible.classList.toggle('collapsed'); | ||
} | ||
|
||
/* | ||
* Collapses the whole json using keyboard | ||
* TODO: Add a navigator support for each of the elements | ||
*/ | ||
function collapseAll(evt: KeyboardEvent) { | ||
let inputList; | ||
let i; | ||
|
||
// Ignore anything paired with a modifier key. See https://github.com/bhollis/jsonview/issues/69 | ||
if (evt.ctrlKey || evt.shiftKey || evt.altKey || evt.metaKey) { | ||
return; | ||
} | ||
|
||
if (evt.keyCode === 37) { // Collapses the json on left arrow key up | ||
inputList = document.querySelectorAll('.collapsible, .collapser'); | ||
for (i = 0; i < inputList.length; i++) { | ||
if ((inputList[i].parentNode! as HTMLElement).id !== 'json') { | ||
inputList[i].classList.add('collapsed'); | ||
} | ||
} | ||
evt.preventDefault(); | ||
} else if (evt.keyCode === 39) { // Expands the json on right arrow key up | ||
inputList = document.querySelectorAll('.collapsed'); | ||
for (i = 0; i < inputList.length; i++) { | ||
inputList[i].classList.remove('collapsed'); | ||
} | ||
evt.preventDefault(); | ||
} | ||
} | ||
|
||
// collapse with event delegation | ||
document.addEventListener('click', collapse, false); | ||
document.addEventListener('keyup', collapseAll, false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { errorPage, jsonToHTML } from './jsonformatter'; | ||
import { safeStringEncodeNums } from './safe-encode-numbers'; | ||
import { installCollapseEventListeners } from './collapse'; | ||
|
||
chrome.runtime.sendMessage({}, (response: boolean) => { | ||
if (!response) { | ||
return; | ||
} | ||
|
||
const content = document.getElementsByTagName('pre')[0].innerText; | ||
let outputDoc = ''; | ||
|
||
try { | ||
const jsonObj = JSON.parse(safeStringEncodeNums(content)); | ||
outputDoc = jsonToHTML(jsonObj, document.URL); | ||
} catch (e) { | ||
outputDoc = errorPage(e, content, document.URL); | ||
} | ||
|
||
document.documentElement.innerHTML = outputDoc; | ||
installCollapseEventListeners(); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { installCollapseEventListeners } from "./collapse"; | ||
|
||
document.addEventListener('DOMContentLoaded', installCollapseEventListeners, false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters