Last active
August 29, 2015 14:27
-
-
Save sftblw/7808f5ff3833498e1d83 to your computer and use it in GitHub Desktop.
flag-ko.js : 국경일 확인 및 본문에 국기 삽입. 문서 : http://lpidx.tistory.com/38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 국경일에만 본문에 국기를 삽입합니다. | |
| // | |
| // DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
| // Version 2, December 2004 | |
| // | |
| // Copyright (C) 2015 Ch. <[email protected]> | |
| // | |
| // Everyone is permitted to copy and distribute verbatim or modified | |
| // copies of this license document, and changing it is allowed as long | |
| // as the name is changed. | |
| // | |
| // DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
| // TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
| // | |
| // 0. You just DO WHAT THE FUCK YOU WANT TO. | |
| (function () { | |
| var cage_front = '<div class="outer-cage fullwidth-cage notice-cage"><div class="container">' | |
| +'<img src="http://cfs.tistory.com/custom/blog/19/198097/skin/images/flag-ko.png" style="width:300px; height: auto; border-style: solid; border-width: 2px;" /><br />' | |
| +'<p style="padding-top: 1em;">'; | |
| var cage_end = '</p></div></div>'; | |
| // main code | |
| replaceAndInsertToDocument(makeFlagDateString()); | |
| // replace <span id="flag-ko"> with supplied string. | |
| function replaceAndInsertToDocument(ment) { | |
| if (typeof ment !== "string") return false; | |
| var target = document.getElementById('flag-ko'); | |
| if (target === null) return false; | |
| var text = cage_front + ment + cage_end; | |
| var replace = $.parseHTML(text); | |
| if (replace.length !== 1) return false; | |
| replace = replace[0]; | |
| target.parentNode.replaceChild(replace, target); | |
| } | |
| // @returns null if not the day. | |
| // @returns string if today is in day. | |
| function makeFlagDateString() { | |
| // month, date, ment | |
| var days_happy = [ | |
| [ 3, 1, '오늘은 <a href="https://namu.wiki/w/%EC%82%BC%EC%9D%BC%EC%A0%88">삼일절</a>입니다. <a href="https://namu.wiki/w/3.1%20%EC%9A%B4%EB%8F%99">3.1 운동</a>을 기억합시다.'], | |
| [ 7, 17, '오늘은 <a href="https://namu.wiki/w/%EC%A0%9C%ED%97%8C%EC%A0%88">제헌절</a>입니다. <a href="https://namu.wiki/w/%EB%8C%80%ED%95%9C%EB%AF%BC%EA%B5%AD%20%ED%97%8C%EB%B2%95">헌법</a>이 제정된 날입니다.'], | |
| [ 8, 15, '오늘은 <a href="https://namu.wiki/w/%EA%B4%91%EB%B3%B5%EC%A0%88">광복절</a>입니다. <a href="https://namu.wiki/w/%EC%9D%BC%EC%A0%9C%EA%B0%95%EC%A0%90%EA%B8%B0">35년간의 일본 식민 통치</a>가 1945년 오늘 끝나고, 우리나라가 <a href="https://namu.wiki/w/8.15%EA%B4%91%EB%B3%B5">해방</a>되었습니다. '], | |
| [10, 3, '오늘은 <a href="https://namu.wiki/w/%EA%B0%9C%EC%B2%9C%EC%A0%88">개천절</a>입니다. <a href="https://namu.wiki/w/%EA%B3%A0%EC%A1%B0%EC%84%A0">고조선</a> 건국을 기념하는 날입니다.'], | |
| [10, 9, '오늘은 <a href="https://namu.wiki/w/%ED%95%9C%EA%B8%80%EB%82%A0">한글날</a>입니다. 한글과 관련된 활동을 해보는 건 어떨까요?'] | |
| ]; | |
| var days_sad = [ | |
| [ 6, 6, '오늘은 <a href="https://namu.wiki/w/%ED%98%84%EC%B6%A9%EC%9D%BC">현충일</a>입니다. 나라를 위해 목숨을 바치신 분들을 추모합시다.'] | |
| ]; | |
| // make today in korea. UTC+9 | |
| var today = new Date(); | |
| today.setUTCHours(today.getUTCHours()+9); | |
| // js month is 0~11. | |
| for (var i = 0; i < days_happy.length; i++) { | |
| var d = days_happy[i]; | |
| if ( | |
| (today.getUTCMonth()+1 === d[0]) | |
| && (today.getUTCDate() === d[1]) | |
| ) return d[2]; | |
| } | |
| for (var i = 0; i < days_sad.length; i++) { | |
| var d = days_sad[i]; | |
| if ( | |
| (today.getUTCMonth()+1 === d[0]) | |
| && (today.getUTCDate() === d[1]) | |
| ) return d[2]; | |
| } | |
| // default | |
| return null; | |
| } | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment