Skip to content

Instantly share code, notes, and snippets.

@ivmirx
Last active June 16, 2024 18:03
Show Gist options
  • Save ivmirx/66a0015884d44297ea05a8c54d93566d to your computer and use it in GitHub Desktop.
Save ivmirx/66a0015884d44297ea05a8c54d93566d to your computer and use it in GitHub Desktop.
Filter for hckrnews.com (Chromium and Firefox extension)
var words = [
'php', 'js', 'css', 'html', 'java', 'ruby', 'rust', 'golang', 'kotlin', 'perl',
'elixir', 'elm ', 'erlang', 'clojure', 'lisp', 'racket', 'scala',
'mozilla', 'firefox', 'mysql', 'mongo', 'latex', 'webgl',
'kubernetes', 'docker', 'tensor', 'graphql', ' ml ', 'machine learning', 'artificial intelligence', 'ai ',
'google', 'facebook', 'amazon', 'aws ', 'dell', 'amd', 'verizon', 'airbnb', 'uber', 'tesla', 'spacex', 'self-driving',
'fundraising', 'investor', 'venture', 'unicorn', 'billionaire', 'musk', 'bezos', 'bill gates',
'bitcoin', 'btc', 'ethereum', 'blockchain', 'cryptocurrenc',
'francisco', 'new york', 'california', 'bay area', 'texas', 'florida', 'wall street',
'politics', 'u.s.', 'white house', 'federal', 'president', 'congress', 'senate', 'scotus', 'court', 'police', 'military', 'fbi', 'cia', 'nsa', 'immigration', 'democracy', 'election', 'mayor', 'trump', 'biden',
'nato', 'russia', 'ukrain', 'china', 'chinese', 'gaza', 'palestin', 'israel', 'idf', 'nazi', 'terrorist',
'guardian', 'vox', 'forbes', 'bbc', 'cnn', 'fox news', 'new york times', 'nyt', 'reuters'];
function filter(list) {
var entries = list.getElementsByClassName('entry row');
var filteredEntries = [];
for (var i = entries.length - 1; i >= 0; i--) {
var link = entries[i].getElementsByClassName('link span15 story')[0];
if (link == null)
continue;
var text = link.innerText.toLowerCase();
for (var j = words.length - 1; j >= 0; j--) {
if (text.indexOf(words[j]) != -1) {
logEntry(entries[i], link);
filteredEntries.push(entries[i]);
break;
}
}
}
for (var i = filteredEntries.length - 1; i >= 0; i--) {
filteredEntries[i].parentNode.removeChild(filteredEntries[i]);
}
}
function logEntry(entry, link) {
var points = entry.getElementsByClassName('points')[0].innerText;
if (points < 100) {
return;
}
var commentsCount = entry.getElementsByClassName('comments')[0].innerText;
console.log(commentsCount + '/' + points + ' ' + link.innerText);
var commentsLink = entry.getElementsByClassName('hn span3 story ')[0].href;
console.log(commentsLink);
}
var entryLists = document.getElementsByClassName('entries unstyled');
for (var i = entryLists.length - 1; i >= 0; i--) {
filter(entryLists[i]);
}
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(item) {
item.addedNodes.forEach(function(node) {
filter(node);
});
});
});
var div = document.querySelector('#entries');
observer.observe(div, { childList: true });
{
"manifest_version": 3,
"name": "hckrnews.com filter",
"version": "1.0",
"description": "Filter out submissions on hckrnews.com based on keywords",
"permissions": [
"tabs"
],
"host_permissions": [
"https://hckrnews.com/"
],
"content_scripts": [
{
"matches": ["https://hckrnews.com/"],
"js": ["filter.js"]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment