[user] to OP's name on StackExchange sites

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

  1. // ==UserScript==
  2. // @name [user] to OP's name on StackExchange sites
  3. // @namespace https://zachsaucier.com/
  4. // @version 0.6
  5. // @description Changes [user] to the OP's username when commenting on StackExchange sites
  6. // @author Zach Saucier
  7. // @match *://*.askubuntu.com/*
  8. // @match *://*.mathoverflow.net/*
  9. // @match *://*.serverfault.com/*
  10. // @match *://*.stackapps.com/*
  11. // @match *://*.stackexchange.com/*
  12. // @match *://*.stackoverflow.com/*
  13. // @match *://*.superuser.com/*
  14. // @exclude *://api.stackexchange.com/*
  15. // @exclude *://blog.*.com/*
  16. // @exclude *://chat.*.com/*
  17. // @exclude *://data.stackexchange.com/*
  18. // @exclude *://elections.stackexchange.com/*
  19. // @exclude *://openid.stackexchange.com/*
  20. // @exclude *://stackexchange.com/*
  21. // @grant none
  22. // ==/UserScript==
  23.  
  24. (function() {
  25. 'use strict';
  26.  
  27. document.body.addEventListener("keyup", (e) => {
  28. let elem = e.target,
  29. opName = "[user]";
  30.  
  31. if(document.querySelector(".owner .user-details a")) {
  32. opName = document.querySelector(".owner .user-details a").innerText;
  33. }
  34.  
  35. if(elem.name === "comment") {
  36. elem.value = elem.value.replace(/\[user\]/g, opName);
  37. }
  38. });
  39. })();