4 ms·
Here is some code for a simple chrome ext for HN to show votes/created date/bio inline (just stick it in a chrome ext) function hackernews() { if (docume
by soheil 5y ago
Here is some code for a simple chrome ext for HN to show votes/created date/bio inline (just stick it in a chrome ext)
function hackernews() {
if (document.location.toString().indexOf('news.ycombinator') === -1) return;
document.querySelector('#hnmain td').style = 'background-color: #55b6f2;';
var i = 0;
function render(user, html) {
const div = document.createElement('div');
let style = 'cursor: text;overflow-y: scroll; height: 39px;position: absolute;border: 1px dotted #828282;width: 250px;margin-left: 250px;margin-top: -34px;background-color: #f6f6ef;';
div.innerHTML = html;
const date = div.querySelectorAll('tr')[5].querySelectorAll('td')[1].innerHTML.split(', ')[1];
const karma = div.querySelectorAll('tr')[6].querySelectorAll('td')[1].innerHTML;
const about = div.querySelectorAll('tr')[7].querySelectorAll('td')[1].innerHTML;
if (about.length < 60) {
style += 'display: flex;flex-direction: column-reverse;margin-top: -39px;border: none;background-color: transparent;';
}
div.innerHTML = about;
div.style = style;
user.querySelector('.age').innerHTML += date ? ' ' + date + ' ' + parseInt(karma).toLocaleString() : ' (x_x)';
user.appendChild(div);
}
function next() {
if (i >= document.querySelectorAll('.default .comhead').length) return;
const user = document.querySelectorAll('.default .comhead')[i++];
if (!user) return next();
const username = user.querySelector('a').href;
if (username.indexOf('soheil') !== -1) return next();
const html = localStorage.getItem(username);
if (html) {
render(user, html);
next();
return;
}
fetch(username)
.then(res => res.text())
.then(res => {
localStorage.setItem(username, res);
render(user, res);
setTimeout(next, 3000);
});
}
next();
}