⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plugin.js

📁 标准 标准 标准 标准 标准 标准 标准 标准 标准 标准
💻 JS
字号:

//---- A class to manage the requests and callbacks of an item
function jsRssPluginClass(rssUrl, htmlElementId, displayTitle) {
	// send request to webserver for data
	var dispCtrl = document.getElementById(htmlElementId);
	if ( dispCtrl == null )
	{
		document.write("<ul id='" + htmlElementId + "'></ul>");
		dispCtrl = document.getElementById(htmlElementId);
	}
	
	// get vip user options
	var isVipUser = true;
	var links = document.links;
	__doTextChanged("正在加载 " + displayTitle + " ...", true);
	
	var isCommentsFeed = false;
	isCommentsFeed = rssUrl.indexOf("/comments/") > 0;
	
    // branch for native XMLHttpRequest object
	var httpReq = null;
    if (window.XMLHttpRequest) {
        httpReq = new XMLHttpRequest();
        httpReq.onreadystatechange = __doReadyStateChanged;
        httpReq.open("GET", rssUrl, true);
        httpReq.send("");
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        httpReq = new ActiveXObject("Microsoft.XMLHTTP");
        if (httpReq) {
            httpReq.onreadystatechange = __doReadyStateChanged;
            httpReq.open("GET", rssUrl, true);
            httpReq.send();
        }
    }
    
	
	// __doTextChanged
	function __doTextChanged(msg, showLoading)
	{
		var strCopyright = '<a href="http://my.donews.com/blogbug//" target="_blank" title="哈啰波波想统计有多少人在使用该插件?请留言给哈啰波波,谢谢!">^ 哈啰波波</a>';
		dispCtrl = document.getElementById(htmlElementId);
		if( dispCtrl != null )
		{
			dispCtrl.innerHTML = '<strong>' + displayTitle + '</strong>'
				+ (showLoading == null ? msg : "<li style='padding: 3px 0px;'>" + msg + "</li>");
		}
	}
	
	// __doReadyStateChanged
	function __doReadyStateChanged() {
		if (httpReq.readyState == 4) { // completed?
			// parse the xml data received
	        __doTextChanged("地址已找到,正在解析数据...", true);
	        if (httpReq.status == 200) {
	        	__doHandleResponse();
	        } else {
	            __doTextChanged("<li>请求数据出错,请检查RSS地址是否正确。</li>");
	        }
		}
	}
	
	// __doHandleResponse
	function __doHandleResponse()
	{
		var doc = null;
		/*
		if ( doc == null )
			doc = new ActiveXObject("Msxml2.DOMDocument");
		if( doc == null )
			doc = new DOMDocument();
		doc.loadXML(httpReq.responseText);
		*/
		doc = httpReq.responseXML;
		
		var strHtml = "";
		// read the word title, description and link from the xml
		var title, desc, link;
		var elems = doc.getElementsByTagName("item");
		if (elems != null && elems.length > 0) {
			for( var i = 0; i < elems.length; i++ ) {
				var elem = elems[i];
				for (var node = elem.firstChild; node != null; node = node.nextSibling) {
					if (node.nodeName == "title")
						title = node.firstChild.nodeValue;
					if (node.nodeName == "link")
						link = node.firstChild.nodeValue;
					if (node.nodeName == "description")
						desc = node.firstChild.nodeValue;
				}
				desc = desc.replace(/<([^>]|\n)*>/g,'');  // remove html tags if present
				desc = desc.replace(/&nbsp;/g, ' ');
				desc = desc.replace(/&quot;/g, '"');
				desc = desc.replace(/&amp;/g, '&');
				if( desc.length > 32 )
					desc = desc.substr(0, 32) + " ...\n\n[点击查看全文]";
				if( isCommentsFeed )
					title = desc.replace(/\n/g,'');
				
				strHtml += "<li style='padding: 3px 0px;border-bottom:1px dotted #BBB;'>&raquo;&nbsp;<a href='" + link + "' target='_blank' title='" + desc + "'>" + title + "</a></li>";
			}
			
			__doTextChanged(strHtml);
		}
		else
		{
			__doTextChanged("<li>该RSS地址没有数据。</li>");
		}
		httpReq = null;  // free the http object*/
	}
}

// function getRss
function getRss(rssUrl, htmlElementId, displayTitle)
{
	rssUrl = rssUrl == null ? "http://my.donews.com/blogbug/feed" : rssUrl;
	htmlElementId = htmlElementId == null ? "blogbugDiv" : htmlElementId;
	displayTitle = displayTitle == null ? "哈啰波波 ^ 点这儿" : displayTitle;
	
	new jsRssPluginClass(rssUrl, htmlElementId, displayTitle);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -