Skip to content

Instantly share code, notes, and snippets.

@lpimem
Last active September 26, 2022 16:24
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 lpimem/57c082dcfcdf3ae075706e5bebce0f56 to your computer and use it in GitHub Desktop.
Save lpimem/57c082dcfcdf3ae075706e5bebce0f56 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Hacker News highlighter
// @namespace http://tampermonkey.net/
// @version 0.2
// @description none
// @author lpimem
// @match https://news.ycombinator.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
+ function () {
function color(sp, c) {
let r1 = sp.parentElement.parentElement.parentElement;
let r2 = r1.previousElementSibling;
[r1, r2].forEach((v)=>{
v.style.backgroundColor = c;
});
};
function highlight(score, sp) {
if (score < 100) {
return;
}
if (score < 200) {
color(sp, '#DFD');
} else if (score < 500) {
color(sp, '#DFF');
} else if (score < 1000) {
color(sp, '#FDD');
} else {
color(sp, '#F99');
}
};
let scores = document.getElementsByClassName("score");
for (let i = 0; i < scores.length; i++) {
let score = Number(/(\d+).*/.exec(scores[i].innerText)[1]);
highlight(score, scores[i]);
};
return null;
}();
})();
@lpimem
Copy link
Author

lpimem commented May 20, 2017

Install for Greasemonkey or Tampermonkey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment