Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adds an estimate of "hotness" to the question sidebar, calculated using the formula from http://meta.stackexchange.com/a/61343. Questions with a high hotness value may be selected for the Hot Network Questions list. Note that the hotness value displayed by this script does not include the per-site scaling factors, and so does not match the "arbi…
// ==UserScript==
// @name Stack Exchange hotness estimator
// @namespace http://vyznev.net/
// @description Estimates how highly each Stack Exchange question would rank on the Hot Network Questions list
// @author Ilmari Karonen
// @version 0.3.3
// @license Public domain
// @homepageURL http://meta.stackexchange.com/a/284933
// @match *://*.stackexchange.com/questions/*
// @match *://*.stackoverflow.com/questions/*
// @match *://*.superuser.com/questions/*
// @match *://*.serverfault.com/questions/*
// @match *://*.stackapps.com/questions/*
// @match *://*.mathoverflow.net/questions/*
// @match *://*.askubuntu.com/questions/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var voteCount = document.querySelector('#question .js-vote-count');
var creationTimeStamp = document.querySelector('#qinfo .label-key[title^="20"][title$=Z]');
if ( ! voteCount || ! creationTimeStamp ) return;
var now = new Date ();
var questionScore = Number(voteCount.textContent);
var qCreationTime = new Date(creationTimeStamp.getAttribute('title'));
var qAgeInHours = (now.getTime() - qCreationTime.getTime()) / (1000*60*60);
var answerScores = document.querySelectorAll('.answer:not(.deleted-answer) .js-vote-count');
var answerCount = answerScores.length;
var answerScore = 0;
for (var i = 0; i < answerScores.length; i++) answerScore += Number(answerScores[i].textContent);
// http://meta.stackexchange.com/questions/60756/how-do-the-arbitrary-hotness-points-work-on-the-new-stack-exchange-home-page
// The conversion to percentages below is completely arbitrary, but seems to yield reasonable-looking values (i.e. around 100% for actual HNQs).
var hotness = ((Math.min(answerCount, 10) * questionScore) / 5 + answerScore) / Math.pow(Math.max(qAgeInHours + 1, 6), 1.4);
var oldRow = document.querySelector('#qinfo tr'), newRow = oldRow.cloneNode(true);
var cells = newRow.querySelectorAll('td');
cells[0].innerHTML = '<p class="label-key">hotness</p>';
cells[1].innerHTML = '<p class="label-key" title="The relative hotness score of this question is approximately ' + hotness.toPrecision(5) + '."><b>' + Math.round(100 * hotness) + '%</b></p>';
oldRow.parentNode.appendChild(newRow);
} )();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.