save / load filters

This commit is contained in:
James Campos 2010-04-28 01:08:38 -07:00
parent 1be8310310
commit ec4387ebdb
2 changed files with 43 additions and 37 deletions

View File

@ -154,15 +154,7 @@ filterSingle: (table, filter) ->
filterAll: -> filterAll: ->
#save current filters saveFilters()
#this should be in its own function to play nice with change()
filter: {}
inputs: $$('input', box)
for input in inputs
if value: input.value
filter[input.name]: value
filters[select.value]: filter
GM_setValue('filters', JSON.stringify(filters))
#better way of doing this? #better way of doing this?
compiled: {} compiled: {}
@ -271,13 +263,23 @@ options: ->
document.body.appendChild(opt) document.body.appendChild(opt)
change: -> loadFilters: ->
filter: filters[@value] filter: filters[@value]
inputs: $$('input', box) inputs: $$('input', box)
for input in inputs for input in inputs
input.value: filter[input.name] || '' input.value: filter[input.name] || ''
saveFilters: ->
filter: {}
inputs: $$('input', box)
for input in inputs
if value: input.value
filter[input.name]: value
filters[select.value]: filter
GM_setValue('filters', JSON.stringify(filters))
box: tag('div') box: tag('div')
box.id: 'box' box.id: 'box'
box.className: GM_getValue('className', 'reply') box.className: GM_getValue('className', 'reply')
@ -289,7 +291,8 @@ bar.addEventListener('mousedown', mousedown, true)
box.appendChild(bar) box.appendChild(bar)
select: tag('select') select: tag('select')
select.addEventListener('change', change, true) select.addEventListener('mousedown', saveFilters, true)
select.addEventListener('mouseup', loadFilters, true)
filters: JSON.parse(GM_getValue('filters', '{ "hide": {} }')) filters: JSON.parse(GM_getValue('filters', '{ "hide": {} }'))
for filter of filters for filter of filters
option: tag('option') option: tag('option')
@ -316,7 +319,7 @@ for field in fields
div.appendChild(label) div.appendChild(label)
box.appendChild(div) box.appendChild(div)
change.call(select) loadFilters.call(select)
div: tag('div') div: tag('div')
div.className: 'bottom' div.className: 'bottom'

View File

@ -1,5 +1,5 @@
(function(){ (function(){
var $, $$, _a, _b, _c, _d, _e, _f, _g, a, addClass, autoHide, bar, box, cancel, change, div, f, field, fields, filter, filterAll, filterSingle, filters, inBefore, input, keydown, label, mousedown, mousemove, mouseup, move, name, option, options, position, remove, reset, save, select, tag, text, x; var $, $$, _a, _b, _c, _d, _e, _f, _g, a, addClass, autoHide, bar, box, cancel, div, f, field, fields, filter, filterAll, filterSingle, filters, inBefore, input, keydown, label, loadFilters, mousedown, mousemove, mouseup, move, name, option, options, position, remove, reset, save, saveFilters, select, tag, text, x;
var __hasProp = Object.prototype.hasOwnProperty; var __hasProp = Object.prototype.hasOwnProperty;
x = function x(path, root) { x = function x(path, root) {
root = root || document.body; root = root || document.body;
@ -184,34 +184,24 @@ display: none; \
}} }}
}; };
filterAll = function filterAll() { filterAll = function filterAll() {
var _a, _b, _c, _d, _e, _f, _g, _h, _i, compiled, field, filter, imagesCount, input, inputs, table, tables, value; var _a, _b, _c, _d, _e, _f, compiled, field, filter, imagesCount, table, tables;
//save current filters saveFilters();
//this should be in its own function to play nice with change()
filter = {};
inputs = $$('input', box);
_b = inputs;
for (_a = 0, _c = _b.length; _a < _c; _a++) {
input = _b[_a];
(value = input.value) ? (filter[input.name] = value) : null;
}
filters[select.value] = filter;
GM_setValue('filters', JSON.stringify(filters));
//better way of doing this? //better way of doing this?
compiled = {}; compiled = {};
_d = filters; _a = filters;
for (filter in _d) { if (__hasProp.call(_d, filter)) { for (filter in _a) { if (__hasProp.call(_a, filter)) {
compiled[filter] = {}; compiled[filter] = {};
_e = filters[filter]; _b = filters[filter];
for (field in _e) { if (__hasProp.call(_e, field)) { for (field in _b) { if (__hasProp.call(_b, field)) {
compiled[filter][field] = new RegExp(filters[filter][field], 'i'); compiled[filter][field] = new RegExp(filters[filter][field], 'i');
}} }}
}} }}
tables = reset(); tables = reset();
_g = tables; _d = tables;
for (_f = 0, _h = _g.length; _f < _h; _f++) { for (_c = 0, _e = _d.length; _c < _e; _c++) {
table = _g[_f]; table = _d[_c];
_i = compiled; _f = compiled;
for (filter in _i) { if (__hasProp.call(_i, filter)) { for (filter in _f) { if (__hasProp.call(_f, filter)) {
filterSingle(table, compiled[filter]) ? (table.className = filter) : null; filterSingle(table, compiled[filter]) ? (table.className = filter) : null;
}} }}
} }
@ -310,7 +300,7 @@ display: none; \
return document.body.appendChild(opt); return document.body.appendChild(opt);
} }
}; };
change = function change() { loadFilters = function loadFilters() {
var _a, _b, _c, _d, filter, input, inputs; var _a, _b, _c, _d, filter, input, inputs;
filter = filters[this.value]; filter = filters[this.value];
inputs = $$('input', box); inputs = $$('input', box);
@ -321,6 +311,18 @@ display: none; \
} }
return _a; return _a;
}; };
saveFilters = function saveFilters() {
var _a, _b, _c, filter, input, inputs, value;
filter = {};
inputs = $$('input', box);
_b = inputs;
for (_a = 0, _c = _b.length; _a < _c; _a++) {
input = _b[_a];
(value = input.value) ? (filter[input.name] = value) : null;
}
filters[select.value] = filter;
return GM_setValue('filters', JSON.stringify(filters));
};
box = tag('div'); box = tag('div');
box.id = 'box'; box.id = 'box';
box.className = GM_getValue('className', 'reply'); box.className = GM_getValue('className', 'reply');
@ -330,7 +332,8 @@ display: none; \
bar.addEventListener('mousedown', mousedown, true); bar.addEventListener('mousedown', mousedown, true);
box.appendChild(bar); box.appendChild(bar);
select = tag('select'); select = tag('select');
select.addEventListener('change', change, true); select.addEventListener('mousedown', saveFilters, true);
select.addEventListener('mouseup', loadFilters, true);
filters = JSON.parse(GM_getValue('filters', '{ "hide": {} }')); filters = JSON.parse(GM_getValue('filters', '{ "hide": {} }'));
_a = filters; _a = filters;
for (filter in _a) { if (__hasProp.call(_a, filter)) { for (filter in _a) { if (__hasProp.call(_a, filter)) {
@ -353,7 +356,7 @@ display: none; \
div.appendChild(label); div.appendChild(label);
box.appendChild(div); box.appendChild(div);
} }
change.call(select); loadFilters.call(select);
div = tag('div'); div = tag('div');
div.className = 'bottom'; div.className = 'bottom';
_f = ['apply', 'reset', 'options', 'autohide']; _f = ['apply', 'reset', 'options', 'autohide'];