📄 www2-main.js
字号:
/** * Part of the KBS BBS Code * Copyright (c) 2005-2008 KBS Development Team. (http://dev.kcn.cn/) * Source file is subject to the pending KBS License. * * You may use and/or modify the source code only for pure personal study * purpose (e.g. using it in a public website is not acceptable), unless * you get explicit permission by the KBS Development Team. *//* TODO: obfuscate this file... */var agt = navigator.userAgent.toLowerCase();var gOp = (agt.indexOf("opera") != -1);var gIE = ((agt.indexOf("msie") != -1) && !gOp);var gFx = (agt.indexOf("gecko") != -1);var gKon = (agt.indexOf("konqueror") != -1) && (agt.indexOf("safari") == -1);var gIE5 = false;if (gIE) { gIE5 = (parseFloat( agt.substring( agt.indexOf('msie ') + 5 ) ) < 6);}var kbsrc = null; //namespace in this windowvar www2dev = (typeof gwww2dev != "undefined");var havejsmath = (typeof gjsmath != "undefined");var gIE6Fx = ((gIE && !gIE5) || gFx || www2dev);if (!Array.prototype.push) { Array.prototype.push = function() { var s = this.length; for (var i = 0; i < arguments.length; i++) this[s + i] = arguments[i]; return this.length; };}function StringBuffer() { this.buffer = []; }StringBuffer.prototype = { append: function(string) { this.buffer.push(string); }, toString: function() { return this.buffer.join(""); }};function w(s) { if (document&&document.write) document.write(s); }var bootFn = Array();function addBootFn(fn) { bootFn.push(fn);}function htmlize(s,html_attrib) { s = s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); if (html_attrib) { s = s.replace(/"/g, """).replace(/'/g, "'"); } else { s = s.replace(/\x20\x20/g, " "); } return s;}var att = null, strPrint = "", strArticle = "", divArtCon = null;function attWriter(bid, id, ftype, num, cacheable) { this.bid = bid; this.id = id; this.ftype = ftype; this.num = num; this.cacheable = cacheable;}function prints(s) { strPrint += s; s = s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); s = s.replace(/\r[\[\d;]+[a-z]/gi, ""); s = s.replace(/\x20\x20/g, " ").replace(/\n /g, "\n "); s = s.replace(/\n(: [^\n]*)/g, "<br/><span class=\"f006\">$1</span>"); if (gKon && s.length > 0) { s = s.split("\n").join("<br/>"); } else { s = s.replace(/\n/g, "<br/>"); } if (!gIE5) { var urlmatch = new RegExp("((?:http|https|ftp|mms|rtsp)://(&(?=amp;)|[A-Za-z0-9\./=\?%_~@#:;\+\-])+)", "ig"); s = s.replace(urlmatch, "<a target=\"_blank\" href=\"$1\">$1</a>"); } strArticle += s; if (!divArtCon) w(s);}function attachURL(name, len, pos) { if (att.bid < 0) { return location.href+'&ap='+pos; }; //mail var ext = null, o = name.lastIndexOf("."); if (!att) return null; if (o != -1) { ext = name.substring(o + 1).toLowerCase(); } var url = "att.php?"; if (!att.cacheable) url += "n"; else if (len > 51200) url += "p"; else url += "s"; url += "." + att.bid + "." + att.id; if (att.ftype) url += "." + att.ftype + "." + att.num; url += "." + pos; if (ext) url += "." + htmlize(ext); return (url);}function attach(name, len, pos) { var bImg = false; var s = "", url = attachURL(name, len, pos); if (!url) return; var o = name.lastIndexOf("."); if (o != -1) { var ext = name.substring(o + 1).toLowerCase(); bImg = (ext == "jpg" || ext == "jpeg" || ext == "gif" || ext == "ico" || ext == "png" || ext == "pcx" || ext == "bmp"); } var sizes = len + ' 字节'; if (len > 8192) sizes = parseInt(len/1024) + 'KB'; if (bImg) { s += '<br /><img src="images/img.gif"/>此主题相关图片如下:' + name + ' (' + sizes + ')<br /><a href="' + url + '" target="_blank">' + '<img src="' + url + '" title="按此在新窗口浏览图片" style="margin: 0.2em 0 0.5em 0;" onload="resizeImg(this)" /></a> '; } else { s += '<br />附件: <a href="' + url + '">' + name + '</a> (' + sizes + ')<br />'; } strArticle += s; if (!divArtCon) w(s);}function writeArticle() { divArtCon.innerHTML = strArticle;}function notifyError(parentEle, msg) { if (parent) { var v = parent.document.getElementById(parentEle); if (v) { v.innerHTML = ""; alert(msg); } }}function getCookie(name, def){ var cname = name + "="; var dc = document.cookie; if (dc.length > 0) { var begin = dc.indexOf(cname); if (begin != -1) { begin += cname.length; var end = dc.indexOf(";", begin); if (end == -1) end = dc.length; return unescape(dc.substring(begin, end)); } } return def;}var kbsAd = false;function getAds(i,l,n,t) { var ret = ""; if (!kbsAd) { kbsAd = true; ret += "<iframe width='0' height='0' src='images/img.gif' frameborder='0' scrolling='no' id='hfad' name='hfad'></iframe>"; } ret += "<a href='" + l + "' target='_blank' onclick='recordAds(" + n + ")' title='为支持水木发展请点击广告'>" + (t?t:"<img src='/guangg/g/" + i + "' border='0'/>") + "</a>"; return ret;}function writeAds(i,l,n,t) { w(getAds(i,l,n,t));}function recordAds(n) { var cc = getCookie('kbsAd', ''); if (cc.length > 0) cc = cc.split(','); else cc = new Array(); var i, now = parseInt((new Date()).getTime() / 1000); for(i=0;i<cc.length-1;i+=2) { if (cc[i] == n) { if (cc[i+1] > now - 1800) return; cc[i+1] = now; break; } } if (i >= cc.length - 1) { cc.push(n); cc.push(now); } window.frames['hfad'].document.location.href = 'http://dev.kcn.cn/adsense.php?' + n; var expire = new Date(); expire.setTime(expire.getTime() + 1800000); document.cookie = 'kbsAd=' + cc.join(',') + ';path=/;expires=' + expire.toGMTString();}function saveParaCookie(v, mask) { var ex = ''; if (!isLogin()) { var expire = new Date(); expire.setTime(expire.getTime() + 3600000 * 24 * 7); ex = ';expires=' + expire.toGMTString(); } var cook = (readParaCookie() & ~mask) | (v & mask); document.cookie = 'WWWPARAMS=' + cook + ex + ';path=/';}function readParaCookie() { return parseInt(getCookie('WWWPARAMS', 0));}function showUnread() { return (isLogin() && gIE && !gIE5 && (readParaCookie() & 0x1000));}function getUserid() { return getCookie("UTMPUSERID", "guest");}function isLogin() { return (getUserid() != "guest");}function queryString(param, def) { var url = location.search.toUpperCase() + "&"; param = param.toUpperCase(); if (!def) def=""; var pos = url.indexOf(param + "="); if (pos == -1) return def; pos += param.length + 1; return location.search.substring(pos, url.indexOf("&", pos));}function getObj(n) { return document.getElementById(n);}var bbsconImg = new Array();function resizeImg(obj) { bbsconImg.push(obj); obj.o_width = obj.width; var maxWidth = document.body.clientWidth - 40; if (obj.width > maxWidth) obj.width = maxWidth;}function adjustImg() { var maxWidth = document.body.clientWidth - 40; for (var i in bbsconImg) { var obj = bbsconImg[i]; var o_width = obj.o_width; obj.width = (o_width > maxWidth) ? maxWidth : o_width; }}window.onresize = adjustImg;function addEvent(obj,ev,func){ if (obj.attachEvent) { obj.attachEvent("on"+ev, func); } else if(obj.addEventListener) { obj.addEventListener(ev,func,true); } else { obj["on"+ev] = func; }}function cancelEvent(ev) { if (gIE) { ev.cancelBubble = true; ev.returnValue = false; } else { ev.preventDefault(); ev.stopPropagation(); }}function input_okd(obj, ev) { var evt = (ev) ? ev : ((window.event) ? event : null); if (evt == null) return true; var key = evt.keyCode ? evt.keyCode : evt.charCode; if (key == 13) { cancelEvent(evt); if (obj.form.onsubmit && !obj.form.onsubmit()) { return true; } obj.form.submit(); return false; } return true;}/* textarea onkeydown event handler. to submit form with ctrl+W(IE only) or ctrl+ENTER */function textarea_okd(func, ev) { var evt = (ev) ? ev : ((window.event) ? event : null); if (evt == null) return true; var key = evt.keyCode ? evt.keyCode : evt.charCode; if ((key == 87 && evt.ctrlKey) || (key == 13 && evt.ctrlKey)) { cancelEvent(evt); if (typeof func == "function") { func(); } else { func.form.submit(); } return false; } return true;}function setCursorPosition(oInput,oStart,oEnd) { oInput.focus(); if( oInput.setSelectionRange ) { oInput.setSelectionRange(oStart,oEnd); } else if( oInput.createTextRange ) { var range = oInput.createTextRange(); range.collapse(true); range.moveEnd('character',oEnd); range.moveStart('character',oStart); range.select(); }}function makeViewable(n) { var o = getObj(n), b = document.body; if (!o) return; var h1 = o.offsetTop, h2 = h1 + o.offsetHeight; var v1 = b.scrollTop, v2 = v1 + b.clientHeight; if (h1 >= v1 && h1 <= v2 && h2 >= v1 && h2 <= v2) return; if (h2 - h1 < v2 - v1) b.scrollTop = h2-(v2-v1); else b.scrollTop = h1;}/* refresh message frame */function alertmsg() { if (top.fmsg && !top.fmsg.document.getElementById("msgs")) top.fmsg.location.reload();}window.onload = function() { /* set focus */ var i,f = getObj("sfocus"); if (f) { f.focus(); setCursorPosition(f, 0, 0); } else { f = getObj("sselect"); if (f) { f.focus(); f.select(); } } /* * apply col class. this is a workaround for css2.1 - atppp * see also: http://ln.hixie.ch/?start=1070385285&count=1 * TODO: consider td's span properties * * also: apply alternate style for rows. * * Don't use this with long table, as IE runs it extremely slowly. */ var m = document.getElementsByTagName("table"); for(i=0;i<m.length;i++) { var tab = m[i]; if (tab.className.indexOf("adj") == -1) continue; var cols = tab.getElementsByTagName("col"); if (cols.length == 0) continue; var rows = tab.getElementsByTagName("tr"); for (var j=0;j<rows.length;j++) { var row = rows[j]; row.className = (j%2)?"odd":"even"; var td = row.getElementsByTagName("td"); for (var k=0;k<td.length;k++) { if (cols[k] && cols[k].className) { if (td[k].className) { td[k].className += " " + cols[k].className; } else { td[k].className = cols[k].className; } } } } } /* this is a workaround for some weird behavior... ask atppp if you are interested. BUGID 7629 */ if (gFx) { var ll, links = document.getElementsByTagName("link"); for(i=0; i<links.length; i++) { ll = links[i]; if((ll.getAttribute("rel") == "stylesheet")) { ll.disabled = true; ll.disabled = false; } } } for(i=0; i<bootFn.length; i++) { var fn = bootFn[i]; fn(); }};/* check required fields when submitting form. required fields are denoted with classname "req" */function chkreq(frm) { var f = frm.getElementsByTagName("input"); var i; for(i=0;i<f.length;i++) { var fe = f[i]; if (fe.className=="req") { if(fe.value==''){ alert('有必填内容为空'); fe.focus(); return false; } } } return true;}var gTimer;function footerStart() { var prefixZero = function(d) { if (d > 9) return d; else return "0" + d; }; var MyTimer = function() { this.start = (new Date()).getTime(); this.serverDiff = serverTime * 1000 - this.start; this.serverTime = serverTime * 1000; this.startTime = this.start - stayTime * 1000; this.lastStay = this.lastClock = ""; this.refreshTime = 0; this.userid = getUserid(); }; MyTimer.prototype.refresh = function() { var now = (new Date()).getTime(); this.serverTime = this.serverDiff + now; var Timer = new Date(this.serverTime); var str = Timer.getUTCFullYear() + "年" + prefixZero(Timer.getUTCMonth() + 1) + "月" + prefixZero(Timer.getUTCDate()) + "日" + prefixZero(Timer.getUTCHours()) + ":" + prefixZero(Timer.getUTCMinutes()); if (this.lastClock != str) { this.lastClock = str; getObj("divTime").innerHTML = str; } var staySec = (now - this.startTime) / 60000; str = parseInt(staySec/60) + "小时" + parseInt(staySec % 60) + "分钟"; if (this.lastStay != str) { this.lastStay = str; getObj("divStay").innerHTML = str; } var bF5 = (this.userid != getUserid()); if (bF5) { if (top.menu) top.menu.location.href = isLogin() ? 'bbsleft.php' : 'bbsguestleft.html'; } if ((this.refreshTime > 0 && now > this.refreshTime) || bF5) { location.reload(); } else { setTimeout("gTimer.refresh()", 1000); } }; gTimer = new MyTimer(); gTimer.refresh();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -