[user] to OP's name on StackExchange sites

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

As of 2018-10-15. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);
        }
    });
})();