本人制作的这个转帖工具的代码:
---------------------------------------------------------------------------------------------------------------------------------
DLLC
1234自制转帖工具
');
str = str.replace(/\[b\]([\s\S]*?)\[\/b\]/ig,
"$1").replace(/\[u\]([\s\S]*?)\[\/u\]/ig,
"$1").replace(/\[i\]([\s\S]*?)\[\/i\]/ig,
"$1");
str = str.replace(/\[align=center\]([\s\S]*?)\[\/align\]/ig, '
$1
');
str = str.replace(/\n/ig,
"\n ");
return (str);
}
function cuturl(url){
var length =
65;
var urllink = '
';
if(url.length > length) {
url = url.substr(0, parseInt(length * 0.5)) + ' ... ' + url.substr(url.length - parseInt(length * 0.3));
}
urllink += url + '';
return urllink;
}
function switch_Edt(m){
if(m == Editor_Mode) return;
var ubb='', html='', obj;
if(Editor_Mode == 0){
ubb = $('UBB_Editor').value;
$('UBB_Editor').style.display = "none";
$('UBB_btn').className = "normal";
}else if(Editor_Mode == 1){
html = $('HTML_Editor').value;
$('HTML_Editor').style.display = "none";
$('HTML_btn').className = "normal";
}else{
html = $('Visual_Editor').contentWindow.document.body.innerHTML;
$('Visual_Editor').style.display = "none";
$('Visual_btn').className = "normal";
}
if(m == 0){
if(ubb=='') ubb = html2ubb(html);
$('UBB_Editor').style.display = "block";
$('UBB_btn').className = "current";
obj = $('UBB_Editor');
obj.value = ubb;
$('dupBtn').style.display = "inline";
$('enB64').style.visibility = "visible";
$('deB64').style.visibility = "visible";
$('pic_filter').style.visibility = "hidden";
}else if(m == 1){
if(html=='') html = ubb2html(ubb);
else html = html.replace(/ ]*?>/ig, "\n ");
$('HTML_Editor').style.display = "block";
$('HTML_btn').className = "current";
obj = $('HTML_Editor');
obj.value = html;
$('dupBtn').style.display = "none";
$('enB64').style.visibility = "hidden";
$('deB64').style.visibility = "hidden";
$('pic_filter').style.visibility = "hidden";
}else{
if(html=='') html = ubb2html(ubb);
$('Visual_Editor').style.display = "block";
$('Visual_btn').className = "current";
obj = $('Visual_Editor').contentWindow.document.body;
obj.innerHTML = html;
$('dupBtn').style.display = "none";
$('enB64').style.visibility = "hidden";
$('deB64').style.visibility = "hidden";
$('pic_filter').style.visibility = "visible";
}
Editor_Mode = m;
focusAtEnd(obj);
sum_word();
}
function focusAtEnd(obj){
obj.focus();
if(Editor_Mode==2){
var sel = obj.ownerDocument.selection.createRange();
var str = obj.innerHTML;
}else{
var sel = obj.createTextRange();
var str = obj.value;
}
var len = (str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
sel.moveStart('character', len);
sel.collapse();
sel.select();
}
function copycode(){
var obj;
if(Editor_Mode==2){
obj = $('Visual_Editor').contentWindow.document.body;
}else{
obj = (Editor_Mode==0) ? 'UBB_Editor' : 'HTML_Editor';
obj = $(obj);
obj.select();
}
obj.createTextRange().execCommand("Copy")
}
function transData(){
var str = "";
$('rtf').contentWindow.focus();
$('rtf').contentWindow.document.body.innerHTML = '';
$('rtf').contentWindow.document.execCommand("paste");
str = $('rtf').contentWindow.document.body.innerHTML;
if(str.length == 0) {
alert("剪贴板不存在超文本数据!");
return "";
}
str = (Editor_Mode==0) ? html2ubb(filter_html(str)) : filter_html(str);
return str;
}
function trans(){
if(Editor_Mode==0){
$('UBB_Editor').value = transData();
}else if(Editor_Mode==1){
$('HTML_Editor').value = transData();
}else{
$('Visual_Editor').contentWindow.document.body.innerHTML = transData();
}
sum_word();
}
function trans2(){
if(Editor_Mode==0){
$('UBB_Editor').value += "\r\n\r\n" + transData();
}else if(Editor_Mode==1){
$('HTML_Editor').value += "\r\n \r\n " + transData();
}else{
$('Visual_Editor').contentWindow.document.body.innerHTML += "
" + transData();
}
sum_word();
}
function preview(){
var html;
if(Editor_Mode == 0){
html = ubb2html($("UBB_Editor").value);
}else if(Editor_Mode == 1){
html = $("HTML_Editor").value;
}else{
html = $("Visual_Editor").contentWindow.document.body.innerHTML;
}
var nWin = window.open("", "_blank");
nWin.document.write(html);
nWin.document.close();
}
function clearEdt(){
if(Editor_Mode == 0){
$("UBB_Editor").value = "";
}else if(Editor_Mode == 1){
$("HTML_Editor").value = "";
}else{
$("Visual_Editor").contentWindow.document.body.innerHTML = "";
}
$("words").innerHTML = "0";
}
function zhen(str){
strfound = str.replace(/\\/ig,"\\\\");
strfound = strfound.replace(/\[/ig,"\\[");
strfound = strfound.replace(/\]/ig,"\\]");
strfound = strfound.replace(/\{/ig,"\\{");
strfound = strfound.replace(/\}/ig,"\\}");
strfound = strfound.replace(/\|/ig,"\\|");
strfound = strfound.replace(/\//ig,"\\/");
strfound = strfound.replace(/\^/ig,"\\^");
strfound = strfound.replace(/\./ig,"\\.");
strfound = strfound.replace(/\*/ig,"\\*");
strfound = strfound.replace(/\?/ig,"\\?");
strfound = strfound.replace(/\+/ig,"\\+");
return strfound;
}
function replace_star(){
var str;
if(Editor_Mode == 0){
str = $("UBB_Editor").value;
}else if(Editor_Mode == 1){
str = $("HTML_Editor").value;
}else{
str = $("Visual_Editor").contentWindow.document.body.innerHTML;
}
var strfound = (reg.checked) ? $('find_text').value : zhen($('find_text').value) ;
var re = new RegExp(strfound, "ig");
str = str.replace(re, $("replace_text").value);
if(Editor_Mode == 0){
$("UBB_Editor").value = str;
}else if(Editor_Mode == 1){
$("HTML_Editor").value = str;
}else{
$("Visual_Editor").contentWindow.document.body.innerHTML = str;
}
sum_word();
}
function font_checker(obj){
var o = $('set').font_all;
if(! obj.checked && o.checked)
o.checked = false;
}
function pasteData(){
if(!$('x_paste').checked) return true;
if(Editor_Mode==2){
var str = transData();
$('rtf').contentWindow.document.body.innerHTML = str;
$('rtf').contentWindow.focus();
$('rtf').contentWindow.document.body.createTextRange().execCommand("Copy");
}else{
clipboardData.setData('text',transData());
}
return true;
}
function attPasteEvt(){
$('Visual_Editor').contentWindow.document.body.onpaste = pasteData;
$('Visual_Editor').onload = null;
}
function filter_Font(Obj){
Obj = Obj.checked;
$('font_color').checked = Obj;
$('font_size').checked = Obj;
$('font_face').checked = Obj;
$('font_b').checked = Obj;
$('font_i').checked = Obj;
$('font_u').checked = Obj;
}
function fltBaseUrl(){
if($('filtrate').checked)
$('base_url').style.display = 'block';
else
$('base_url').style.display = 'none';
}
function clearBaseUrl(){
$('textfield').value = '';
}
function reset(){
$('set').reset();
fltBaseUrl();
$('find_text').value = '';
$('replace_text').value = '';
$('textfield').value = '';
}
function configTip(msg){
var e;
try{
clearTimeout(Timer);
}catch(e){}
$('config_tip').innerHTML = msg;
Timer = setTimeout('$("config_tip").innerHTML=""', 1000);
}
function Simplized(){
var obj;
if(Editor_Mode==0){
obj = $('UBB_Editor');
obj.value = convJT(obj.value);
}else if(Editor_Mode==1){
obj = $('HTML_Editor');
obj.value = convJT(obj.value);
}else{
obj = $('Visual_Editor').contentWindow.document.body;
StranBody(obj, 0);
}
}
function Traditionalized(){
var obj;
if(Editor_Mode==0){
obj = $('UBB_Editor');
obj.value = convFT(obj.value);
}else if(Editor_Mode==1){
obj = $('HTML_Editor');
obj.value = convFT(obj.value);
}else{
obj = $('Visual_Editor').contentWindow.document.body;
StranBody(obj, 1);
}
}
function QQ90sized(){
var obj;
if(Editor_Mode==0){
obj = $('UBB_Editor');
obj.value = convQQ(obj.value);
}else if(Editor_Mode==1){
obj = $('HTML_Editor');
obj.value = convQQ(obj.value);
}else{
obj = $('Visual_Editor').contentWindow.document.body;
StranBody(obj, 2);
}
}
function noDuplicate(){
var o = $("UBB_Editor");
var ary = o.value.replace(/^\s*|\s*$/g, "").split("\r\n");
var re = {};
var str = "", s;
for(var i = 0, len = ary.length, j = 0; i < len; i++){
s = ary[i];
if(s == ""){
str += "\r\n";
j++;
}else{
if(!re[s]){
re[s] = true;
str += s +"\r\n";
j++;
}
}
}
str = str.substr(0, str.length-2);
o.value = str;
configTip(len + "->" + j);
sum_word();
}
function decodeBase64(){
var o = $("UBB_Editor");
o.value = base64decode(o.value);
sum_word();
}
function encodeBase64(){
var o = $("UBB_Editor");
o.value = base64encode(o.value);
sum_word();
}
function moreTool(){
$('advTool').style.display = ($('advTool').style.display=="block") ? "none" : "block";
}
function sum_word(){
var s;
if(Editor_Mode == 0){
s = $("UBB_Editor").value.length;
}else if(Editor_Mode == 1){
s = $("HTML_Editor").value.length;
}else{
s = $("Visual_Editor").contentWindow.document.body.innerHTML.length;
}
$("words").innerHTML = ""+s;
}
function init(){
$('rtf').contentWindow.document.designMode = "On";
$('Visual_Editor').contentWindow.document.designMode = "On";
$('set').reset();
}
if(window.addEventListener){
window.addEventListener('load', init, false);
}else{
window.attachEvent('onload', init);
}
|
有话要说...