Muzer
4 Aug 2008, 10:34
As I said in my QuickQuote+ thread, I'm looking at porting it to FireFox. However, when I get it to run the script., I get:
txt is undefined
In the error console. Someone on IRC recommended I use a debugger, but I have no idea how to do so. All I managed to get it to do is watch the variable, which stays at null.
The code is pasted below:
"javascript:{var sel = document.createElement('div');
var s = window.getSelection();
if(s.toString() == '')
{
frm = document.getElementsByTagName('iframe')[document.getElementsByTagName('iframe').length - 1];
s = frm.contentWindow.getSelection();
}
if(s != '')sel.appendChild(s.getRangeAt(0).cloneContents() );
var ele = sel.getElementsByTagName('*');
for(var i=0, e; e=ele[i]; i++)
{
switch(e.tagName.toUpperCase())
{
case 'A' : e.innerHTML='[ url='+e.href+']'+e.innerHTML+'[/url ]';
break;
case 'FONT' : if(e.color)
{
e.innerHTML=''+e.innerHTML+''
};
if(/(?:^|,)\s*monospace\s*(?:,|$)/i.test(e.getAttribute('face')))
{
e.innerHTML='[ code]'+e.innerHTML+'[/code ]'
};
break;
case 'DIV' : if(e.className=='code')
{
e.innerHTML='[ code]'+e.innerHTML+'[/code ]'
}
else
{
if(e.className=='quote')
{
e.innerHTML='[ quote]'+e.innerHTML+'[/quote ]'
}
else
{
e.innerHTML='<br>'+e.innerHTML
}
};
break;
case 'B' : e.innerHTML='[ b]'+e.innerHTML+'[/b ]';
break;
case 'STRONG' : e.innerHTML='[ b]'+e.innerHTML+'[/b ]';
break;
case 'I' : e.innerHTML='[ i]'+e.innerHTML+'[/i ]';
break;
case 'U' : e.innerHTML='[ u]'+e.innerHTML+'[/u ]';
break;
case 'PRE' : e.innerHTML='[ code]'+e.innerHTML+'[/code ]';
break;
case 'BLOCKQUOTE' : e.innerHTML='[ quote]'+e.innerHTML+'[/quote ]';
break;
case 'IMG' : e.outerHTML+='[ img]'+e.src+'[/img ]';
break;
}
};
var txt = sel.innerText;
var n = txt.split('\n').length;
if(txt.toString() === '')
{
frm = document.getElementsByTagName('iframe')[document.getElementsByTagName('iframe').length - 1];
txt = frm.contentDocument.getSelection();
}
var ta = document.getElementsByTagName('textarea');
var tl=ta.length-1;
if(typeof window.qr_activate == 'function')
{
if(ta[tl].disabled)
{
qr_activate(1);
}
}
if(document.getElementById('qr_open'))
{
if(typeof window.my_show_div == 'function')
{
my_show_div(qr_open);
}
else
{
itm = document.getElementById('qr_open');
itm.style.display = '';
}
}
var t;
do
{
t=ta[tl];
tl--
}
while(t && (t.rows<5 || t.offsetHeight==0));
if(!t)
{
prompt('Please copy BBCode', txt);
exit(0);
}
if(t.rows < 15)
{
t.rows + n <= 15 ? t.rows += n : t.rows = 15
};
var nam='';
var url='';
var l=location.hostname;
var c=s.focusNode;
if(c && l=='forum.ru-board.com')
{
while(c.className!='tpc'&&c.parentNode)
{
c=c.parentNode
};
if(c.className!='tpc')exit(0);
var tn=c.parentNode.parentNode.childNodes[1].childNodes[0].childNodes[1];
nam='[ b]'+c.parentNode.firstChild.innerText.replace(/\n.*/g,'')+'[/b ] ';
url='[ url='+tn.childNodes[5].href+'][u ]'+tn.childNodes[7].innerText.replace(/^ +/,'').replace(/ +$/,'')+'[/u ][/url ] '
};
if(c && l=='operafan.net'||l=='opera-ac.com'||l=='bit-center.ru')
{
while(c.className!='windowbg'&&c.className!='windowbg2'&&c.parentNode)
{
c=c.parentNode
};
var dv=c.getElementsByTagName('div');
for(var i=0,di; di=dv[i]; i++)
{
if(di.className=='post')
{
c=di;
break
}
};
if(c.className!='post')exit(0);
var pn=c.parentNode.childNodes[1].firstChild.firstChild;
nam='[b ]'+c.parentNode.parentNode.firstChild.childNodes[1].innerText+'[/b ] ';
url='[ url='+pn.firstChild.firstChild.href+'][u ]'+/(\d\d\D\d.*\d).*$/.exec(pn.childNodes[1].innerText)[1]+'[/u ][/url ] '
};
if(t.value.indexOf(nam)!=-1){nam=''};
if(nam==''){var qtg='[ quote'}else{var qtg='[quote='};
if(t.value.indexOf(url)!=-1)url='';
t.focus();
document.selection.createRange().text += qtg+nam+']'+txt+'[/quote ]\r\n';
t.setSelectionRange(t.selectionEnd+n-1, t.selectionEnd+n-1);}"
EDIT: Please note I have added some spaces in order to stop the forum from parsing them
txt is undefined
In the error console. Someone on IRC recommended I use a debugger, but I have no idea how to do so. All I managed to get it to do is watch the variable, which stays at null.
The code is pasted below:
"javascript:{var sel = document.createElement('div');
var s = window.getSelection();
if(s.toString() == '')
{
frm = document.getElementsByTagName('iframe')[document.getElementsByTagName('iframe').length - 1];
s = frm.contentWindow.getSelection();
}
if(s != '')sel.appendChild(s.getRangeAt(0).cloneContents() );
var ele = sel.getElementsByTagName('*');
for(var i=0, e; e=ele[i]; i++)
{
switch(e.tagName.toUpperCase())
{
case 'A' : e.innerHTML='[ url='+e.href+']'+e.innerHTML+'[/url ]';
break;
case 'FONT' : if(e.color)
{
e.innerHTML=''+e.innerHTML+''
};
if(/(?:^|,)\s*monospace\s*(?:,|$)/i.test(e.getAttribute('face')))
{
e.innerHTML='[ code]'+e.innerHTML+'[/code ]'
};
break;
case 'DIV' : if(e.className=='code')
{
e.innerHTML='[ code]'+e.innerHTML+'[/code ]'
}
else
{
if(e.className=='quote')
{
e.innerHTML='[ quote]'+e.innerHTML+'[/quote ]'
}
else
{
e.innerHTML='<br>'+e.innerHTML
}
};
break;
case 'B' : e.innerHTML='[ b]'+e.innerHTML+'[/b ]';
break;
case 'STRONG' : e.innerHTML='[ b]'+e.innerHTML+'[/b ]';
break;
case 'I' : e.innerHTML='[ i]'+e.innerHTML+'[/i ]';
break;
case 'U' : e.innerHTML='[ u]'+e.innerHTML+'[/u ]';
break;
case 'PRE' : e.innerHTML='[ code]'+e.innerHTML+'[/code ]';
break;
case 'BLOCKQUOTE' : e.innerHTML='[ quote]'+e.innerHTML+'[/quote ]';
break;
case 'IMG' : e.outerHTML+='[ img]'+e.src+'[/img ]';
break;
}
};
var txt = sel.innerText;
var n = txt.split('\n').length;
if(txt.toString() === '')
{
frm = document.getElementsByTagName('iframe')[document.getElementsByTagName('iframe').length - 1];
txt = frm.contentDocument.getSelection();
}
var ta = document.getElementsByTagName('textarea');
var tl=ta.length-1;
if(typeof window.qr_activate == 'function')
{
if(ta[tl].disabled)
{
qr_activate(1);
}
}
if(document.getElementById('qr_open'))
{
if(typeof window.my_show_div == 'function')
{
my_show_div(qr_open);
}
else
{
itm = document.getElementById('qr_open');
itm.style.display = '';
}
}
var t;
do
{
t=ta[tl];
tl--
}
while(t && (t.rows<5 || t.offsetHeight==0));
if(!t)
{
prompt('Please copy BBCode', txt);
exit(0);
}
if(t.rows < 15)
{
t.rows + n <= 15 ? t.rows += n : t.rows = 15
};
var nam='';
var url='';
var l=location.hostname;
var c=s.focusNode;
if(c && l=='forum.ru-board.com')
{
while(c.className!='tpc'&&c.parentNode)
{
c=c.parentNode
};
if(c.className!='tpc')exit(0);
var tn=c.parentNode.parentNode.childNodes[1].childNodes[0].childNodes[1];
nam='[ b]'+c.parentNode.firstChild.innerText.replace(/\n.*/g,'')+'[/b ] ';
url='[ url='+tn.childNodes[5].href+'][u ]'+tn.childNodes[7].innerText.replace(/^ +/,'').replace(/ +$/,'')+'[/u ][/url ] '
};
if(c && l=='operafan.net'||l=='opera-ac.com'||l=='bit-center.ru')
{
while(c.className!='windowbg'&&c.className!='windowbg2'&&c.parentNode)
{
c=c.parentNode
};
var dv=c.getElementsByTagName('div');
for(var i=0,di; di=dv[i]; i++)
{
if(di.className=='post')
{
c=di;
break
}
};
if(c.className!='post')exit(0);
var pn=c.parentNode.childNodes[1].firstChild.firstChild;
nam='[b ]'+c.parentNode.parentNode.firstChild.childNodes[1].innerText+'[/b ] ';
url='[ url='+pn.firstChild.firstChild.href+'][u ]'+/(\d\d\D\d.*\d).*$/.exec(pn.childNodes[1].innerText)[1]+'[/u ][/url ] '
};
if(t.value.indexOf(nam)!=-1){nam=''};
if(nam==''){var qtg='[ quote'}else{var qtg='[quote='};
if(t.value.indexOf(url)!=-1)url='';
t.focus();
document.selection.createRange().text += qtg+nam+']'+txt+'[/quote ]\r\n';
t.setSelectionRange(t.selectionEnd+n-1, t.selectionEnd+n-1);}"
EDIT: Please note I have added some spaces in order to stop the forum from parsing them