posts

접근 차단

Oct 1, 2025 updated Oct 1, 2025 architecturecssjavascript

<script>
	(function() {
		//=================================================================================
		// 우클릭, 드래그, 복사 차단
		//=================================================================================
		//var events = [ "contextmenu", "selectstart", "dragstart", "copy", "cut" ];
		var events = [ "contextmenu", "selectstart", "dragstart"];

		events.forEach(function(event) {
			window.addEventListener(event, blockEvent, true);
		})

		function blockEvent(e) {
			e.preventDefault();
		}
		//=================================================================================
		// 개발자 메뉴 (F12) 차단
		//=================================================================================
		window.addEventListener('keydown', blockDeveloperMenu, true);

		function blockDeveloperMenu(e) {
			if (e.keyCode === 123) { // F12
				blockEvent(e);
			}
			if (e.ctrlKey && e.shiftKey) {
				var code = e.keyCode;
				// 개발자 도구를 여는 Ctrl + Shift + 키 조합
				if (code === 67 || code === 69 || code === 73 || code === 74
						|| code === 75 || code === 77 || code === 83) {
					blockEvent(e);
				}
			}
		}

		setInterval(function() {
			debugger;
		}, 200);
		//=================================================================================
		// 애드온 (pig toolbox 등) 차단
		//=================================================================================
		var event, received = false;

		refreshEvent();

		window.addEventListener("contextmenu", function(e) {
			if (e === event) {
				received = true;
			}
		}, true);

		setInterval(function() {
			received = false;
			window.dispatchEvent(event);
			received ? hideMessage() : showMessage();
			refreshEvent();
		}, 200);

		function refreshEvent() {
			if (event && !event.cancelBubble) {
				return;
			}
			event = document.createEvent("MouseEvents");
			event.initMouseEvent("contextmenu", true, true, window, 1, 50, 121,
					50, 50, false, false, false, false, 2, null);
		}
		//=================================================================================
		// 자바스크립트 비활성화 (Disable Javascript) 시 메세지 띄우기
		//=================================================================================
		var timer = null;
		function showMessage() {
			clearInterval(timer);
			timer = null;
		}
		function hideMessage() {
			if (timer === null) {
				timer = setInterval(reveal, 450);
			}
		}
		function reveal() {
			cl().toggle("cm-hide");
			cl().toggle("cm-hide-2");
		}
		function cl() {
			return Copyright_Message.classList;
		}

		window.addEventListener('visibilitychange', function() {
			// 페이지가 숨겨질 시 animation을 정지함
			if (document.visibilityState === "hidden") {
				cl().remove("cm-hide", "cm-hide-2");
				void Copyright_Message.offsetWidth;
				showMessage();
			} else {
				cl().add("cm-hide");
				cl().remove("cm-hide-2");
				hideMessage();
			}
		}, true);

		hideMessage();
	})();
</script>
<!---------------------------------------------------------------
    자바스크립트 비활성화 후 새로고침 시 메세지 띄우기
---------------------------------------------------------------->
<noscript>
    <style>
#Copyright_Message>span { display: none; }
.cm-no-js { background: white; visibility: visible!important; }
</style>
</noscript>
<!---------------------------------------------------------------
    드래그 차단
---------------------------------------------------------------->
<style>
*:not(input):not(textarea):not(code):not(blockquote):not(pre) {
    user-select: none !important;
    -webkit-user-select: none !important;
    -webkit-touch-callout: none !important;
}
</style>
<!-- 저작권 메세지 CSS -->
<style>
.cm-overlay {
    height: 100%;
    width: 100%;
    position: fixed;
    left: 0;
    top: 0;
    overflow-x: hidden;
    z-index: 2147483647;
}

#Copyright_Message, .cm-no-js { visibility: hidden; }

#Copyright_Message.cm-hide {
    animation: 1s cm-reveal 500ms forwards;
}
#Copyright_Message.cm-hide-2 {
    animation: 1s cm-reveal-2 500ms forwards;
}

@keyframes cm-reveal {
    from { opacity: 0; visibility: visible; }
    to { opacity: 1; visibility: visible; }
}
@keyframes cm-reveal-2 {
    from { opacity: 0; visibility: visible; }
    to { opacity: 1; visibility: visible; }
}

@media print { noscript { display: none; } }
</style>
<!---------------------------------------------------------------
    저작권 안내 메세지, <span> 내의 글을 원하는 대로 수정하세요.
---------------------------------------------------------------->
<div>
	<div class="cm-overlay cm-no-js"></div>
	<div id="Copyright_Message" class="cm-overlay cm-hide">
		<span> 불법적인 예약방지를 위하여 개발자 도구의 사용이 금지됩니다.
		</span>
		<noscript class="cm-no-js">
			<!-- 자바스크립트 비활성화 시에 보여지는 메세지 -->
			<span> 이 페이지를 보기 위해서는 자바스크립트가 필요합니다. <br> 사이트 설정에서
				자바스크립트를 사용하도록 설정해주세요.
			</span>
		</noscript>
	</div>
</div>
<!---------------------------------------------------------------
    아래 CSS를 수정하여 메세지의 스타일을 변경하세요.
---------------------------------------------------------------->
	<style>
#Copyright_Message span {
	font-size: 15px;
	font-family: sans-serif;
	position: fixed;
	width: 500px;
	max-width: 90%;
	top: 50%;
	left: 50%;
	margin-left: -250px;
	margin-top: -100px;
	border-radius: 10px;
	box-shadow: 0px 0px 34px 2px rgba(242, 191, 191, 1);
	padding: 10px 10px 10px 35px;
	line-height: 1.5;
	color: #555;
	background: #ffecec
		url('https://tistory4.daumcdn.net/tistory/770263/skin/images/warning.png')
		no-repeat 10px 50%;
	border: 1px solid #f5aca6;
}
</style><!-- @!@ 20240628 개발자도구창 제한 -->