Skip to content

Instantly share code, notes, and snippets.

@derekpeterson
Created November 1, 2016 21:04
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 derekpeterson/74740c192dc66122fa4fcda0d390d651 to your computer and use it in GitHub Desktop.
Save derekpeterson/74740c192dc66122fa4fcda0d390d651 to your computer and use it in GitHub Desktop.
GreaseMonkey script to undo HN's contrast effects
// ==UserScript==
// @name HN font-color
// @namespace hackerNewsFix
// @include https://news.ycombinator.com
// @include https://news.ycombinator.com/*
// @version 1
// @grant none
// ==/UserScript==
var comments = Array.from(document.querySelectorAll('span[class^=c]:not(.comhead)'));
var rgb = /rgba?\((\d+),\s*(\d+),\s*(\d+)\)/;
var black = '#000';
comments.forEach(function (el) {
var className = el.classList[0];
var styles = window.getComputedStyle(el);
var color = styles.color;
var hexColor = rgbToHex(color);
el.style.color = black;
if (hexColor === black) return;
var ageEl = el.parentElement.parentElement.querySelectorAll('.age')[0];
var div = document.createElement('span');
div.textContent = ' | ' + hexColor + ' | ';
div.title = 'color class is ' + className;
ageEl.before(div);
});
function rgbToHex (color) {
var match = rgb.exec(color);
if (!match || match.length < 4) return null;
return '#' + match.slice(1).map(function (n) {
if (n.length === 1) {
n = '0' + n;
}
n = parseInt(n);
return n.toString(16);
})
.join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment