[user] to OP's name on StackExchange sites

Changes [user] to the OP's username when commenting on StackExchange sites

Versione datata 15/10/2018. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         [user] to OP's name on StackExchange sites
// @namespace    https://zachsaucier.com/
// @version      0.4
// @description  Changes [user] to the OP's username when commenting on StackExchange sites
// @author       Zach Saucier
// @match        https://*.stackexchange.com/*
// @match        https://stackoverflow.com/*
// @match        https://meta.stackoverflow.com/*
// @match        https://superuser.com/*
// @match        https://meta.superuser.com/*
// @match        https://askubuntu.com/*
// @match        https://meta.askubuntu.com/*
// @match        https://serverfault.com/*
// @match        https://meta.serverfault.com/*
// @match        https://mathoverflow.net/*
// @match        https://meta.mathoverflow.net/*
// @match        https://stackapps.com/*
// @match        https://meta.stackapps.com/*
// @exclude      http://chat.stackexchange.com/*
// @exclude      http://chat.stackoverflow.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    document.body.addEventListener("keyup", (e) => {
        let elem = e.target,
            opName = "[user]";

        if(document.querySelector(".owner .user-details a")) {
            opName = document.querySelector(".owner .user-details a").innerText;
        }

        if(elem.name === "comment") {
            elem.value = elem.value.replace(/\[user\]/g, opName);
        }
    });
})();