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

Presets settings #4

Open
wants to merge 4 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: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.4.0 (20-01-2019)

* Updated `discovery` to `1.0.0-beta.6`
* New feature "View Presets". Now you can preset custom view for any host you need.

## 1.3.0 (26-12-2018)

* Updated `discovery` (new stunning `jora` suggestions on report page)
Expand Down
14 changes: 8 additions & 6 deletions core/settings.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
<meta charset="utf-8">
<title><%= htmlWebpackPlugin.options.title %></title>
<link href='https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons' rel="stylesheet" type="text/css">
<style>
.row {
margin-bottom: 10px;
}
</style>
</head>
<body>
<div id="root">
<h1>Settings</h1>
<form id="settings-form">
<div class="row">
<input type="number" min="0" id="expand" required> Expand level
<input type="number" min="0" id="expand"> Expand level
</div>
<div class="row">
<h2>Presets:<button id="add-host">Add host</button></h2>
</div>
<div class="row">
<ul id="presets">
</ul>
</div>
<div class="row">
<input type="submit" id="save" value="Save">
Expand Down
188 changes: 94 additions & 94 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{
"name": "jsondiscovery",
"version": "1.3.0",
"version": "1.4.0",
"description": "DiscoveryJson",
"author": "exsdis@gmail.com",
"license": "MIT",
"private": false,
"dependencies": {},
"scripts": {
"lint": "eslint --ext .js src core",
"dev": "webpack --config ./core/webpack.dev.js --hide-modules",
"build": "rimraf build && webpack --config ./core/webpack.prod.js -p --progress --hide-modules --colors --info-verbosity verbose && node core/zip.js"
},
"devDependencies": {
"@discoveryjs/discovery": "^1.0.0-beta.5",
"@discoveryjs/discovery": "^1.0.0-beta.6",
"archiver": "^2.1.0",
"babel-core": "^6.26.0",
"babel-eslint": "^8.0.1",
Expand All @@ -23,6 +22,7 @@
"buble": "^0.16.0",
"buble-loader": "^0.4.1",
"clean-webpack-plugin": "^0.1.19",
"codemirror": "^5.42.2",
"copy-webpack-plugin": "^4.5.4",
"cross-env": "^5.1.0",
"css-loader": "^1.0.1",
Expand Down
4 changes: 3 additions & 1 deletion src/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ require('./index.css');
* @returns {Discovery}
*/
function initDiscovery(settings) {
const discovery = new Widget(document.body);
const discovery = new Widget(document.body, {
viewPresets: settings.viewPresets || []
});

discovery.apply(router);
discovery.apply(complexViews);
Expand Down
17 changes: 16 additions & 1 deletion src/content/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*/
function getSettings(cb) {
chrome.storage.sync.get({
expandLevel: 3
expandLevel: 3,
viewPresets: []
}, settings => {
cb(settings);
});
Expand Down Expand Up @@ -48,6 +49,20 @@ if (json) {

iframe.addEventListener('load', () => {
getSettings(settings => {
let viewPresets = [];

for (const item of settings.viewPresets) {
const { host, presets } = item;

const hostRe = new RegExp(host);

if (hostRe.test(document.location.toString())) {
viewPresets = viewPresets.concat(presets);
}
}

settings.viewPresets = viewPresets;

iframe.contentWindow.postMessage({
json,
raw,
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
],
options_ui: { // eslint-disable-line camelcase
page: 'pages/settings.html',
chrome_style: true, // eslint-disable-line camelcase
chrome_style: false, // eslint-disable-line camelcase
open_in_tab: false // eslint-disable-line camelcase
},
content_scripts: [{ // eslint-disable-line camelcase
Expand Down
89 changes: 89 additions & 0 deletions src/settings.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
body {
font-family: Tahoma,Verdana,Arial,sans-serif;
font-size: 14px;
line-height: 1.6;
}

*:focus {
outline: none;
}

h2 button {
margin-left: 10px;
}

.row {
margin-bottom: 10px;
}

#status.error {
color: red;
}

button, input[type=submit] {
display: inline-block;
vertical-align: middle;
padding: 4px 24px;
border-radius: 4px;
border: none;
background: #0af;
color: #fff;
font: inherit;
cursor: pointer;
}

input[type=text], input[type=number] {
display: inline-block;
vertical-align: middle;
width: 300px;
border: 1px solid #aaa;
border-radius: 4px;
height: 28px;
margin-right: 10px;
padding: 0 6px 0 6px;
}

input[type=text]:focus, input[type=number]:focus {
border-color: #0af;
box-shadow: 0 0 1px 3px rgba(0,170,255,.2),inset 0 1px 1px hsla(0,0%,55.7%,.2) !important;
}

input.error, textarea.error, #presets .CodeMirror.error {
border: 1px solid red;
}

ul ul {
margin-top: 10px;
}

li {
margin-bottom: 10px;
}

#presets .CodeMirror {
width: 446px;
height: auto;
padding: 4px 8px;
margin-top: 10px;
font-family: Consolas, Monaco, monospace;
font-size: 12px;
border: 1px solid #aaa;
border-radius: 3px;
box-shadow: inset 0 1px 1px rgba(142, 142, 142, .2);
}

#presets .CodeMirror-scroll {
min-height: 6.5em;
cursor: text;
}

#presets .CodeMirror-focused {
border-color: #0af;
box-shadow: 0 0 1px 3px rgba(0, 170, 255, .2), inset 0 1px 1px rgba(142, 142, 142, .2) !important;
}

#presets .CodeMirror-cursor {
border-left: 1px solid black;
background: none;
width: 0;
}
Loading