Skip to content

Instantly share code, notes, and snippets.

@adriendumont
Forked from kristopolous/hn_seach.js
Last active August 29, 2015 14:27
Show Gist options
  • Save adriendumont/9268fed0482ce351b79a to your computer and use it in GitHub Desktop.
Save adriendumont/9268fed0482ce351b79a to your computer and use it in GitHub Desktop.

Revisions

  1. @kristopolous kristopolous revised this gist Aug 6, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion hn_seach.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    function query() {
    var
    total = 0, shown = 0,
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c00')),
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c00,.cdd')),
    query_list = Array.prototype.slice.call(arguments);

    // turn them all off
  2. @kristopolous kristopolous renamed this gist Aug 4, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @kristopolous kristopolous created this gist Aug 4, 2015.
    39 changes: 39 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    function query() {
    var
    total = 0, shown = 0,
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c00')),
    query_list = Array.prototype.slice.call(arguments);

    // turn them all off
    job_list.forEach(function(node) {
    node.parentNode.parentNode.parentNode.style.display = 'none';
    total ++;
    });

    query_list.forEach(function(query) {
    if (query.forEach) {
    var and_query_list = query.map(function(what) { return what.toLowerCase(); });

    job_list.forEach(function(node) {
    var doesMatch = true, toTest = node.innerHTML.toLowerCase();
    and_query_list.forEach(function(query) {
    doesMatch &= (toTest.search(query) > -1);
    })
    if(doesMatch) {
    node.parentNode.parentNode.parentNode.style.display = 'block';
    shown ++;
    }
    });

    } else {
    query = query.toLowerCase();
    job_list.forEach(function(node) {
    if(node.innerHTML.toLowerCase().search(query) !== -1) {
    node.parentNode.parentNode.parentNode.style.display = 'block';
    shown ++;
    }
    });
    }
    });
    return {shown: shown, total: total}
    }