0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ScriptAutoRunnerで本番環境サイトに警告メッセージを出す

Last updated at Posted at 2021-07-01

やりたいこと

本番環境ドメイン(product.hoge.com)にアクセスしているときだけ、画面の上の方に警告メッセージを出したい。

やったこと

① 拡張機能「ScriptAutoRunner」をインストール。

② 設定画面で以下のスクリプトを設定 (コード中の改行は適宜削除して下さい)

function insertWarning() {
	const parts = location.hostname.split(".");
	const subdomain = parts.shift();
	if (subdomain === 'product') {
		warningMessage = document.createElement('div');
		warningMessage.setAttribute('class', 'warningMessage')
		warningMessage.setAttribute('style','background-color: rgba(230, 20, 20, 0.8);
											 color: white;
											 position: fixed;
											 padding: 4px;
											 z-index: 999999;
											 top: 0px; width: 100%;
											 font-size: larger;
											 text-align: center;
											 letter-spacing: 3px;')
		warningMessage.innerHTML = '本番環境';
		document.body.appendChild(warningMessage);
	} else {;
	};
};
insertWarning();

Target hostname に product.hoge.com を設定。
④ プラグボタンをクリックして有効化。

設定例

sample-screenshot.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?