Hacker News - Most upvoted & most commented links

Show top 🔥👄 links of Hacker News

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

"use strict";
/* globals jQuery, $, waitForKeyElements */
// ==UserScript==
// @name         Hacker News - Most upvoted & most commented links
// @namespace    https://github.com/scambier/userscripts
// @author       Simon Cambier
// @version      0.0.10
// @description  Show top 🔥👄 links of Hacker News
// @license      ISC
// @require      https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js
// @match        https://news.ycombinator.com/
// @match        https://news.ycombinator.com/ask*
// @match        https://news.ycombinator.com/news*
// @match        https://news.ycombinator.com/show*
// @match        https://news.ycombinator.com/front*
// @grant        none
// @run-at       document-end
// ==/UserScript==
(() => {
    // Firefox mobile fix, do nothing if icons are already injected
    if ([...$('[data-userscript="scambier"]')].length)
        return;
    const rows = [...$("tr.athing")];
    // Select lines
    const items = rows
        // Filter out ads
        .filter((tr) => $(tr).find("td.votelinks").length)
        // Get id and score
        .map((tr) => {
        var _a, _b;
        return {
            id: $(tr).attr("id"),
            score: Number((_a = $(tr).next().find(".score")[0].textContent) === null || _a === void 0 ? void 0 : _a.split(" ")[0]),
            // Weirdly, .split(' ') does not work
            comments: Number((_b = $(tr)
                .next()
                .find('a:contains("comments")')
                .text()
                .split("comments")[0]
                .trim()) !== null && _b !== void 0 ? _b : 0),
        };
    });
    // Top 10% for new entries, top 20% for other pages
    const ratio = location.href.includes("news.ycombinator.com/newest")
        ? 0.1
        : 0.2;
    // Inject icons
    items.forEach((o) => {
        const title = $(`tr#${o.id}`).find("span.titleline");
        if (getTop(items, "comments", ratio).includes(o) && o.comments > 0) {
            title.before('<span title="Most commented" data-userscript="scambier">👄 </span>');
        }
        if (getTop(items, "score", ratio).includes(o) && o.score > 0) {
            title.before('<span title="Most upvoted" data-userscript="scambier">🔥 </span>');
        }
    });
    /**
     * Get [ratio] best [items], ordered by [key]
     *
     * @param items
     * @param key
     * @param ratio
     */
    function getTop(items, key, ratio) {
        const count = rows.length;
        return [...items].sort((a, b) => b[key] - a[key]).slice(0, count * ratio);
    }
})();