Skip to content

Commit

Permalink
Add option to toggle debug mode (#213)
Browse files Browse the repository at this point in the history
This PR adds a checkbox which allows you to toggle the debug mode. The debug mode basically just adds a css class on every OctoLinker link so you easily spot all links. On Firefox and Opera the settings are stored locally. Chrome stores the settings within the users account, if available.
  • Loading branch information
stefanbuck authored and josephfrazier committed Nov 29, 2016
1 parent 85a46b4 commit 706be13
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 6 deletions.
1 change: 1 addition & 0 deletions assets/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
}
],
"permissions": [
"storage",
"https://github.com/",
"https://gist.github.com/",
"https://githublinker.herokuapp.com/"
Expand Down
16 changes: 16 additions & 0 deletions assets/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
body {
user-select: none;
}
label {
display: block;
margin: 12px 0;
}

#options {
margin-bottom: 36px;
}
</style>
</head>
<body>
<div id="options"></div>

<iframe src="http://ghbtns.com/github-btn.html?user=octolinker&amp;repo=browser-extension&amp;type=watch&amp;count=true&amp;size=small" style="background-color: transparent; border: none; overflow:hidden" width="120" height="20"></iframe>
<script src="options.js"></script>
</body>
</html>
7 changes: 5 additions & 2 deletions lib/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'babel-polyfill';
import OctoLinker from './octo-linker.js';
import * as storage from './options/storage.js';

const octoLinker = new OctoLinker();
octoLinker.init();
storage.load(() => {
const octoLinker = new OctoLinker();
octoLinker.init();
});
7 changes: 4 additions & 3 deletions lib/octo-linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import clickHandler from './click-handler';
import Plugins from './plugin-manager.js';
import debugMode from './debug-mode.js';
import loadPlugins from './load-plugins';
import * as storage from './options/storage.js';


function initialize(self) {
debugMode(false);
debugMode(storage.get('debugMode'));
clickHandler(resolvers);
notification();

Expand Down Expand Up @@ -38,8 +39,8 @@ function run(self) {
}

export default class OctoLinkerCore {
constructor() {
initialize(this);
constructor(options) {
initialize(this, options);
}

init() {
Expand Down
9 changes: 9 additions & 0 deletions lib/options/components/checkbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default ({ name, label, value, defaultValue }) => {
const val = (value === undefined) ? defaultValue : value;

return `<section>
<label>
<input type="checkbox" name="${name}" ${val ? 'checked' : ''} /> ${label}
</label>
</section>`;
};
7 changes: 7 additions & 0 deletions lib/options/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import checkbox from './checkbox';

export default function ({ type, ...rest }) {
if (type === 'checkbox') {
return checkbox(rest);
}
}
9 changes: 9 additions & 0 deletions lib/options/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const options = [
{
type: 'checkbox',
name: 'debugMode',
label: 'Debug mode',
value: undefined,
defaultValue: false,
},
];
22 changes: 22 additions & 0 deletions lib/options/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import components from './components';
import * as storage from './storage';
import { options } from './options';

const formEl = document.querySelector('#options');

storage.load(() => {
options.forEach((item) => {
formEl.innerHTML += components({
...item,
value: storage.get(item.name),
});
});
});

formEl.addEventListener('click', ({ target }) => {
const tag = target.tagName.toLowerCase();

if (tag === 'input' && target.type === 'checkbox') {
storage.set(target.name, target.checked);
}
});
24 changes: 24 additions & 0 deletions lib/options/storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { options } from './options';

const store = {};
const defaults = {};

options.forEach((item) => {
defaults[item.name] = item.defaultValue;
});

export const load = (cb) => {
(chrome.storage.sync || chrome.storage.local).get(null, (data) => {
Object.assign(store, defaults, data);

cb();
});
};

export const get = key => store[key];

export const set = (key, value) => {
(chrome.storage.sync || chrome.storage.local).set({
[key]: value,
});
};
12 changes: 12 additions & 0 deletions npm-shrinkwrap.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": "json -I -f assets/manifest.json -e \"this.version='`json -f package.json version`'\" && git add assets/manifest.json",
"package-all": "npm-run-all chrome-pack firefox-pack && cp out/chrome-octolinker-$npm_package_version.zip out/opera-octolinker-$npm_package_version.zip",
"release": "webstore upload --source out/chrome-octolinker-$npm_package_version.zip --auto-publish",
"chrome-manifest": "mkdirp dist && json -e \"delete this.applications; this.permissions.shift()\" < assets/manifest.json > dist/manifest.json",
"chrome-manifest": "mkdirp dist && json -e \"delete this.applications;\" < assets/manifest.json > dist/manifest.json",
"chrome-build": "npm run chrome-manifest && webpack",
"chrome-dist": "npm run chrome-build -- -p",
"chrome-watch": "npm run chrome-manifest && webpack --watch",
Expand Down Expand Up @@ -44,6 +44,7 @@
"babel-core": "^6.18.2",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.2.8",
"babel-plugin-transform-object-rest-spread": "^6.19.0",
"babel-preset-es2015": "^6.9.0",
"chrome-webstore-upload-cli": "^1.1.0",
"copy-webpack-plugin": "^4.0.1",
Expand Down
2 changes: 2 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
entry: {
app: './lib/app',
background: './lib/background',
options: './lib/options/page',
},
devtool: 'source-map',
output: {
Expand All @@ -24,6 +25,7 @@ module.exports = {
exclude: /(node_modules)/,
loader: 'babel',
query: {
plugins: ['transform-object-rest-spread'],
presets: ['es2015'],
},
},
Expand Down

0 comments on commit 706be13

Please sign in to comment.