Identify development environment

Display an alert on your work environment for disambiguation

  1. // ==UserScript==
  2. // @name Identify development environment
  3. // @description Display an alert on your work environment for disambiguation
  4. // @author Deuchnord
  5. // @version 1.0.0
  6. // @namespace https://deuchnord.fr/userscripts/#all_sites/identify-environment
  7. // @match http*://*/*
  8. // @license AGPL-3.0
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // ==/UserScript==
  12.  
  13. (function () {
  14.  
  15. let ENVIRONMENTS = GM_getValue("environments", null);
  16.  
  17. if (ENVIRONMENTS === null) {
  18. // set default value
  19. ENVIRONMENTS = [{
  20. hostname: "example.com",
  21. name: "Production",
  22. background: "red",
  23. textColor: "white"
  24. }];
  25.  
  26. GM_setValue("environments", ENVIRONMENTS);
  27. }
  28.  
  29. let environment = null;
  30.  
  31. for (let env of ENVIRONMENTS) {
  32. if (window.location.hostname !== env.hostname) {
  33. continue;
  34. }
  35.  
  36. environment = env;
  37. break;
  38. }
  39.  
  40. if (environment === null) {
  41. return;
  42. }
  43.  
  44. let signal = document.createElement("aside");
  45. signal.setAttribute("aria-role", "status");
  46. signal.innerText = environment.name;
  47. signal.style.borderBottom = "2px solid black";
  48. signal.style.background = environment.background;
  49. signal.style.color = environment.textColor;
  50. signal.style.fontFamily = "sans-serif";
  51. signal.style.fontSize = "16px";
  52. signal.style.padding = "5px 15px";
  53. signal.style.position = "fixed";
  54. signal.style.left = 0;
  55. signal.style.right = 0;
  56. signal.style.top = 0;
  57. signal.style.zIndex = 10000000;
  58. signal.style.cursor = "default";
  59. signal.style.textAlign = "center";
  60.  
  61. document.body.appendChild(signal);
  62. document.body.style.marginTop = "36px";
  63.  
  64. })();