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

📄 ctbcode.js

📁 详细对一般字符串表达式解析
💻 JS
字号:
function insertstr(str) {
	if (document.ctbform.postBody) {
		if (document.all) {
			insertAtCaret(document.ctbform.postBody, str);
		}
		else {
			document.ctbform.postBody.value += str;
		}
		document.ctbform.postBody.focus();
	}
	else if (document.ctbform.replyBody) {
		if (document.all) {
			insertAtCaret(document.ctbform.replyBody, str);
		}
		else {
			document.ctbform.replyBody.value += str;
		}
		document.ctbform.replyBody.focus();
	}
}

function storeCaret(textEl) {
	if (textEl.createTextRange) {
		textEl.caretPos = document.selection.createRange().duplicate();
	}
}

function insertAtCaret(textEl, text) {
	if (textEl.createTextRange && textEl.caretPos) {
		var caretPos = textEl.caretPos;
		caretPos.text += caretPos.text.charAt(caretPos.text.length - 2) == ' ' ? text + ' ' : text;
	}
	else if (textEl) {
		textEl.value += text;
	}
	else {
		textEl.value = text;
	}
}

function btn_b() {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[b]" + range.text + "[/b]";
	}
	else {
		txt = prompt("粗体文字:", "粗体文字");
		if (txt != null) {
			insertstr("[b]");
			insertstr(txt);
			insertstr("[/b]");
		}
	}
}

function btn_i() {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[i]" + range.text + "[/i]";
	}
	else {
		txt = prompt("斜体文字:", "斜体文字");
		if (txt != null) {
			insertstr("[i]");
			insertstr(txt);
			insertstr("[/i]");
		}
	}
}

function btn_u() {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[u]" + range.text + "[/u]";
	}
	else {
		txt = prompt("下划线文字:", "下划线文字");
		if (txt != null) {
			insertstr("[u]");
			insertstr(txt);
			insertstr("[/u]");
		}
	}
}

function btn_url() {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[url]" + range.text + "[/url]";
	}
	else {
		txt = prompt("URL:", "http://");
		if (txt != null) {
			insertstr("[url]");
			insertstr(txt);
			insertstr("[/url]");
		}
	}
}

function btn_email() {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[email]" + range.text + "[/email]";
	}
	else {
		txt = prompt("Email:", "@");
		if (txt != null) {
			insertstr("[email]");
			insertstr(txt);
			insertstr("[/email]");
		}
	}
}

function btn_img() {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[img]" + range.text + "[/img]";
	}
	else {
		txt = prompt("图片的 URL 地址:", "http://");
		if (txt != null) {
			insertstr("[img]");
			insertstr(txt);
			insertstr("[/img]");
		}
	}
}

function btn_swf() {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[swf x=480 y=360]" + range.text + "[/swf]";
	}
	else {
		txt = prompt("Flash 动画的 URL 地址(x:100~699,y:100~999):", "http://");
		if (txt != null) {
			insertstr("[swf x=480 y=360]");
			insertstr(txt);
			insertstr("[/swf]");
		}
	}
}

function btn_q() {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[quote]" + range.text + "[/quote]";
	}
	else {
		txt = prompt("引用内容:", "引用文字");
		if (txt != null) {
			insertstr("[quote]");
			insertstr(txt);
			insertstr("[/quote]");
		}
	}
}

function btn_code() {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[code]" + range.text + "[/code]";
	}
	else {
		txt = prompt("程式代码:", "程式代码");
		if (txt != null) {
			insertstr("[code]");
			insertstr(txt);
			insertstr("[/code]");
		}
	}
}

function btn_rp() {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[rp x=480 y=360]" + range.text + "[/rp]";
	}
	else {
		txt = prompt("Real 多媒体链接(x:100~699,y:100~999):", "http://");
		if (txt != null) {
			insertstr("[rp x=480 y=360]");
			insertstr(txt);
			insertstr("[/rp]");
		}
	}
}

function btn_mp() {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[mp x=480 y=390]" + range.text + "[/mp]";
	}
	else {
		txt = prompt("Windows Media Player 多媒体链接(x:100~699,y:100~999):", "http://");
		if (txt != null) {
			insertstr("[mp x=480 y=390]");
			insertstr(txt);
			insertstr("[/mp]");
		}
	}
}

function showcolor(color) {
	if (color && document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[color=" + color + "]" + range.text + "[/color]";
	}
	else if (color) {
		txt = prompt("文字颜色:" + color, "文字颜色");
		if (txt != null) {
			insertstr("[color=");
			insertstr(color);
			insertstr("]");
			insertstr(txt);
			insertstr("[/color]");
		}
	}
}

function xfont(font) {
	if (font && document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[font=" + font + "]" + range.text + "[/font]";
	}
	else if (font) {
		txt = prompt("字体:" + font, "字体");
		if (txt != null) {
			insertstr("[font=");
			insertstr(font);
			insertstr("]");
			insertstr(txt);
			insertstr("[/font]");
		}
	}
}

function fontSize(size) {
	if (size && document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[size=" + size + "]" + range.text + "[/size]";
	}
	else if (size >= 1 && size <= 7) {
		txt = prompt("文字大小(1~7):" + size, "文字大小");
		if (txt != null) {
			insertstr("[size=");
			insertstr(size);
			insertstr("]");
			insertstr(txt);
			insertstr("[/size]");
		}
	}
}

function xpos(pos) {
	if (pos && document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[" + pos + "]" + range.text + "[/" + pos + "]";
	}
	else if (pos == 'center') {
		txt = prompt("居中文字:", "居中文字");
		if (txt != null) {
			insertstr("[center]");
			insertstr(txt);
			insertstr("[/center]");
		}
	}
	else if (pos == 'right') {
		txt = prompt("靠右文字:", "靠右文字");
		if (txt != null) {
			insertstr("[right]");
			insertstr(txt);
			insertstr("[/right]");
		}
	}
}

function xaction(act) {
	if (act && document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[" + act + "]" + range.text + "[/" + act + "]";
	}
	else if (act == 'fly') {
		txt = prompt("飞行文字:", "我要飞~");
		if (txt != null) {
			insertstr("[fly]");
			insertstr(txt);
			insertstr("[/fly]");
		}
	}
	else if (act == 'move') {
		txt = prompt("滚动文字:", "滚来滚去");
		if (txt != null) {
			insertstr("[move]");
			insertstr(txt);
			insertstr("[/move]");
		}
	}
}

function xlook(look) {
	if (look && document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[" + look + "]" + range.text + "[/" + look + "]";
	}
	else if (look == 'glow') {
		txt = prompt("发光文字:", "发光文字");
		if (txt != null) {
			insertstr("[glow]");
			insertstr(txt);
			insertstr("[/glow]");
		}
	}
	else if (look == 'shadow') {
		txt = prompt("阴影文字:", "阴影文字");
		if (txt != null) {
			insertstr("[shadow]");
			insertstr(txt);
			insertstr("[/shadow]");
		}
	}
}

⌨️ 快捷键说明

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