Demagog procent

Wyświetla procent koło liczby wypowiedzi

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Demagog procent
// @namespace    http://tampermonkey.net/
// @version      2025-06-16
// @description  Wyświetla procent koło liczby wypowiedzi
// @author       MZKNEK
// @match        https://demagog.org.pl/osoba/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=org.pl
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    function extractAndDisplay() {
        let trueCount = 0;
        let falseCount = 0;

        const items = document.querySelectorAll("li[data-number]");
        if (items.length === 0) return;

        items.forEach(item => {
            const span = item.querySelector("span");
            if (!span) return;

            const match = span.textContent.match(/(Prawda|Częściowa prawda|Fałsz|Manipulacja)\s*-\s*(\d+)/i);
            if (match) {
                const type = match[1].toLowerCase();
                const value = parseInt(match[2], 10);

                if (type === "prawda" || type === "częściowa prawda") {
                    trueCount += value;
                } else if (type === "fałsz" || type === "manipulacja") {
                    falseCount += value;
                }
            }
        });

        const total = trueCount + falseCount;
        const percent = total > 0 ? (trueCount / total * 100).toFixed(1) : "0.0";

        let color = "#F9CA51";
        if (percent > 75) color = "#089B16";
        else if (percent < 35) color = "#B90000";

        const counterSpan = document.querySelector('.dg-post-checked-statements__checked-counter');
        if (!counterSpan) return;

        let existingPercentSpan = document.querySelector('.dg-truth-percent');
        if (!existingPercentSpan) {
            existingPercentSpan = document.createElement("span");
            existingPercentSpan.className = "dg-truth-percent";
            existingPercentSpan.style.marginLeft = "8px";
            existingPercentSpan.style.fontWeight = "bold";
            counterSpan.insertAdjacentElement("afterend", existingPercentSpan);
        }

        existingPercentSpan.textContent = `(${percent}%)`;
        existingPercentSpan.style.color = color;
    }

    setInterval(extractAndDisplay, 1000);
})();