Last active
January 31, 2023 23:49
-
-
Save sillysaurus/4d917e925548e4c7ec6f6bb96c94ef5c to your computer and use it in GitHub Desktop.
HN Ignorance Is Bliss
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 HN Ignorance Is Bliss | |
// @description Hide your comment scores and karma counters. See https://news.ycombinator.com/item?id=14456203 | |
// @author sillysaurus3 | |
// @version 1.0 | |
// @match *://news.ycombinator.com/* | |
// @grant none | |
// @downloadURL https://gist.githubusercontent.com/sillysaurus/4d917e925548e4c7ec6f6bb96c94ef5c/raw | |
// @updateURL https://gist.githubusercontent.com/sillysaurus/4d917e925548e4c7ec6f6bb96c94ef5c/raw | |
// ==/UserScript== | |
(function() { | |
var map1 = function (f, l, o) { | |
o = o || {}; | |
var r = []; | |
var more = true; | |
var done = function(x) { r = x; more = false; }; | |
for (var k in l) { | |
var i = (k.search(/^[-]?[0-9]+$/) < 0 ? null : parseInt(k)); | |
var x = f(l[k], {index: i, key: (i ? null : k), input: l, output: r, return: done}); | |
if (!more) { return r; } | |
if (o.nulls || (x != null)) { | |
r[k === i ? k : r.length] = x; | |
} | |
} | |
return r; | |
}; | |
var scramble = function (s) { return s.replace(/[0-9]/g, '9'); }; | |
// Hide comment scores. | |
var scores = document.getElementsByClassName('score'); | |
for (var i = 0; i < scores.length; i++) { | |
var x = scores[i]; | |
if (x.parentElement && x.parentElement.className === 'comhead') { | |
x.innerHTML = ''; | |
} | |
} | |
// Build a table of HN properties. | |
hnKeys = []; | |
map1(function (x,o) { | |
if (o.index !== null && x.children.length === 2) { | |
var k = x.children[0].innerHTML; | |
var v = x.children[1]; | |
hnKeys[k.length <= 0 ? hnKeys.length : k] = v; | |
} | |
}, document.querySelector('#hnmain tbody').lastElementChild.querySelectorAll('tr:not([class]) table tr')); | |
// Get the logged-in user. | |
hnUser = null; | |
map1( function (n, o) { | |
if (o.index && o.index > 0 && n.innerHTML === 'logout') { | |
hnUser = o.input[o.index-1]; | |
o.return(); | |
} | |
}, document.querySelectorAll('.pagetop a')); | |
if (hnUser) { | |
// Scramble the profile karma counter. | |
if (hnKeys['user:'] && hnKeys['karma:'] && hnKeys['user:'].firstChild.innerHTML === hnUser.innerHTML) { | |
hnKeys['karma:'].innerHTML = scramble(hnKeys['karma:'].innerHTML); | |
} | |
// Scramble the topbar karma counter. | |
var KarmaCounter = /[(][0-9]+[)]\s+[|]/; | |
map1( function (n, o) { | |
if (n.nodeType === document.TEXT_NODE && n.nodeValue.search(KarmaCounter) >= 0) { | |
n.nodeValue = scramble(n.nodeValue); | |
o.return(); | |
} | |
}, hnUser.parentElement.childNodes); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
New version that works as of Jan 2023: https://gist.github.com/shawwn/2dae1d9bc796c158139952b4678d96be