// ==UserScript== // @name [user] to OP's name on StackExchange sites // @namespace https://zachsaucier.com/ // @version 0.2 // @description Adds the OP's username in the [name] slot when pasting snippets for comments on GD.SE // @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/* // @grant none // @downloadURL 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); } }); })();