Skip to content

Instantly share code, notes, and snippets.

@shawwn
Forked from sillysaurus/hn_ignorance.js
Created January 31, 2023 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawwn/ee78a1e7c60fe972ea440ea194fbb9ab to your computer and use it in GitHub Desktop.
Save shawwn/ee78a1e7c60fe972ea440ea194fbb9ab to your computer and use it in GitHub Desktop.
HN Ignorance Is Bliss
// ==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