📄 ybbcode.js
字号:
var Quote = 0;
var Bold = 0;
var Italic = 0;
var Underline = 0;
var Code = 0;
function fontchuli(){
if ((document.selection)&&(document.selection.type == "Text")) {
var range = document.selection.createRange();
var ch_text=range.text;
range.text = fontbegin + ch_text + fontend;
}
else {
document.topic.content.value=fontbegin+document.topic.content.value+fontend;
document.topic.content.focus();
}
}
function AddText(text) {
if (document.topic.content.createTextRange && document.topic.content.caretPos) {
var caretPos = document.topic.content.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
text + ' ' : text;
}
else document.topic.content.value += text;
document.topic.content.focus(caretPos);
}
function COLOR(color){
fontbegin="[color="+color+"]";
fontend="[/color]";
fontchuli();
}
helpstat = false;
stprompt = true;
basic = false;
function thelp(swtch){
if (swtch == 1){
basic = false;
stprompt = false;
helpstat = true;
} else if (swtch == 0) {
helpstat = false;
stprompt = false;
basic = true;
} else if (swtch == 2) {
helpstat = false;
basic = false;
stprompt = true;
}
}
function Crm() {
if (helpstat) {
alert("realplay\n播放realplay文件.\n用法: [rm=宽度, 高度]文件地址[/rm]");
} else if (basic) {
AddTxt="[rm=500,350][/rm]";
AddText(AddTxt);
} else {
txt2=prompt("视频的宽度,高度","500,350");
if (txt2!=null) {
txt=prompt("视频文件的地址","请输入");
if (txt!=null) {
if (txt2=="") {
AddTxt="[rm=500,350]"+txt;
AddText(AddTxt);
AddTxt="[/rm]";
AddText(AddTxt);
} else {
AddTxt="[rm="+txt2+"]"+txt;
AddText(AddTxt);
AddTxt="[/rm]";
AddText(AddTxt);
}
}
}
}
}
function Cwmv() {
if (helpstat) {
alert("Media Player\n播放Media Player文件.\n用法: [mp=宽度, 高度]文件地址[/mp]");
} else if (basic) {
AddTxt="[mp=500,350][/mp]";
AddText(AddTxt);
} else {
txt2=prompt("视频的宽度,高度","500,350");
if (txt2!=null) {
txt=prompt("视频文件的地址","请输入");
if (txt!=null) {
if (txt2=="") {
AddTxt="[mp=500,350]"+txt;
AddText(AddTxt);
AddTxt="[/mp]";
AddText(AddTxt);
} else {
AddTxt="[mp="+txt2+"]"+txt;
AddText(AddTxt);
AddTxt="[/mp]";
AddText(AddTxt);
}
}
}
}
}
function Cdir() {
if (helpstat) {
alert("Shockwave\n插入Shockwave文件.\n用法: [dir=宽度, 高度]文件地址[/dir]");
} else if (basic) {
AddTxt="[dir=500,350][/dir]";
AddText(AddTxt);
} else {
txt2=prompt("Shockwave文件的宽度,高度","500,350");
if (txt2!=null) {
txt=prompt("Shockwave文件的地址","请输入地址");
if (txt!=null) {
if (txt2=="") {
AddTxt="[dir=500,350]"+txt;
AddText(AddTxt);
AddTxt="[/dir]";
AddText(AddTxt);
} else {
AddTxt="[dir="+txt2+"]"+txt;
AddText(AddTxt);
AddTxt="[/dir]";
AddText(AddTxt);
}
}
}
}
}
function ybbsize(theSmilie){
var text=prompt("请输入文字", "");
if(text){
document.topic.content.value += '[size=' + theSmilie + ']'+ text + '[/size]';
}
}
function showsize(theSmilie){
var text=prompt("请输入文字", "");
if(text){
document.topic.content.value += '[face=' + theSmilie + ']'+ text + '[/face]';
}
}
function image() {
var FoundErrors = '';
var enterURL = prompt("请输入图片地址","http://");
if (!enterURL) {
FoundErrors +="\n";
}
if (FoundErrors) {
return;
}
var ToAdd = "[IMG]"+enterURL+"[/IMG]";
document.topic.content.value+=ToAdd;
document.topic.content.focus();
}
function fly() {
fontbegin="[fly]";
fontend="[/fly]";
fontchuli();
}
function move() {
fontbegin="[move]";
fontend="[/move]";
fontchuli();
}
function center() {
fontbegin="[align=center]";
fontend="[/align]";
fontchuli();
}
function light() {
fontbegin="[light]";
fontend="[/light]";
fontchuli();
}
function grade() {
var ToAdd = "[showtograde=1]内容[/s]";
document.topic.content.value+=ToAdd;
document.topic.content.focus();
}
function name() {
var ToAdd = "[showtoname=对方昵称]内容[/s]";
document.topic.content.value+=ToAdd;
document.topic.content.focus();
}
function reply() {
var ToAdd = "[showtoreply]内容[/s]";
document.topic.content.value+=ToAdd;
document.topic.content.focus();
}
function ying() {
fontbegin="[SHADOW=255,yellow,1]";
fontend="[/shadow]";
fontchuli();
}
function smark() {
var ToAdd = "[smark=10]内容[/s]";
document.topic.content.value+=ToAdd;
document.topic.content.focus();
}
function Curl() {
var FoundErrors = '';
var enterURL = prompt("请输入连接网址", "http://");
var enterTxT = prompt("请输入连接说明", enterURL);
if (!enterURL) {
FoundErrors += "\n" + "您必须输入网址";
}
if (!enterTxT) {
FoundErrors += "\n" + "您必须连接说明";
}
if (FoundErrors) {
alert("错误!"+FoundErrors);
return;
}
var ToAdd = "[URL="+enterURL+"]"+enterTxT+"[/URL]";
document.topic.content.value+=ToAdd;
document.topic.content.focus();
}
function showdate() {
var FoundErrors = '';
var enterdate=prompt("请输入日期按这样格式2005-10-1,该帖将这天以后方能浏览","2005-10-1");
if (!enterdate) {
FoundErrors += "\n" +"请输入正确日期";
}
if (FoundErrors) {
alert("错误!"+FoundErrors);
return;
}
var ToAdd = "[showdate="+enterdate+"]内容[/s]";
document.topic.content.value+=ToAdd;
document.topic.content.focus();
}
function Cemail() {
var emailAddress = prompt("请输入邮件地址","");
if (!emailAddress) { alert("请输入正确的email地址"); return; }
var ToAdd = "[email]"+emailAddress+"[/email]";
document.topic.content.value+=ToAdd;
document.topic.content.focus();
}
function Cbold() {
fontbegin="[B]";
fontend="[/B]";
fontchuli();
}
function Citalic() {
fontbegin="[I]";
fontend="[/I]";
fontchuli();
}
function Cunder() {
fontbegin="[U]";
fontend="[/U]";
fontchuli();
}
function mustlogin() {
var ToAdd = "[mustlogin]内容[/s]";
document.topic.content.value+=ToAdd;
document.topic.content.focus();
}
function DoTitle(addTitle){
document.topic.topic.value=addTitle+document.topic.topic.value;
document.topic.topic.focus();
}
function openwin()
{
document.forms[1].topic.value=document.forms[0].topic.value;
document.forms[1].content.value=document.forms[0].content.value;
var popupWin = window.open('post.asp?action=preview', 'showgg', 'width=500,height=400,resizable=1,scrollbars=yes,menubar=no,status=yes');
document.forms[1].submit()
}
function Csound() {
var FoundErrors = '';
var enterURL = prompt("请输入背景音乐地址", "http://");
if (!enterURL) {
FoundErrors += "\n" + "您必须要输入有效地址";
}
if (FoundErrors) {
alert("错误!"+FoundErrors);
return;
}
var ToAdd = "[SOUND]"+enterURL+"[/SOUND]";
document.topic.content.value+=ToAdd;
document.topic.content.focus();
}
function Cswf() {
if (helpstat){
alert("Flash\nFlash 动画.\n用法: [flash=宽度, 高度]Flash 文件的地址[/flash]");
} else if (basic) {
AddTxt="[flash=500,350][/flash]";
AddText(AddTxt);
} else {
txt2=prompt("flash宽度,高度","500,350");
if (txt2!=null) {
txt=prompt("Flash 文件的地址","http://");
if (txt!=null) {
if (txt2=="") {
AddTxt="[flash=500,350]"+txt;
AddText(AddTxt);
AddTxt="[/flash]";
AddText(AddTxt);
} else {
AddTxt="[flash="+txt2+"]"+txt;
AddText(AddTxt);
AddTxt="[/flash]";
AddText(AddTxt);
}
}
}
}
}
function html_trans(str) {
str = str.replace(/\r/g,"");
str = str.replace(/on(load|click|dbclick|mouseover|mousedown|mouseup)="[^"]+"/ig,"");
str = str.replace(/<script[^>]*?>([\w\W]*?)<\/script>/ig,"");
str = str.replace(/<a[^>]+href="([^"]+)"[^>]*>(.*?)<\/a>/ig,"[url=$1]$2[/url]");
str = str.replace(/<font[^>]+size=([^ >]+)[^>]*>(.*?)<\/font>/ig,"[size=$1]$2[/size]");
str = str.replace(/<font[^>]+color=([^ >]+)[^>]*>(.*?)<\/font>/ig,"[color=$1]$2[/color]");
str = str.replace(/<div[^>]+align=([^ >]+)[^>]*>(.*?)<\/div>/ig,"[align=$1]$2[/align]");
str = str.replace(/<img[^>]+src="([^"]+)"[^>]*>/ig,"[img]$1[/img]");
str = str.replace(/<([\/]?)b>/ig,"[$1b]");
str = str.replace(/<([\/]?)strong>/ig,"[$1b]");
str = str.replace(/<([\/]?)u>/ig,"[$1u]");
str = str.replace(/<([\/]?)i>/ig,"[$1i]");
str = str.replace(/ /g," ");
str = str.replace(/&/g,"&");
str = str.replace(/"/g,"\"");
str = str.replace(/</g,"<");
str = str.replace(/>/g,">");
str = str.replace(/<br>/ig,"\n");
str = str.replace(/<[^>]*?>/g,"");
str = str.replace(/\[url=([^\]]+)\]\n(\[img\]\1\[\/img\])\n\[\/url\]/g,"$2");
str = str.replace(/\n+/g,"\n");
return str;
}
function trans(){
var str = "";
rtf.focus();
rtf.document.body.innerHTML = "";
rtf.document.execCommand("paste");
str = rtf.document.body.innerHTML;
if(str.length == 0) {
alert("剪切版不存在超文本数据!");
return "";
}
return html_trans(str);
}
function showpic() {
window.open ("images/emote/index.htm", "", "width=600,height=300,resizable=no,scrollbars=no,menubar=no,status=no");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -