[user] to OP's name on StackExchange sites

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

当前为 2018-10-15 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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