Last active
August 29, 2015 13:57
-
-
Save theY4Kman/9645503 to your computer and use it in GitHub Desktop.
Quickly filter down and navigate to pages on Ubersmith's setup & admin page
This file contains hidden or 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
| // ==UserScript== | |
| // @name Ubersmith Quick Filters | |
| // @version 0.1 | |
| // @description enter something useful | |
| // @match https://uberdev.hivelocity.net/admin/config/ | |
| // @match https://manage.hivelocity.net/admin/config/ | |
| // @require http://code.jquery.com/jquery-latest.js | |
| // @copyright 2014 Zach "theY4Kman" Kanzler | |
| // @grant GM_unsafeWindow | |
| // ==/UserScript== | |
| $ = unsafeWindow.$; | |
| var RETURN = 13; | |
| $(function() { | |
| var $tbody, | |
| $tr, | |
| $filter, | |
| $enter_msg, | |
| groups, | |
| debounce, | |
| $matched_element, | |
| filter_func; | |
| $tbody = $('table[height="90%"] > tbody > tr > td > table > tbody'); | |
| $tr = $('<tr><td>Filter: <input type="text" id="#filter"> <span style="font-weight: bold; color: orange; display: none;">1 page matched. Press Enter to visit.</span></td></tr>'); | |
| $filter = $tr.find('input'); | |
| $enter_msg = $tr.find('span'); | |
| $tbody.prepend($tr); | |
| groups = []; | |
| $('.config-box-1').each(function(_, group_elem) { | |
| var $group, | |
| cells; | |
| $group = $(group_elem); | |
| // Grab the text from each and cache that shit | |
| cells = []; | |
| $('.CellText', $group).each(function(_, el) { | |
| var $el; | |
| $el = $(el); | |
| cells.push({ | |
| el: $el, | |
| text: $el.text().replace(/\s+/g, '').toLowerCase() | |
| }); | |
| }); | |
| groups.push({ | |
| el: $group, | |
| cells: cells | |
| }); | |
| }); | |
| $matched_element = $(); | |
| filter_func = function() { | |
| var query, | |
| terms, | |
| matched_elements, | |
| i, | |
| matched_one_element; | |
| query = $filter.val(); | |
| terms = query.trim().toLowerCase().split(/\s+/); | |
| // Keep track of which elements were matched, | |
| matched_elements = []; | |
| for (i=0; i<groups.length; i++) { | |
| var group, | |
| should_show, | |
| j; | |
| group = groups[i]; | |
| should_show = false; | |
| $.each(group.cells, function(_, cell) { | |
| for (j=0; j<terms.length; j++) { | |
| if (cell.text.indexOf(terms[j]) !== -1) { | |
| cell.el.show(); | |
| matched_elements.push(cell.el.get(0)); | |
| should_show = true; | |
| return; | |
| } | |
| } | |
| // else | |
| cell.el.hide(); | |
| }); | |
| group.el.toggle(should_show); | |
| } | |
| matched_one_element = matched_elements.length == 1; | |
| $enter_msg.toggle(matched_one_element); | |
| $matched_element = $(matched_elements); | |
| }; | |
| $filter.keydown(function(evt) { | |
| if (debounce != null) | |
| clearTimeout(debounce); | |
| if (evt.keyCode == RETURN) { | |
| filter_func(); | |
| if ($matched_element.length == 1 && evt.keyCode == 13) { | |
| $matched_element.find('a').get(0).click(); | |
| } | |
| } else { | |
| debounce = setTimeout(filter_func, 100); | |
| } | |
| }); | |
| // Focus on load | |
| $filter.focus(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment