production.staging.highlight.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // ==UserScript==
  2. // @name production.staging.highlight
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @updateURL https://git.koehls.de/ric/monkeyscripts/raw/master/production.staging.highlight.js
  6. // @description Colors the local/staging/production site differently.
  7. // @author Richard Köhl
  8. // @match *://*.wikipedia.org/*
  9. // @grant none
  10. // ==/UserScript==
  11. /* jshint -W097 */
  12. "use strict";
  13. // in this example we use wikipedia where language subdomain "de" acts as local environment,
  14. // "en" as staging and all other languages as productive environments.
  15. let background = "rgba(170, 0, 0, 0.8)";
  16. if ( window.location.href.match(/^https?:\/\/en\./) ) {
  17. background = "rgba(0, 130, 60, 0.8)";
  18. } else if ( window.location.href.match(/^https?:\/\/de\./) ) {
  19. background = "rgba(90, 0, 130, 0.8)";
  20. }
  21. // color a specific element (e.g. header)
  22. const navBar = document.querySelector("#mw-head-base");
  23. if ( navBar ) {
  24. navBar.style.background = background;
  25. }
  26. // put an overlay over the page that colors the borders
  27. const div = document.createElement("div");
  28. div.style.pointerEvents = "none";
  29. div.style.position = "fixed";
  30. div.style.left = 0;
  31. div.style.top = 0;
  32. div.style.right = 0;
  33. div.style.bottom = 0;
  34. div.style.boxShadow = "0 0 50px 10px " + background + " inset";
  35. div.style.zIndex = 100001;
  36. document.body.appendChild(div);