Skip to content

Instantly share code, notes, and snippets.

@Cosmeen
Created May 30, 2018 13:24
Show Gist options
  • Save Cosmeen/5ee606c2ce1d9116016fed538ed47459 to your computer and use it in GitHub Desktop.
Save Cosmeen/5ee606c2ce1d9116016fed538ed47459 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name yc
// @namespace yc
// @include https://news.ycombinator.com/*
// @version 0.1
// @grant GM_addStyle
// ==/UserScript==
GM_addStyle(" \
.ind { \
border-right: 1px dotted #cccccc; \
position: relative; \
} \
.ind::before { \
color: #cccccc; \
content: '^'; \
font-size: 10px; \
position: absolute; \
right: -4px; \
top: -3px; \
} \
.subtext a.high {background: #f38a8ae6;color: #fff;} \
.subtext a.medium {background: #ec8e34e6;color: #fff;} \
");
(function() {
if (window.location == "https://news.ycombinator.com/news"){
computeAvgCommentNr();
}
function computeAvgCommentNr(){
var commentsArray = [];
var comments = [];
var commentsNumbers = [];
commentsArray = document.querySelectorAll('td.subtext a:nth-of-type(3n)');
for(var i=0; i<commentsArray.length; i++){
comments.push({"comments":commentsArray[i].textContent.replace("comments", "").slice(0,-1), "id": i});
}
for(var i=0; i<commentsArray.length; i++){
commentsNumbers.push(commentsArray[i].textContent.replace("comments", "").slice(0,-1));
}
console.log(avg(commentsNumbers));
}
/*
*
* helper functions
*
*/
/*
return average from an Array of numbers
*/
function avg(elmt){
var sum = 0;
for(var i = 0; i < elmt.length; i++){
sum += parseInt( elmt[i], 10 );
}
return Math.round(sum/elmt.length);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment