Ja

JavaScript snippet to highlight new posts

Hacker News

JavaScript snippet to highlight new posts

Hi all. I wanted an easy way to highlight new posts, without basing it on the last time I visited a page. The snippet is as follows, if any of you folks would like to use it: /** * Usage: highlight('newpost', 3, 'hours'); * * This will add the class 'newpost' to any post made within * the past 3 hours. This includes, for example: * * 3 hours ago * 45 minutes ago * 22 seconds ago */ function highlight(className, number, type) { var types = ['second', 'seconds', 'minute', 'minutes', 'hour', 'hours', 'day', 'days']; // Types are inclusive, so if we filtered to 'minutes', then // we always want posts that were made 'seconds' ago. types = types.slice(0, types.indexOf(type) + 1); // Any link with 'item?id' is assumed to be a timestamp. var posts = document.querySelectorAll('a[href*="item?id"]'); // Loop through the number of posts, since we need to access // each post using NodeList#item. for(var i = 0; i < posts.length; i++) { var post = posts.item(i); try { // The leftmost integer. var label_number = parseInt(post.innerHTML.match(/^\d+/)); // The label (a value that maps up to the types array). var label_type = post.innerHTML.match(/^\d+ (.+?) ago$/)[1]; } catch(e) { // If either of the matches fail, it's due to an // irrelevant link. continue; } // Continue if the label is out of bounds. // For instance, 'days' when filtering by 'minutes'. if(types.indexOf(label_type) === -1) continue; // Continue if the label type matches, but the number // is larger than what we're filtering for. if(type === label_type && label_number > number) continue; // td > div > span > a post.parentNode.parentNode.parentNode.className += ' ' + className; } }

Share card

Actual performance

2points
1comments
Did not reach leaderboard

Launch Intel predictions

Analyze your own launch →
Product HuntOn track for Day 1 leaderboard · Strong signals: new, using · Missing: mac, agents, macos
62%62% predicted probability of success on Product Hunt, based on ML models trained on real launch data.
best fitHighest predicted score across all platforms for this description.
Indie HackersFits the IH revenue-focused audience · Missing: supports, reddit linkedin, podcasting
59%59% predicted probability of success on Indie Hackers, based on ML models trained on real launch data.
TrustMRRFits verified-revenue profile · Strong signals: way · Missing: mobile apps, ios, personal
51%51% predicted probability of success on TrustMRR, based on ML models trained on real launch data.
AppSumoMay struggle as an AppSumo deal · Missing: plus, platform, intuitive
43%43% predicted probability of success on AppSumo, based on ML models trained on real launch data.
Hacker NewsMay not resonate with HN audience · Strong signals: io · Missing: https docs, excited, just released
41%41% predicted probability of success on Hacker News, based on ML models trained on real launch data.
nativeThis product was originally launched on this platform.
Acquire.comPre-revenue stage for this audience · Strong signals: arr · Missing: mrr, revenue, profit
22%22% predicted probability of success on Acquire.com, based on ML models trained on real launch data.
BetaListMay not resonate with beta-testers · Missing: web3, chat, crypto
1%1% predicted probability of success on BetaList, based on ML models trained on real launch data.

Correct prediction on native model

Similar products

Ex
Extension to highlight new posts on HN frontpage since your last visit38%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Extension to highlight new posts on HN frontpage since your last visit

Hacker News2
Ex
Extension to highlight new posts on HN frontpage since your last visit38%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Extension to highlight new posts on HN frontpage since your last visit

Hacker News1
Ex
Extension to highlight new posts on HN frontpage since your last visit38%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Extension to highlight new posts on HN frontpage since your last visit

Hacker News1
Ex
Extension to Highlight new posts on HN frontpage since your last visit38%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Extension to Highlight new posts on HN frontpage since your last visit

Hacker News1
A
A new EventEmitter for Deno ( and every other JavaScript runtimes)46%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

A new EventEmitter for Deno ( and every other JavaScript runtimes)

Hacker News2
Ja
JavaScript is the new Punk Rock50%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

JavaScript is the new Punk Rock

Hacker News1
Ne
New HN titles JavaScript app without dependencies40%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

New HN titles JavaScript app without dependencies

Hacker News4
Ne
New async JavaScript paradime with async generator and async iteration38%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

New async JavaScript paradime with async generator and async iteration

Hacker News3
Ja
JavaScript Snippet for removing ?utm_ from URLs after they've loaded39%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

JavaScript Snippet for removing ?utm_ from URLs after they've loaded

Hacker News1
A
A new language that merges FORTH and Javascript61%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

A new language that merges FORTH and Javascript

Hacker News10