글 수정

작성자 본인만 수정할 수 있습니다

← 홈으로
익명 · 2023.10.18 · 조회 25,759
세이프 서치 모드
<p>데이터 텍스트 파일 내의 단어와 페이지 내의 단어가 일치하면 페이지 블러처리</p><div>&lt;?php</div><div>$words = file("data.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);</div><div>?&gt;</div><div>&lt;script&gt;</div><div>document.addEventListener("DOMContentLoaded", function() {</div><div>&nbsp; &nbsp; var wordsToBlur = &lt;?php echo json_encode($words); ?&gt;;</div><div><br></div><div>&nbsp; &nbsp; function createBlurredElement(originalElement) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; // '세이프 서칭이 적용됐습니다.' 메시지를 추가</div><div>&nbsp; &nbsp; &nbsp; &nbsp; var message = document.createElement("div");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; message.innerHTML = "세이프 서칭이 적용됐습니다.";</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; // 완전한 블러 스타일 적용을 위한 spanWrapper 생성</div><div>&nbsp; &nbsp; &nbsp; &nbsp; var blurredElement = originalElement.cloneNode(true);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; blurredElement.style.position = "relative";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; blurredElement.style.overflow = "hidden";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; blurredElement.style.filter = "blur(4px)"; // 블러 강도 조절 가능</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; blurredElement.appendChild(message);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp;return blurredElement;</div><div>&nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; function applyBlurToElements(element) {</div><div>&nbsp; &nbsp; &nbsp; wordsToBlur.forEach(function(word) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (element.textContent.includes(word)) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var blurredEl= createBlurredElement(element);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; element.replaceWith(blurredEl);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; });</div><div><br></div><div>&nbsp; &nbsp; &nbsp; for (var i=0; i&lt;element.children.length; i++) {&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; applyBlurToElements(element.children[i]);&nbsp;</div><div>&nbsp; &nbsp; &nbsp; }</div><div>&nbsp; }</div><div><br></div><div>&nbsp; applyBlurToElements(document.body);&nbsp;</div><div><br></div><div>});</div><div>&lt;/script&gt;</div>