stackoverflow show user reputation in comments

stackoverflow stackexchange show user reputation in comments

Stan na 16-09-2021. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         stackoverflow show user reputation in comments
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description   stackoverflow stackexchange show user reputation in comments
// @author        批小将
// @match         https://*.stackexchange.com/*
// @match         https://stackoverflow.com/*
// @grant         none
// ==/UserScript==

(function() {
    'use strict';
    let timeout = 1000; //you can customize this timeout based on your ajax network speed
    let repTemplate = `<span class="reputation-score" title="reputation score " dir="ltr"> %reputation%</span>`;

    function getRep(userReputations){
        for(let i = 0; i < userReputations.length; i++){
            let rep = userReputations[i].title.split(' ')[0];
            let repHtml = repTemplate.replace('%reputation%', rep);
            userReputations[i].parentNode.insertAdjacentHTML('beforeend', repHtml);
        }
    }

    let showMoreCommentsElements = document.querySelectorAll('a.js-show-link.comments-link');
    for(let i = 0; i < showMoreCommentsElements.length; i++){
        showMoreCommentsElements[i].addEventListener('click', function(event){
            setTimeout(function(){
                let users = event.target.parentNode.parentNode.querySelectorAll('span.comment-copy + div > a');
                getRep(users);
            }, timeout);//timeout variable is used here.
        });
    }

    function main(){
        let allUsers = document.querySelectorAll('a.comment-user');
        getRep(allUsers);
    }

    main();


})();