浏览代码

production/staging coloring

Richard Köhl 5 年之前
父节点
当前提交
f502de7f05
共有 2 个文件被更改,包括 40 次插入1 次删除
  1. 1 1
      LICENSE
  2. 39 0
      production.staging.highlight.js

+ 1 - 1
LICENSE

@@ -1,5 +1,5 @@
 MIT License
-Copyright (c) <year> <copyright holders>
+Copyright (c) 2020 Richard Köhl
 
 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 

+ 39 - 0
production.staging.highlight.js

@@ -0,0 +1,39 @@
+// ==UserScript==
+// @name         production.staging.highlight
+// @namespace    http://tampermonkey.net/
+// @version      0.1
+// @updateURL    https://git.koehls.de/ric/monkeyscripts/raw/master/production.staging.highlight.js
+// @description  Colors the local/staging/production site differently.
+// @author       Richard Köhl
+// @match        *://*.wikipedia.org/*
+// @grant        none
+// ==/UserScript==
+/* jshint -W097 */
+"use strict";
+
+// in this example we use wikipedia where language subdomain "de" acts as local environment,
+// "en" as staging and all other languages as productive environments.
+let background = "rgba(170, 0, 0, 0.8)";
+if ( window.location.href.match(/^https?:\/\/en\./) ) {
+    background = "rgba(0, 130, 60, 0.8)";
+} else if ( window.location.href.match(/^https?:\/\/de\./) ) {
+    background = "rgba(90, 0, 130, 0.8)";
+}
+
+// color a specific element (e.g. header)
+const navBar = document.querySelector("#mw-head-base");
+if ( navBar ) {
+    navBar.style.background = background;
+}
+
+// put an overlay over the page that colors the borders
+const div = document.createElement("div");
+div.style.pointerEvents = "none";
+div.style.position = "fixed";
+div.style.left = 0;
+div.style.top = 0;
+div.style.right = 0;
+div.style.bottom = 0;
+div.style.boxShadow = "0 0 50px 10px " + background + " inset";
+div.style.zIndex = 100001;
+document.body.appendChild(div);