Created
July 20, 2019 16:41
-
-
Save maurizi/65ea6676cbd94451b1846048a864b636 to your computer and use it in GitHub Desktop.
Hide old news on HN
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
// ==UserScript== | |
// @name Hide old news | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Hides old articles on Hacker News | |
// @author Mike M | |
// @match https://news.ycombinator.com/ | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function addGlobalStyle (css) { | |
var head, style | |
head = document.getElementsByTagName('head')[0] | |
if (!head) { return } | |
style = document.createElement('style') | |
style.type = 'text/css' | |
style.innerHTML = css | |
head.appendChild(style) | |
} | |
addGlobalStyle('tr.old-news:not(:hover), tr.old-news:not(:hover) + tr, tr.old-news:not(:hover) + tr + tr { opacity: 0.1; }'); | |
document.querySelectorAll('.storylink').forEach(node => { | |
if (/\(\d+\)/.test(node.textContent)) { | |
const tr = node.closest('tr'); | |
tr.classList.add('old-news'); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment