Last active
August 29, 2015 14:19
-
-
Save avalanchy/049b16c287a6763bf89b 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 - Score like reddit | |
// @namespace http://avalanchy.tk/ | |
// @version 0.1 | |
// @description Swap score with the position | |
// @author avalanchy | |
// @match https://news.ycombinator.com/* | |
// @grant none | |
// ==/UserScript== | |
var ranks = document.getElementsByClassName('rank'); | |
var scores = document.getElementsByClassName('score'); | |
var subtexts = document.getElementsByClassName('subtext'); | |
var max_score = 0; | |
for (var i=0; i<ranks.length; i++) { | |
var rank = ranks[i]; | |
var score = scores[i]; | |
var subtext = subtexts[i]; | |
var score_text = '0 points'; | |
var rank_td = rank.parentElement; | |
var under_rank_td = subtext.previousSibling; | |
rank_td.rowSpan = 2; | |
rank_td.align = 'center'; | |
under_rank_td.colSpan = 1; | |
if (!!score) { | |
var score_text = score.innerHTML; | |
score.innerHTML = i + '.'; | |
} | |
rank.innerHTML = score_text.replace(/ points?/, ''); | |
var int_score = parseInt(rank.innerText); | |
if (int_score > max_score) { | |
max_score = int_score; | |
} | |
} | |
for (var i=0; i<ranks.length; i++) { | |
var rank = ranks[i]; | |
var int_score = parseInt(rank.innerText); | |
rank.style.opacity = (0.5*max_score+int_score)/max_score; | |
} |
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
// best looks with "Hacker News - Light Theme" https://userstyles.org/styles/89773/hacker-news-light-theme | |
span.rank { | |
padding: 4px; | |
background-color: #f60; | |
color: #fff; | |
display: list-item; | |
margin-top: 4px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment