Last active
September 26, 2022 16:24
-
-
Save lpimem/57c082dcfcdf3ae075706e5bebce0f56 to your computer and use it in GitHub Desktop.
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 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; | |
}(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install for Greasemonkey or Tampermonkey