BlueCat Address Manager Table Quick-Filter

Add a quick filter to visible Table content in BlueCat Address Manager

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        BlueCat Address Manager Table Quick-Filter
// @namespace   *
// @description Add a quick filter to visible Table content in BlueCat Address Manager
// @include     */app*
// @license		MIT
// @version     1
// @grant       none
// @copyright   2019, Marius Galm
// @license		MIT
// @icon        https://www.bluecatnetworks.com/wp-content/uploads/2018/03/cropped-bluecat-favicon-32x32.png
// @require     http://code.jquery.com/jquery-latest.js
// ==/UserScript==

if (document.readyState === "interactive" ) {
    var topBar = document.getElementsByClassName('value-table-topToolBar')[0];
    var tBody = topBar.getElementsByTagName('tbody')[2];
    var tR = tBody.getElementsByTagName('tr')[0];
    var w = tR.insertCell(-1);
    w.innerHTML='<div class="separator"></div>';
    var x = tR.insertCell(-1);
    x.innerHTML='<td><form action="#" method="get"><div class="input-group"><span class="title-center"><b> Quick Filter: </b></span><input autocomplete="off" class="form-control" id="system-search" name="q" placeholder=" Type to filter..." required=""></div></form></td>';
    var y = tR.insertCell(-1);
    y.innerHTML='<td><div id="qcontent"></div></td>';
}

$(document).ready(function() {
    var activeSystemClass = $('.list-group-item.active');
    var qcontent = $('#qcontent');

    //something is entered in search form
    $('#system-search').keyup( function() {
       var that = this;
        // affect all table rows on in systems table
        var tableBody = $('#outerTable tbody:first');
        var tableRowsClass = $('#outerTable tbody:first > tr').not(':first').not('th');
        $('.search-sf').remove();
        tableRowsClass.each( function(i, val) {
            //Lower text for case insensitive
            var rowText = $(val).text().toLowerCase();
            var inputText = $(that).val().toLowerCase();
            if(inputText != '')
            {
                $('.search-query-sf').remove();
                 qcontent.prepend('<span style="padding-left: 5px;" class="search-query-sf"><strong>Searching for: "'
                     + $(that).val()
                     + '"</strong></span>');
            }
            else
            {
                $('.search-query-sf').remove();
            }

            if( rowText.indexOf( inputText ) == -1 )
            {
                //hide rows
                tableRowsClass.eq(i).hide();
            }
            else
            {
                $('.search-sf').remove();
                tableRowsClass.eq(i).show();
            }
        });
        //all tr elements are hidden
        if(tableRowsClass.children(':visible').length == 0)
        {
            tableBody.append('<tr class="search-sf"><td class="text-muted" colspan="6">No entries found.</td></tr>');
        }
    });
});