Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JSHint Options Chooser
// Just paste this into the console on http://www.jshint.com/docs/options/
(function() {
var i, row, link, span, extraCol, checkbox, value;
var rows = document.querySelectorAll('table.options tr');
var links = document.querySelectorAll('table.options a');
// add checkboxes
for (var i = 0; i < rows.length; i++) {
row = rows[i];
extraCol = document.createElement('td');
checkbox = document.createElement('input');
value = document.createElement('input');
value.value = 'true';
value.style['margin-top'] = '16px';
value.style.width = '40px';
checkbox.type = 'checkbox';
checkbox.dataset.option = row.querySelector('.name a').innerText;
extraCol.appendChild(checkbox);
extraCol.appendChild(value);
extraCol.style['padding-right'] = '26px';
row.insertBefore(extraCol, row.firstChild);
}
// clear links to make tabbing through checkboxes quick and easy
for (i = 0; i < links.length; i++) {
span = document.createElement('span');
link = links[i];
span.innerHTML = link.innerHTML;
link.parentNode.replaceChild(span, link);
}
// add output stuff
var parent = document.querySelectorAll('table.options:last-child')[0].parentNode;
var output = document.createElement('textarea');
output.setAttribute('rows', '14');
output.setAttribute('cols', '26');
output.style.display = 'block';
output.style['margin-top'] = '16px';
var button = document.createElement('button');
button.innerText = 'Generate .jshintrc';
button.addEventListener('click', function() {
var checkbox, val;
var checkboxes = document.querySelectorAll('table.options tr [type=checkbox]');
var selectedOptions = {};
for (i = 0; i < checkboxes.length; i++) {
checkbox = checkboxes[i];
if (checkbox.checked) {
val = checkbox.nextSibling.value;
// Type coercion
if (!isNaN(val)) val = ~~val;
if (val === 'true') val = true;
if (val === 'false') val = false;
selectedOptions[checkbox.dataset.option] = val;
}
}
output.value = JSON.stringify(selectedOptions, null, 2);
});
parent.appendChild(button);
parent.appendChild(output);
})();
@milsosa

This comment has been minimized.

Copy link

milsosa commented Oct 9, 2015

It is not working because an issue in the selector in the line 18, it can be fixed using this selector row.querySelector('td:first-child a').innerText instead.

@vipex

This comment has been minimized.

Copy link

vipex commented Sep 6, 2016

on line 18 replace this:
checkbox.dataset.option = row.querySelector('.name a').innerText;
with this:
checkbox.dataset.option = row.querySelector('td > a').innerText;
And will work again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.