📄 ubb.js
字号:
function RunCode(s) {
var win=window.open('', '', '');
win.opener = null;
win.document.write(s);
win.document.close();
}
function ubb2HTML(s) {
//图片UBB
s = s.replace(/\[img\](http|https|ftp):\/\/(.[^\[]*)\[\/img\]/ig, function($0, $1, $2) {
return "<a onfocus=\"this.blur()\" href=\""+$1+"://"+$2+"\" target=new><img src=\""+$1+"://"+$2+"\" border=\"0\" alt=\"按此在新窗口浏览图片\" onload=\"javascript:if(this.width>screen.width-333)this.width=screen.width-333\"></a>";
});
//链接UBB
s = s.replace(/(\[url\])(.[^\[]*)(\[\/url\])/ig, function($0, $1, $2) {
return "<a href=\""+$2+"\" target=\"new\">xxxx"+$2+"</a>";
});
s = s.replace(/\[url\=(.[^\[]*)\]/ig, function($0, $1, $2) {
return "<a href=\""+$1+"\" target=\"new\">";
});
//邮箱UBB
s = s.replace(/(\[email\])(.*?)(\[\/email\])/ig, function($0, $1, $2) {
return "<img align=\"absmiddle\" src=\"image/email1.gif\"><a href=\"mailto:"+$2+"\">"+$2+"</a>";
});
s = s.replace(/\[email\=(.[^\[]*)\]/ig, function($0, $1, $2) {
return "<img align='absmiddle' src='image/email1.gif'><a href=\"mailto:"+$2+"\" target='new'>";
});
//QQ号码UBB
s = s.replace(/\[qq=([1-9]*)\]([1-9]*)\[\/qq\]/ig, function($0, $1, $2) {
return "<a target='new' href=\"tencent://message/?uin="+$2+"&Site=ialvin.cn&Menu=yes\"><img border='0' src=\"http://wpa.qq.com/pa?p=1:"+$2+":"+$1+"\" alt='点击这里给我发消息'></a>";
});
//颜色UBB
s = s.replace(/\[color=(.[^\[]*)\]/ig, function($0, $1, $2) {
return "<font color=\""+$1+"\">";
});
//文字字体UBB
s = s.replace(/\[font=(.[^\[]*)\]/ig, function($0, $1, $2) {
return "<font face=\""+$1+"\">";
});
//文字大小UBB
s = s.replace(/\[size=([1-7])\]/ig, function($0, $1, $2) {
return "<font size=\""+$1+"\">";
});
//文字对齐方式UBB
s = s.replace(/\[align=(center|left|right)\]/ig, function($0, $1, $2) {
return "<div align=\""+$1+"\">";
});
//表格UBB
s = s.replace(/\[table=(.[^\[]*)\]/ig, function($0, $1, $2) {
return "<table width=\""+$1+"\">";
});
//FLASH动画UBB
s = s.replace(/(\[flash\])(http:\/\/.[^\[]*(.swf))(\[\/flash\])/ig, function($0, $1, $2) {
return "<a href=\""+$2+"\" target='new'><img src='image/swf.gif' border='0' alt='点击开新窗口欣赏该flash动画!' height='16' width='16'>[全屏欣赏]</a><br /><center><embed src=\""+$2+"\" pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash' type='application/x-shockwave-flash' width='300' height='200'></embed></object>";
});
s = s.replace(/(\[flash=*([0-9]*),*([0-9]*)\])(http:\/\/.[^\[]*(.swf))(\[\/flash\])/ig, function($0, $1, $2, $3, $4) {
return "<a href=\""+$4+"\" target='new'><img src='image/swf.gif' border='0' alt='点击开新窗口欣赏该flash动画!' height='16' width='16'>[全屏欣赏]</a><br /><center><embed src=\""+$4+"\" pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash' type='application/x-shockwave-flash' width='"+$2+"' height='"+$3+"'></embed></object>";
});
//MEDIA PLAY播放UBB
s = s.replace(/\[wmv\](.[^\[]*)\[\/wmv]/ig, function($0, $1) {
return "<object align='middle' classid='clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95' width='300' height='200'><param name='showstatusbar' value='-1'/><param name='filename' value=\""+$1+"\"/><embed type='application/x-oleobject' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701' src='"+$1+"' width='300' height='200'></embed></object>";
});
s = s.replace(/\[wmv=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/wmv]/ig, function($0, $1, $2, $3, $4) {
return "<object align='middle' classid='clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95' width='"+$1+"' height='"+$2+"'><param name='showstatusbar' value='-1'/><param name='filename' value=\""+$3+"\"/><embed type='application/x-oleobject' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701' src='"+$3+"' width='300' height='200'></embed></object>";
});
//REALPLAY 播放UBB
s = s.replace(/\[rm\](.[^\[]*)\[\/rm\]/ig, function($0, $1) {
return "<object classid='clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa' width='300' height='200'><param name='src' value=\""+$1+"\" /><param name='console' value='clip1' /><param name='controls' value='imagewindow' /><param name='autostart' value='true' /></object><br /><object classid='clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa' height='32' width='300' /><param name='src' value=\""+$1+"\" /><param name='autostart' value='-1' /><param name='controls' value='controlpanel' /><param name='console' value='clip1' /></object>";
});
s = s.replace(/\[rm=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/rm]/ig, function($0, $1, $2, $3, $4) {
return "<object classid='clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa' width='"+$1+"' height='"+$2+"'><param name='src' value=\""+$3+"\" /><param name='console' value='clip1' /><param name='controls' value='imagewindow' /><param name='autostart' value='true' /></object><br /><object classid='clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa' height='32' width='"+$1+"' /><param name='src' value=\""+$3+"\" /><param name='autostart' value='-1' /><param name='controls' value='controlpanel' /><param name='console' value='clip1' /></object>";
});
s = s.replace(/\r?\n/g, "<br />");
s = s.replace(/\[code\=[^\]]+\]([\d\D]*?)\[\/code\]/ig, function($0, $1) {
return $0.replace(/\<br \/\>/ig, "\r\n");
});
s = s.replace(/\u0020{2}/g, " ");
s = s.replace(/\[code\=[^\]]+\]([\d\D]*?)\[\/code\]/ig, function($0, $1) {
return $0.replace(/ /ig, " ");
});
// 代码
s = s.replace(/\[code\=([^\]]+)\]/ig, function($0, $1) {
return "<textarea name='code' class='" + $1 + "' cols='100'>";
});
var sarr = [
["\\/url", "</a>"],
["\\/email", "</a>"],
["\\/color", "</font>"],
["\\/size", "</font>"],
["\\/font", "</font>"],
["\\/align", "</div>"],
["b", "<b>"],
["\\/b", "</b>"],
["i", "<i>"],
["\\/i", "</i>"],
["u", "<u>"],
["\\/u", "</u>"],
["list", "<ul>"],
["list=1", "<ol type='1'>"],
["list=a", "<ol type='a'>"],
["\\*", "<li>"],
["\\/list", "</ul></ol>"],
["indent", "<blockquote>"],
["\\/indent", "</blockquote>"],
//["code", "<div><textarea name='codes' rows='12' cols='65'>"],
//["\\/code", "</textarea><br/><input type='button' value='运行代码' onclick='RunCode(this.parentNode.childNodes[0].value)'/> 提示:您可以先修改部分代码再运行</div>"],
//["code", "<textarea name='code' class='xml'>"],
["\\/code", "</textarea>"],
["quote", "<div style=\"background:#E2F2FF;width:90%;height:300px;border:1px solid #3CAAEC\">"],
["\\/quote", "</div>"],
["table", "<table>"],
["tr", "<tr>"],
["td", "<td>"],
["\\/tr", "</tr>"],
["\\/td", "</td>"],
["\\/table", "</table>"]
];
for (var i in sarr) {
var reg = new RegExp("\\["+sarr[i][0]+"\\]", "ig");
s = s.replace(reg, sarr[i][1]);
}
return s;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -