Last active
March 29, 2019 02:14
-
-
Save briankung/c970ce4d998a7af496093186edc517cc to your computer and use it in GitHub Desktop.
lobste.rs top level comment search using the root level comment input. If you're using the bookmarklet, save it as a bookmark and then click it once when you want to search top-level comments. Otherwise just copy the contents into console.
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
javacript:void((() => { | |
const topLevelComments = [...document.querySelectorAll('ol.comments > li > div')].slice(1), | |
hide = (node) => { node.closest('li').style.display = 'none' }, | |
show = (node) => { node.closest('li').style.display = null }, | |
reset = () => { topLevelComments.forEach(show) }; | |
window.query = (query) => { | |
// Convenient for using it as an event handler | |
if (query && query.target) { query = query.target.value } | |
// If it's empty string or falsy value, just reset everything | |
if (!query) return reset() | |
// Stole this from the hn search.js console snippet: | |
// https://gist.github.com/kristopolous/19260ae54967c2219da8#file-hn_seach-js-L26 | |
// just turns strings into case-insensitive Regexes | |
query = query.test ? query : new RegExp(query.toString(), 'i') | |
topLevelComments.filter((el) => !query.test(el.innerText)).forEach(hide) | |
} | |
// Hijacking the top comment textarea because I am lazy and it's a nicer interface than going into console | |
document.getElementById('comment').onkeyup = window.query | |
})()) |
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
javascript:void((()=>{const e=[...document.querySelectorAll("ol.comments > li > div")].slice(1),t=e=>{e.closest("li").style.display="none"},l=e=>{e.closest("li").style.display=null};window.query=(n=>{n&&n.target&&(n=n.target.value),n?(n=n.test?n:new RegExp(n.toString(),"i"),e.filter(e=>!n.test(e.innerText)).forEach(t)):e.forEach(l)}),document.getElementById("comment").onkeyup=window.query})()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment