<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>RSS 리더기</title>
<script type="text/javascript">
// Control
var txtTimer;
var lblTimer;
var refreshTime;
var rssList;
var last_modif;
function timerSet(){
refreshTime = parseInt(txtTimer.value);
if(isNaN(refreshTime)){
alert("숫자기입바람");
txtTimer.value="";
txtTimer.focus();
return;
}
lblTimer.replaceChild(document.createTextNode(refreshTime), lblTimer.firstChild );
refreshXML();
}
function refreshXML(){
clearTimeout(refreshXMLTimer);
doParse();
var refreshXMLTimer = setTimeout("refreshXML()", refreshTime*60000 );
last_modif.replaceChild(document.createTextNode(new Date()), last_modif.firstChild );
}
window.onload = function(){
txtTimer = document.getElementById("txtTimer");
lblTimer = document.getElementById("lblTimer");
rssList = document.getElementById("rssList");
last_modif = document.getElementById("last_modif");
//timerSet();
document.getElementById("sendButton").onclick = function (){
timerSet();
}
}
// RSS Request관련.
var rssDoc;
function doParse(){
if (document.implementation && document.implementation.createDocument){
try{
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
}catch(e){alert(e);}
rssDoc = document.implementation.createDocument("", "", null);
rssDoc.async = false;
} else if (window.ActiveXObject) {
rssDoc = new ActiveXObject("Microsoft.XMLDOM");
rssDoc.async = true;
rssDoc.onreadystatechange = function (){
if (rssDoc.readyState != 4) return false;
rssDocLoad();
return true;
}
} else {
alert("미지원 브라우져....");
}
try{
var rssAddr = document.getElementById("rssAddr");
rssDoc.load(rssAddr.value)
if(rssDoc.readyState==null) rssDocLoad();
} catch(e) {
alert(e);
return;
}
}
function rssDocLoad(){
tableReset();
var rssTitle = document.getElementById("rssTitle");
var rssDocsTitle = rssDoc.getElementsByTagName("title").item(0).firstChild.nodeValue;
var rssDocsLink = rssDoc.getElementsByTagName("link").item(0).firstChild.nodeValue;
var aEl = document.createElement("a");
var hrefAttr = document.createAttribute("href");
hrefAttr.value = rssDocsLink;
aEl.setAttributeNode(hrefAttr);
aEl.appendChild(document.createTextNode(rssDocsTitle));
aEl.target ="_blank";
rssTitle.replaceChild(aEl, rssTitle.firstChild);
var itemNode = rssDoc.getElementsByTagName("item");
var lblProgress = document.getElementById("lblProgress");
var tbodyEl = document.createElement("tbody");
for(i=0; i<itemNode.length; i++){
removeWhiteSpace(itemNode[i]);
var title = "";
var link = "";
var description = "";
var pubDate = "";
var author = "";
var category = "";
for(ix=0; ix<itemNode[i].childNodes.length; ix++){
var curNode = itemNode[i].childNodes[ix];
var curNodeVal = curNode.firstChild.nodeValue;
switch( curNode.tagName ){
case "title":
title = curNodeVal;
break;
case "link":
link = curNodeVal;
break;
case "description":
description = curNodeVal;
break;
case "author":
author = curNodeVal;
break;
case "category":
case "dc:subject":
category = curNodeVal;
break;
case "pubDate":
case "dc:date":
pubDate = curNodeVal;
break;
default:
}
}
var trEl = document.createElement("tr");
var tdEl;
tdEl = document.createElement("td");
tdEl.appendChild(
document.createTextNode(pubDate.substring(0,10)) );
trEl.appendChild(tdEl);
tdEl = document.createElement("td");
tdEl.appendChild(
document.createTextNode(title));
trEl.appendChild(tdEl);
tdEl = document.createElement("td");
tdEl.appendChild(
document.createTextNode(author));
trEl.appendChild(tdEl);
tdEl = document.createElement("td");
var aEl = document.createElement("a");
var hrefAttr = document.createAttribute("href");
hrefAttr.value = link;
aEl.setAttributeNode(hrefAttr);
aEl.appendChild(document.createTextNode("열기"));
aEl.target ="_blank";
tdEl.appendChild(aEl);
trEl.appendChild(tdEl);
tdEl = document.createElement("td");
tdEl.appendChild(
document.createTextNode(category));
trEl.appendChild(tdEl);
tbodyEl.appendChild(trEl);
}
rssList.appendChild(tbodyEl);
}
function removeWhiteSpace(nodeList){
var notWhitespace = /\S/
for (var rwi=0; rwi<nodeList.childNodes.length; rwi++){
if ((nodeList.childNodes[rwi].nodeType == 3)&&
(!notWhitespace.test(nodeList.childNodes[rwi].nodeValue))) {
nodeList.removeChild(nodeList.childNodes[rwi])
rwi--;
}
}
}
function tableReset(){
// 제목만 있다면 지우지 않는다.
if(rssList.childNodes.length==1) return;
for(var tri=1; tri<rssList.childNodes.length; tri++){
rssList.removeChild(rssList.childNodes[tri]);
tri--;
}
}
</script>
<style type="text/css">
table.mainTbl {
border:1px solid blue;
background-color:#eaeafa;
width: 100%;
}
table.mainTbl td{
padding:8px 4px 4px 4px;
}
table.mainTbl td.header{
font-weight:bold;
border-bottom: 1px solid gray;
}
input {
border:1px solid gray;
padding: 1px 1px 1px 1px;
}
</style>
</head>
<body>
<form action=" ">
RSS주소: <input type="text" name="rssAddr" id="rssAddr" style="width:350px"/><input type="button" id="sendButton" value="가져오기"/><br/>
체널: <span id="rssTitle"> </span> <br/><br/>
새로고침은 <input
type="text" value="1" name="txtTimer" id="txtTimer" style="width:20px"/>분 단위로<input
type="button" id="btnSet" name="btnSet" value="설 정" onclick="timerSet()"/> (현재 <span id="lblTimer"> </span>분 단위로)<br/>
마지막 읽은 시간 : <span id="last_modif"> </span>
<br/><br/>
<input type="button" value="새 로 고 침" style="margin-bottom:10px" onclick="javascript
<table class="mainTbl" cellpadding="0" cellspacing="0" id="rssList"><tr>
<td class="header">날짜</td>
<td class="header">제목</td>
<td class="header">글쓴이</td>
<td class="header">원본링크</td>
<td class="header">카테고리</td>
</tr></table>
<br/>
<div style="text-align:center">by visharp (in <a href="http://okjsp.pe.kr" target="_blank">okjsp.pe.kr</a>)</div>
</form>
</body>
</html>