Skip to content

Instantly share code, notes, and snippets.

@bleuarg
Forked from kristopolous/hn_seach.js
Created September 25, 2017 17:36
Show Gist options
  • Save bleuarg/fe24ab2b0756c4a01f7f3c7bc41a65d2 to your computer and use it in GitHub Desktop.
Save bleuarg/fe24ab2b0756c4a01f7f3c7bc41a65d2 to your computer and use it in GitHub Desktop.

Revisions

  1. @kristopolous kristopolous revised this gist Aug 1, 2016. 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
    @@ -7,7 +7,7 @@ function query() {

    // Traverses up the dom stack trying to find a match of a specific class
    function up_to(node, klass) {
    if (node.className === klass) {
    if (node.classList.contains(klass)) {
    return node;
    }
    if(node === document.body) {
  2. @kristopolous kristopolous revised this gist Mar 1, 2016. 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
    @@ -54,7 +54,7 @@ function query() {
    query = destring(query);

    job_list.forEach(function(node) {
    if(node.innerHTML.search(query) !== -1) {
    if(node.innerHTML.search(query) > -1) {
    display(node, 'block');
    shown ++;
    }
  3. @kristopolous kristopolous revised this gist Mar 1, 2016. 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
    @@ -41,7 +41,7 @@ function query() {
    toTest = node.innerHTML;

    and_query_list.forEach(function(query) {
    doesMatch &= (toTest.search(query) > -1);
    doesMatch &= toTest.search(query) > -1;
    })

    if(doesMatch) {
  4. @kristopolous kristopolous revised this gist Mar 1, 2016. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions hn_seach.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    function query() {
    var
    shown = 0, total = 0,
    // HN is done with very unsemantic classes.
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c5a,.cae,.c00,.c9c,.cdd,.c73,.c88')),
    query_list = Array.prototype.slice.call(arguments);
    query_list = Array.prototype.slice.call(arguments),
    shown = 0, total = job_list.length;

    // Traverses up the dom stack trying to find a match of a specific class
    function up_to(node, klass) {
    @@ -29,7 +29,6 @@ function query() {
    // Hide all the postings
    job_list.forEach(function(node) {
    display(node, 'none');
    total ++;
    });

    query_list.forEach(function(query) {
  5. @kristopolous kristopolous revised this gist Mar 1, 2016. 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,6 +1,6 @@
    function query() {
    var
    total = 0, shown = 0,
    shown = 0, total = 0,
    // HN is done with very unsemantic classes.
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c5a,.cae,.c00,.c9c,.cdd,.c73,.c88')),
    query_list = Array.prototype.slice.call(arguments);
  6. @kristopolous kristopolous revised this gist Mar 1, 2016. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions hn_seach.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ function query() {
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c5a,.cae,.c00,.c9c,.cdd,.c73,.c88')),
    query_list = Array.prototype.slice.call(arguments);

    // This traverses up the dom stack trying to find a match of a specific class
    // Traverses up the dom stack trying to find a match of a specific class
    function up_to(node, klass) {
    if (node.className === klass) {
    return node;
    @@ -20,11 +20,13 @@ function query() {
    up_to(node, 'athing').style.display = what;
    }

    // If we have a RegEx, return it
    // Otherwise make it a case insensitive regex.
    function destring(what) {
    return what.test ? what : new RegExp(what.toString(), 'i');
    }

    // Turn them all off
    // Hide all the postings
    job_list.forEach(function(node) {
    display(node, 'none');
    total ++;
    @@ -60,5 +62,6 @@ function query() {
    });
    }
    });

    return {shown: shown, total: total}
    }
  7. @kristopolous kristopolous revised this gist Mar 1, 2016. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions hn_seach.js
    Original file line number Diff line number Diff line change
    @@ -20,6 +20,10 @@ function query() {
    up_to(node, 'athing').style.display = what;
    }

    function destring(what) {
    return what.test ? what : new RegExp(what.toString(), 'i');
    }

    // Turn them all off
    job_list.forEach(function(node) {
    display(node, 'none');
    @@ -28,9 +32,7 @@ function query() {

    query_list.forEach(function(query) {
    if (query.forEach) {
    var and_query_list = query.map(function(what) {
    return what.test ? what : new RegExp(what.toString(), 'i');
    });
    var and_query_list = query.map(destring);

    job_list.forEach(function(node) {
    var
    @@ -48,7 +50,7 @@ function query() {
    });

    } else {
    query = query.test ? query : new RegExp(query.toString(), 'i');
    query = destring(query);

    job_list.forEach(function(node) {
    if(node.innerHTML.search(query) !== -1) {
  8. @kristopolous kristopolous revised this gist Mar 1, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions hn_seach.js
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ function query() {
    query_list.forEach(function(query) {
    if (query.forEach) {
    var and_query_list = query.map(function(what) {
    return new RegExp(what.toString(), 'i');
    return what.test ? what : new RegExp(what.toString(), 'i');
    });

    job_list.forEach(function(node) {
    @@ -48,7 +48,7 @@ function query() {
    });

    } else {
    query = new RegExp(query.toString(), 'i');
    query = query.test ? query : new RegExp(query.toString(), 'i');

    job_list.forEach(function(node) {
    if(node.innerHTML.search(query) !== -1) {
  9. @kristopolous kristopolous revised this gist Sep 2, 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
    @@ -51,7 +51,7 @@ function query() {
    query = new RegExp(query.toString(), 'i');

    job_list.forEach(function(node) {
    if(node.innerHTML.toLowerCase().search(query) !== -1) {
    if(node.innerHTML.search(query) !== -1) {
    display(node, 'block');
    shown ++;
    }
  10. @kristopolous kristopolous revised this gist Sep 2, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions hn_seach.js
    Original file line number Diff line number Diff line change
    @@ -19,13 +19,13 @@ function query() {
    function display(node, what) {
    up_to(node, 'athing').style.display = what;
    }

    // Turn them all off
    job_list.forEach(function(node) {
    display(node, 'none');
    total ++;
    });

    query_list.forEach(function(query) {
    if (query.forEach) {
    var and_query_list = query.map(function(what) {
    @@ -35,7 +35,7 @@ function query() {
    job_list.forEach(function(node) {
    var
    doesMatch = true,
    toTest = node.innerHTML.toLowerCase();
    toTest = node.innerHTML;

    and_query_list.forEach(function(query) {
    doesMatch &= (toTest.search(query) > -1);
  11. @kristopolous kristopolous revised this gist Sep 2, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions hn_seach.js
    Original file line number Diff line number Diff line change
    @@ -16,13 +16,13 @@ function query() {
    return up_to(node.parentNode, klass);
    }

    function style(node, what) {
    function display(node, what) {
    up_to(node, 'athing').style.display = what;
    }

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

    @@ -42,7 +42,7 @@ function query() {
    })

    if(doesMatch) {
    style(node, 'block');
    display(node, 'block');
    shown ++;
    }
    });
    @@ -52,7 +52,7 @@ function query() {

    job_list.forEach(function(node) {
    if(node.innerHTML.toLowerCase().search(query) !== -1) {
    style(node, 'block');
    display(node, 'block');
    shown ++;
    }
    });
  12. @kristopolous kristopolous revised this gist Sep 2, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions hn_seach.js
    Original file line number Diff line number Diff line change
    @@ -6,18 +6,18 @@ function query() {
    query_list = Array.prototype.slice.call(arguments);

    // This traverses up the dom stack trying to find a match of a specific class
    function upTo(node, klass) {
    function up_to(node, klass) {
    if (node.className === klass) {
    return node;
    }
    if(node === document.body) {
    throw new Exception();
    }
    return upTo(node.parentNode, klass);
    return up_to(node.parentNode, klass);
    }

    function style(node, what) {
    upTo(node, 'athing').style.display = what;
    up_to(node, 'athing').style.display = what;
    }

    // Turn them all off
  13. @kristopolous kristopolous revised this gist Sep 2, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions hn_seach.js
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ function query() {
    query_list.forEach(function(query) {
    if (query.forEach) {
    var and_query_list = query.map(function(what) {
    return what.toLowerCase ? what.toLowerCase() : what;
    return new RegExp(what.toString(), 'i');
    });

    job_list.forEach(function(node) {
    @@ -48,7 +48,7 @@ function query() {
    });

    } else {
    query = query.toLowerCase ? query.toLowerCase() : query;
    query = new RegExp(query.toString(), 'i');

    job_list.forEach(function(node) {
    if(node.innerHTML.toLowerCase().search(query) !== -1) {
    @@ -59,4 +59,4 @@ function query() {
    }
    });
    return {shown: shown, total: total}
    }
    }
  14. @kristopolous kristopolous revised this gist Sep 2, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions hn_seach.js
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ function query() {
    query_list.forEach(function(query) {
    if (query.forEach) {
    var and_query_list = query.map(function(what) {
    return what.toLowerCase();
    return what.toLowerCase ? what.toLowerCase() : what;
    });

    job_list.forEach(function(node) {
    @@ -48,7 +48,7 @@ function query() {
    });

    } else {
    query = query.toLowerCase();
    query = query.toLowerCase ? query.toLowerCase() : query;

    job_list.forEach(function(node) {
    if(node.innerHTML.toLowerCase().search(query) !== -1) {
  15. @kristopolous kristopolous revised this gist Sep 2, 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
    @@ -2,7 +2,7 @@ function query() {
    var
    total = 0, shown = 0,
    // HN is done with very unsemantic classes.
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c5a,.c00,.c9c,.cdd,.c73,.c88')),
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c5a,.cae,.c00,.c9c,.cdd,.c73,.c88')),
    query_list = Array.prototype.slice.call(arguments);

    // This traverses up the dom stack trying to find a match of a specific class
  16. @kristopolous kristopolous revised this gist Sep 1, 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
    @@ -2,7 +2,7 @@ function query() {
    var
    total = 0, shown = 0,
    // HN is done with very unsemantic classes.
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c5a,.c00,.cdd,.c73,.c88')),
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c5a,.c00,.c9c,.cdd,.c73,.c88')),
    query_list = Array.prototype.slice.call(arguments);

    // This traverses up the dom stack trying to find a match of a specific class
  17. @kristopolous kristopolous revised this gist Sep 1, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions hn_seach.js
    Original file line number Diff line number Diff line change
    @@ -36,9 +36,11 @@ function query() {
    var
    doesMatch = true,
    toTest = node.innerHTML.toLowerCase();

    and_query_list.forEach(function(query) {
    doesMatch &= (toTest.search(query) > -1);
    })

    if(doesMatch) {
    style(node, 'block');
    shown ++;
  18. @kristopolous kristopolous revised this gist Sep 1, 2015. 1 changed file with 6 additions and 7 deletions.
    13 changes: 6 additions & 7 deletions hn_seach.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,10 @@
    function query() {
    var
    total = 0, shown = 0,
    // HN is done with very unsemantic classes.
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c5a,.c00,.cdd,.c73,.c88')),
    query_list = Array.prototype.slice.call(arguments);

    // This traverses up the dom stack trying to find a match of a specific class
    function upTo(node, klass) {
    if (node.className === klass) {
    @@ -13,13 +19,6 @@ function query() {
    function style(node, what) {
    upTo(node, 'athing').style.display = what;
    }


    var
    total = 0, shown = 0,
    // hn is done with very unsemantic classes.
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c5a,.c00,.cdd,.c73,.c88')),
    query_list = Array.prototype.slice.call(arguments);

    // Turn them all off
    job_list.forEach(function(node) {
  19. @kristopolous kristopolous revised this gist Sep 1, 2015. 1 changed file with 15 additions and 7 deletions.
    22 changes: 15 additions & 7 deletions hn_seach.js
    Original file line number Diff line number Diff line change
    @@ -8,17 +8,22 @@ function query() {
    throw new Exception();
    }
    return upTo(node.parentNode, klass);
    }
    }

    function style(node, what) {
    upTo(node, 'athing').style.display = what;
    }


    var
    total = 0, shown = 0,
    // hn is done with very unsemantic classes.
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c5a,.c00,.cdd,.c73,.c88')),
    query_list = Array.prototype.slice.call(arguments);

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

    @@ -29,25 +34,28 @@ function query() {
    });

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

    } else {
    query = query.toLowerCase();

    job_list.forEach(function(node) {
    if(node.innerHTML.toLowerCase().search(query) !== -1) {
    upTo(node, 'athing').style.display = 'block';
    style(node, 'block');
    shown ++;
    }
    });
    }
    });
    return {shown: shown, total: total}
    }
    }
  20. @kristopolous kristopolous revised this gist Sep 1, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions hn_seach.js
    Original file line number Diff line number Diff line change
    @@ -2,10 +2,10 @@ function query() {
    // This traverses up the dom stack trying to find a match of a specific class
    function upTo(node, klass) {
    if (node.className === klass) {
    return node;
    return node;
    }
    if(node === document.body) {
    throw new Exception();
    throw new Exception();
    }
    return upTo(node.parentNode, klass);
    }
    @@ -25,7 +25,7 @@ function query() {
    query_list.forEach(function(query) {
    if (query.forEach) {
    var and_query_list = query.map(function(what) {
    return what.toLowerCase();
    return what.toLowerCase();
    });

    job_list.forEach(function(node) {
  21. @kristopolous kristopolous revised this gist Sep 1, 2015. 1 changed file with 20 additions and 6 deletions.
    26 changes: 20 additions & 6 deletions hn_seach.js
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,40 @@
    function query() {
    // This traverses up the dom stack trying to find a match of a specific class
    function upTo(node, klass) {
    if (node.className === klass) {
    return node;
    }
    if(node === document.body) {
    throw new Exception();
    }
    return upTo(node.parentNode, klass);
    }

    var
    total = 0, shown = 0,
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c00,.cdd,.c88')),
    // hn is done with very unsemantic classes.
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c5a,.c00,.cdd,.c73,.c88')),
    query_list = Array.prototype.slice.call(arguments);

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

    query_list.forEach(function(query) {
    if (query.forEach) {
    var and_query_list = query.map(function(what) { return what.toLowerCase(); });
    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';
    upTo(node, 'athing').style.display = 'block';
    shown ++;
    }
    });
    @@ -29,11 +43,11 @@ function query() {
    query = query.toLowerCase();
    job_list.forEach(function(node) {
    if(node.innerHTML.toLowerCase().search(query) !== -1) {
    node.parentNode.parentNode.parentNode.style.display = 'block';
    upTo(node, 'athing').style.display = 'block';
    shown ++;
    }
    });
    }
    });
    return {shown: shown, total: total}
    }
    }
  22. @kristopolous kristopolous revised this gist Sep 1, 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,.cdd')),
    job_list = Array.prototype.slice.call(document.querySelectorAll('.c00,.cdd,.c88')),
    query_list = Array.prototype.slice.call(arguments);

    // turn them all off
  23. @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
  24. @kristopolous kristopolous renamed this gist Aug 4, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  25. @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}
    }