// ==UserScript==
// @name whirlpoolPosting
// @namespace jaromanda/GreaseMonkey
// @description quick reply and whirlcode shortcuts v8.3
// @include http://forums.whirlpool.net.au/forum-reply*
// @include http://forums.whirlpool.net.au/forum-replies*
// @include http://forums.whirlpool.net.au/index.cfm?a=wiki*
// @include http://forums.whirlpool.net.au/whim-send*
// ==/UserScript==
(function(){
var noQuickQuote=GM_getValue("QuickQuote", "show") == "hide";
var uWin=unsafeWindow?unsafeWindow:window;
var qqRoot=null;
var qQuote=null;
var replyURL='';
var inReply=document.location.href.indexOf('forum-reply.cfm?r=')>-1;
var inEdit=document.location.href.indexOf('forum-reply.cfm?e=')>-1;
var inThread=document.location.href.indexOf('forum-replies.cfm')>-1;
var inWiki=document.location.href.indexOf('index.cfm?a=wiki')>-1;
var inWhim=document.location.href.indexOf('whim-send')>-1;
var replyArea=document.getElementById('body');
var replyNumber=0;
var savedNumber=GM_getValue('savedNumber', 'C');
var savedText=(savedNumber=='C')?'':unescape(GM_getValue('savedText', ''));
var threadId=0;
var EventManager= {
_registry: null,
Initialise: function() {
if (this._registry == null) {
this._registry = [];
EventManager.Add(window, '_unload', this.CleanUp);
}
},
Add: function(obj, type, fn, useCapture) {
this.Initialise();
var realType=(type=='_unload'?'unload':type);
if (typeof obj == 'string')
obj = document.getElementById(obj);
if (obj == null || fn == null)
return false;
obj.addEventListener(realType, fn, useCapture);
this._registry.push({obj:obj, type:type, fn:fn, useCapture:useCapture});
return true;
},
CleanUp: function() {
for (var i = 0; i < EventManager._registry.length; i++) {
with(EventManager._registry[i]) {
if(type=='unload') fn();
obj.removeEventListener(type,fn,useCapture);
}
}
EventManager._registry = null;
}
};
//
// buttons to add
//
var buttons={
whirlBold :{ value:'-b-old', whirl:'*', key:'b' },
whirlItalic :{ value:'-i-talic', whirl:'/', key:'i' },
whirlSingleQuote :{ value:"'quo-t-e'", whirl:"'", key:'t' },
whirlDoubleQuote :{ value:'"-q-uote"', whirl:'"', key:'q' },
whirlQuote :{ value:'w-h-o', whirl:'+', key:'h' }, // looks like rubbish
whirlSuperscript :{ value:'su-p-er', whirl:'^', key:'p' },
whirlSubscript :{ value:'sub-\\-', whirl:'\\', key:'\\' },
whirlStrike :{ value:'stri-k-e', whirl:'-', key:'k' },
whirlCourier :{ value:'-c-ourier', whirl:'#', key:'c' },
whirlSmall :{ value:'s-m-all', whirl:'()', key:'m' },
whirlGrey :{ value:'g-r-ey', whirl:'`', key:'r' },
whirlSerif :{ value:'-s-erif', whirl:'~', key:'s' },
whirlGoogle :{ value:'-g-oogle', whirl:'?', key:'g' },
whirlEscape :{ value:'-e-sc', whirl:'.', key:'e' },
whirlWiki :{ value:'-w-iki', whirl:'[]', key:'w', re:/_/g, replace:' ' },
makeUrlText :{ value:'-l-ink', key:'l' },
makeUrlHref :{ value:'-u-rl', key:'u' },
cleanupCode :{ value:'cle-a-n', key:'a' }
};
function saveText() {
var e=document.getElementById('qqText');
var txt=e?e.value:'';
if(txt.length && threadId) {
GM_setValue("savedText", escape(txt));
GM_setValue("savedNumber", "T"+threadId);
}
}
function getAny(trig) { // get a single node specified in an xPath
var res = document.evaluate(trig,document,null,XPathResult.ANY_UNORDERED_NODE_TYPE,null);
return res.singleNodeValue;
}
var buttonStack=[];
function flushStack() {
while(buttonStack.length) {
var xB=buttonStack.pop();
xB.opened=false;
if(!xB.hidden) xB.el.className='whirlyCSS';
}
}
// new
function shortcutKeys(e){
if (e.ctrlKey==1 && e.keyCode==13 )
postReply();
else if (e.ctrlKey==1 && e.keyCode==92 )
postPreview();
else if (e.ctrlKey==1 && e.keyCode==32)
clearQuote();
}
// old
function clearQuote() {
flushStack();
document.getElementById('qqText').value = '';
document.getElementById('qqText').focus();
}
function postReply() {
var txt=document.getElementById('qqText').value;
if(txt.length && replyNumber) {
GM_setValue("savedText", escape(txt));
GM_setValue("savedNumber", "R"+replyNumber);
clearQuote();
}
document.location = replyURL;
}
function postPreview() {
var txt=document.getElementById('qqText').value;
if(txt.length && replyNumber) {
GM_setValue("savedText", escape(txt));
GM_setValue("savedNumber", "P"+replyNumber);
clearQuote();
}
document.location = replyURL;
}
function setButtons(e) {
var ta=e.currentTarget;
var selEnd=ta.selectionEnd;
var txt=ta.value.substring(0,selEnd);
for(o in buttons) {
var btn=buttons[o];
if(btn.whirl) {
var op='['+btn.whirl.substr(0,1);
var cl=btn.whirl.substr(-1)+']';
btn.opened=txt.split(op).length>txt.split(cl).length;
if(!btn.hidden) {
btn.el.className=btn.opened?'whirlyCSSopen':'whirlyCSS';
}
}
}
}
function toggleQuote() {
var qqCnt = document.getElementById('qqCnt');
qqCnt.className = (qqCnt.className == 'qqInline') ? 'qqFloat' : 'qqInline';
}
function createQuote(txt) {
if(noQuickQuote) return null;
var qqContain = document.createElement('div');
qqContain.id = 'qqCnt';
qqContain.className = 'qqInline';
var qqDiv = document.createElement('div');
qqDiv = qqContain.appendChild(qqDiv);
qqDiv.align = 'center';
qQuote = document.createElement('textarea');
qQuote.name ='qqText';
qQuote.id = 'qqText';
qQuote.className='textCSS';
qQuote.cols = '100';
qQuote.rows = '10';
qQuote.value = unescape(txt);
qQuote=qqDiv.appendChild(qQuote);
EventManager.Add(qQuote, "keydown", shortcutKeys, false);
var brk = document.createElement('br');
qqDiv.appendChild(brk);
var prevBtn =document.createElement('input');
prevBtn.type = 'submit';
prevBtn.className= 'previewCSS';
prevBtn.value='Show Preview' ;
prevBtn.accessKey ='v';
prevBtn.addEventListener('click', postPreview, false);
qqDiv.appendChild(prevBtn);
var prevBtn =document.createElement('input');
prevBtn.type = 'submit';
prevBtn.className= 'submitCSS';
prevBtn.value='Post Reply' ;
prevBtn.accessKey ='p';
prevBtn.addEventListener('click', postReply, false);
qqDiv.appendChild(prevBtn);
var clearBtn =document.createElement('input');
clearBtn.type = 'reset';
clearBtn.className= 'clearCSS';
clearBtn.value='Clear' ;
clearBtn.accessKey ='x';
clearBtn.addEventListener('click', clearQuote,false);
qqDiv.appendChild(clearBtn);
if(inThread) {
var toggleBtn =document.createElement('input');
toggleBtn.type = 'button';
toggleBtn.className= 'toggleCSS';
toggleBtn.value='Float' ;
toggleBtn.addEventListener('click', toggleQuote,false);
qqDiv.appendChild(toggleBtn);
}
return qqContain; //qqDiv;
}
if(inReply && replyArea) {
replyNumber=parseInt(document.location.search.substring(3));
if((savedNumber.substr(0,1) == 'R' && savedNumber==('R'+replyNumber)) ||
(savedNumber.substr(0,1) == 'P' && savedNumber==('P'+replyNumber)) ){ // qquote 'post'
if(savedText.length) { // this should always have a length - more a sanity check
GM_setValue('savedText', '');
GM_setValue('savedNumber', 'C');
replyArea.value=savedText;
// --- test
var div=document.createElement('DIV');
div.style.width='100%';
div.style.height='100%';
div.style.margin='0';
div.style.padding='0';
div.style.position='fixed';
div.style.zIndex='2000';
div.style.top='0';
div.style.left='0';
div.style.textAlign='center';
div=document.body.appendChild(div);
var inDiv=document.createElement('DIV');
inDiv.style.width='14em';
inDiv.style.margin='200px auto 0';
inDiv.style.backgroundColor='orange';
inDiv.style.border='ridge 3px gold';
inDiv.style.textAlign='center';
inDiv.style.fontSize='24pt';
inDiv.style.fontWeight='bold';
inDiv.style.fontFamily='verdana,helvetica,sans-serif';
inDiv.style.color='black';
inDiv.appendChild(document.createTextNode('Please Wait ...'));
inDiv=div.appendChild(inDiv);
// --- test
if(savedNumber.substr(0,1) == 'P')
uWin.prevbutton.click();
else if(savedNumber.substr(0,1) == 'R')
uWin.postbutton.click();
}
}
}
var newStyle=[
'.previewCSS {border:0px solid gray;color:black;background:#FFDCBF;width:150px;font:16px Arial;',
'margin-right:2em;}',
'.submitCSS {border:0px solid gray;color:black;background:#BFDCFF;width:150px;font:16px Arial;',
'margin-right:2em;}',
'.clearCSS {border:0px solid gray;color:black;background:#DAF2B3;width:150px;font:16px Arial;}',
'.toggleCSS {border:0px solid gray;color:black;background:#bbb;width:auto;font:16px Arial;margin-left:1em;}',
'.textCSS {border:0px solid gray; color:black; background:#e5e5e5;}',
'.whirlyCSSopen, .whirlyCSS {border:1px outset gray;color:black;',
'padding:0;margin:0 1px;color:#018;font-size:1em;cursor:pointer;}',
'.whirlyCSS {background:#ddddff;}',
'.whirlyCSS:hover {background:#eeffee;}',
'.whirlyCSS:focus {background:#ddffdd;border-style:inset;}',
'.whirlyCSSopen {border-style:inset;background:#eeeeff;}',
'.whirlyCSSopen:hover {background:#ffeeee;}',
'.whirlyCSSopen:focus {background:#ffdddd;}',
'.whirlyCSS SPAN {color:#900;}',
'.whirlyHiddenCSS {height:0;width:0;border:none;padding:0;margin:0;}',
'.qqInline {}',
'.qqFloat { position:fixed; background:grey; border:solid black 1px; width:auto; height:auto; bottom:10px; right:210px;'
].join('');
var head = document.getElementsByTagName('head')[0];
if (head) {
var el = document.createElement('style');
el.type = 'text/css';
el.innerHTML = newStyle;
head.appendChild(el);
}
if(inThread) {
var reply=getAny('//td[@class = "breadtask"]/a');
if(!reply) return;
replyURL=reply.href; //getAttribute('href');
var x=replyURL.indexOf('r=');
if(x>-1)
replyNumber=replyURL.substring(x+2);
x=document.location.search.indexOf('t=');
if(x>-1) {
threadId=parseInt(document.location.search.substring(x+2));
}
if(savedNumber.substr(0,1) == 'T' && savedNumber==('T'+threadId)) {
GM_setValue('savedText', '');
GM_setValue('savedNumber', 'C');
}
else
savedText='';
window.addEventListener('unload', saveText, false);
var qqloc=getAny('//BODY[1]/TABLE[1]/TBODY[1]/TR[1]/TD[2]/DIV[2]');
var createdQQ=createQuote(savedText);
if(createdQQ) {
qqRoot = qqloc.parentNode.insertBefore(createdQQ,qqloc);
// lets add some q-quote "links"
var repDiv=document.getElementById('replies');
var bar=getAny('//DIV[@id="replies"]/TABLE[1]/TBODY[1]/TR/TD/DIV/SPAN[@class="bar"]');
var repx='//DIV[@id="replies"]/TABLE[1]/TBODY[1]/TR/TD[@class="bodytext"]';
var reps=document.evaluate(repx,repDiv,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
var locx='//DIV[@id="replies"]/TABLE[1]/TBODY[1]/TR/TD/DIV/A[@title="a link to this specific post"]';
var locs=document.evaluate(locx,repDiv,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
var whox='//DIV[@id="replies"]/TABLE[1]/TBODY[1]/TR/TD/DIV/A/SPAN[@class="bu_name"]';
var whos=document.evaluate(whox,repDiv,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
function addQuoter(par, lnk, post, who) {
var newLink=document.createElement('BUTTON');
// newLink.href='';
newLink.style.color='#777';
newLink.style.fontSize='inherit';
newLink.style.fontFamily='inherit';
newLink.style.backgroundColor='inherit';
newLink.style.border='none';
newLink.style.cursor='pointer';
newLink.appendChild(document.createTextNode('q-quote'));
newLink=par.appendChild(newLink);
EventManager.Add(newLink, 'click', function() {
var e=arguments[0];
e.preventDefault();
e.stopPropagation();
var sel=window.getSelection();
var txt=sel.toString();
if(txt.length == 0) {
sel.selectAllChildren(post);
}
txt=sel.toString();
var wName=who.firstChild.nodeValue;
var wLink=who.parentNode.getAttribute('href');
var pLink=lnk.getAttribute('href');
var postRow=post.parentNode;
var postNumx='./TD[1]/A[2]';
var postNuma = document.evaluate(postNumx,postRow,null,XPathResult.ANY_UNORDERED_NODE_TYPE,null);
var ttxt=postNuma.singleNodeValue.name;
ttxt=ttxt.substr(1);
var qt=[
// '[+'+wName+' writes...+]',
// '[+'+wName+' writes...+]',
'[+'+ttxt+' '+wName+' writes...+]',
'["'+txt+'"]',
''
].join('\n');
qQuote.value+=qt;
qQuote.focus();
}, false);
}
for(var i=0; i < locs.snapshotLength; i++) {
var postEl=reps.snapshotItem(i);
var anch=locs.snapshotItem(i);
var whom=whos.snapshotItem(i);
var newBar=bar.cloneNode(bar, true);
anch.parentNode.appendChild(newBar);
addQuoter(anch.parentNode, anch, postEl, whom);
}
}
}
var DefaultUrlPrompt='Click here ...';
//
// return selected text ... selected either anywhere in the window or in a input/textarea
//
function editObject(tgt) {
this.tgt=tgt;
this.text=null;
this.obj=null;
}
editObject.prototype.getTarget=function() {
return this.tgt;
}
editObject.prototype.getSelectedText=function() {
this.text=null;
this.obj=null;
if (window.getSelection) {
this.text=(window.getSelection()).toString();
}
else if (document.getSelection) {
this.text=(document.getSelection()).toString();
}
if(this.text.length==0) {
var els = document.evaluate('.//textarea | .//input[@type="text" or not(@type)]',
document.body, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
for(var i=0; i < els.snapshotLength; i++) {
var el=els.snapshotItem(i);
if(el.ownerDocument === document || el.id=='qqText' || el.id == 'body')
if(!(el.form && el.form.style && el.form.style.display == 'none'))
if(0<(el.selectionEnd-el.selectionStart)) {
this.obj=el;
this.text=el.value.substring(el.selectionStart,el.selectionEnd);
break;
}
}
}
return this.text;
}
editObject.prototype.addReplaceSelectedText=function(s) {
var scrollTop=this.tgt.scrollTop;
var scrollLeft=this.tgt.scrollLeft;
var before;
var after;
var caretStart;
var caretEnd;
if(this.obj == this.tgt) { // src and destination element are the same - we replace
caretStart=this.tgt.selectionStart;
caretEnd=caretStart+s.length;
} else {
caretEnd=this.tgt.selectionEnd+s.length;
caretStart=caretEnd;
}
before=(this.tgt.value).substring(0,this.tgt.selectionStart);
after=(this.tgt.value).substring(this.tgt.selectionEnd);
this.tgt.value=before+s+after;
this.tgt.setSelectionRange(caretStart, caretEnd);
this.tgt.focus();
this.tgt.scrollTop=scrollTop;
this.tgt.scrollLeft=scrollLeft;
}
//
// add buttons to el, they will add whirlcode to element txtDest
//
function writeConfig() {
var config='';
for(o in buttons) {
var btn=document.getElementById('wc_'+o);
if(btn) btn.className='whirlyCSS';
if(buttons[o].hidden) {
if(btn) btn.className='whirlyHiddenCSS';
config+=(config.length?':':'')+o;
}
}
GM_setValue('hiddenButtons', config);
}
function addConfigCheckbox(where, id, label, state) {
var newInput=document.createElement('INPUT');
newInput.id=id;
newInput.type='checkbox';
newInput.checked=state;
var newLabel=document.createElement('LABEL');
newLabel.setAttribute('for',id);
newLabel.appendChild(document.createTextNode(label));
where.appendChild(newInput);
where.appendChild(newLabel);
where.appendChild(document.createElement('BR'));
return newInput;
}
function clickConfig(event) {
if(event) {
event.stopPropagation();
event.preventDefault();
}
var newDiv=document.getElementById('wc_config');
if(newDiv)
return;
newDiv=document.createElement('DIV');
newDiv.style.position='fixed';
newDiv.style.left='10px';
newDiv.style.top='10px';
newDiv.id='wc_config';
newDiv=document.body.appendChild(newDiv);
newDiv=newDiv.appendChild(document.createElement('DIV'));
newDiv.style.backgroundColor='#ddddff';
newDiv.style.border='ridge 3px';
newDiv.style.color='#000000';
for(o in buttons)
addConfigCheckbox(newDiv, 'wc_config_'+o, buttons[o].value.replace(/\-/g,''),
buttons[o].hidden?false:true);
addConfigCheckbox(newDiv, 'wc_config_quickquote', 'Quick Quote/Reply',
noQuickQuote?false:true);
newDiv.appendChild(document.createElement('BR'));
var inClose=newDiv.appendChild(document.createElement('INPUT'));
inClose.type='button';
inClose.value='CANCEL';
EventManager.Add(inClose, 'click', function() {
var div=document.getElementById('wc_config');
document.body.removeChild(div);
}, false);
var inSubmit=newDiv.appendChild(document.createElement('INPUT'));
inSubmit.type='button';
inSubmit.value='ACCEPT';
EventManager.Add(inSubmit, 'click', function() {
var div=document.getElementById('wc_config');
var btns=div.getElementsByTagName('INPUT');
// for(var i=0; i < btns.length; i++) {
// var btn=btns[i];
Array.forEach(btns, function(btn) {
if(btn.type=='checkbox') {
var nm=btn.id.substr(10);
if(nm == 'quickquote')
GM_setValue('QuickQuote', btn.checked?"show":"hide");
else
buttons[nm].hidden=btn.checked?false:true;
}
});
// }
writeConfig();
document.body.removeChild(div);
}, false);
}
function cleanupWhirlcode(s) {
var tbl=[
'*','b',
'/','i',
"'",'abbr',
'"','q',
'^','sup',
'\\','sub',
'-','s',
'#','code',
'()','small',
'+','h2',
'`','h3',
'[]','h4',
'~','h5',
'?','h6'
];
for(var i=0; i < tbl.length; i+=2) {
var x='\\[\\'+tbl[i].substr(0,1);
var y=new RegExp(x, 'gm');
s=s.replace(y, "<"+tbl[i+1]+">");
x='\\'+tbl[i].substr(-1)+'\\]';
y=new RegExp(x, 'gm');
s=s.replace(y, ""+tbl[i+1]+">");
}
var div=document.createElement('div');
div.innerHTML=s;
s=div.innerHTML;
for(var i=0; i < tbl.length; i+=2) {
var x='<'+tbl[i+1]+'>';
var y=new RegExp(x, 'gm');
s=s.replace(y, "["+tbl[i].substr(0,1));
x=''+tbl[i+1]+'>';
y=new RegExp(x, 'gm');
s=s.replace(y, tbl[i].substr(-1)+"]");
}
delete div;
return s;
}
function clickClean(event) {
event.stopPropagation();
event.preventDefault();
var tgt=edit.getTarget();
tgt.value=cleanupWhirlcode(tgt.value);
flushStack();
tgt.focus();
}
function clickWhirl(event) {
var bId;
event.stopPropagation();
event.preventDefault();
bId=event.currentTarget.id.substr(3);
if(event.which==3)
return(clickConfig(event));
var bObj=buttons[bId];
var text=edit.getSelectedText();
var pre='['+bObj.whirl.substr(0,1);
var post=bObj.whirl.substr(-1)+']';
if(text.length) {
if(bObj.re && bObj.replace) {
var tt=text.split('|');
tt[0]=tt[0].replace(bObj.re, bObj.replace);
text=tt.join('|');
}
edit.addReplaceSelectedText(pre+text+post);
} else {
if(!bObj.opened) {
bObj.el.className='whirlyCSSopen';
buttonStack.push(bObj);
}
else if(bObj.opened && buttonStack.length>1) {
var prePost='';
var xB=buttonStack.pop();
while(xB && xB != bObj) {
prePost+=xB.whirl.substr(-1)+']';
xB.opened=false;
xB.el.className='whirlyCSS';
xB=buttonStack.pop();
}
post=prePost+post;
}
else buttonStack.pop();
edit.addReplaceSelectedText(bObj.opened?post:pre);
bObj.opened=!bObj.opened;
bObj.el.className=bObj.opened?'whirlyCSSopen':'whirlyCSS';
}
}
function clickUrl(event) {
var bId;
event.stopPropagation();
event.preventDefault();
bId=event.currentTarget.id.substr(3);
if(event.which==3)
return(clickConfig(event));
var bObj=buttons[bId];
var promptText=bId.substr(7);
var url=edit.getSelectedText();
var pre='';
var post='';
var cutPos=-1;
if(!url) {
var textArea=document.getElementById('body');
if(!textArea)textArea=document.getElementById('f_body');
if(!textArea)textArea=document.getElementById('qqText');
if(textArea && textArea.setSelectionRange) {
textArea.focus();
var caret=textArea.selectionStart;
var txt=textArea.value;
var c=txt.substr(caret, 1);
if(c>' ') {
var start=caret;
var end=caret;
while(start>-1 && txt.substr(--start,1)>' ');
start++;
while(end' ');
url=txt.substring(start,end);
textArea.setSelectionRange(start, end+1);
}
}
}
if(!url) {
var clean=textArea.value.replace(/\n/gm,' ');
var sp=clean.split(' ');
if(sp.length) {
var indx=sp.length-1;
var check=sp[indx].toLowerCase();
if(!check.length)
check=sp[--indx].toLowerCase();
if(check.indexOf('http://') == 0 || check.indexOf('https://') == 0 ||
check.indexOf('ftp://') == 0) {
url=sp[indx];
cutPos=textArea.value.lastIndexOf(url);
}
}
}
if(url.length) {
var text;
if(promptText=='Text')
text=window.prompt('Enter desription for this link', DefaultUrlPrompt);
else if(promptText=='Href') {
text=url;
url='';
url=window.prompt('Enter url', 'http://');
}
if(text.length && url.length) {
if(cutPos >= 0)
textArea.value=textArea.value.substr(0, cutPos);
edit.addReplaceSelectedText(pre+url+mid+text+post);
}
}
}
function readConfig() {
var config=GM_getValue('hiddenButtons', '');
if(config.length) {
var configArray=config.split(':');
configArray.forEach(function(x) { if(buttons[x]) buttons[x].hidden=true; });
}
}
function addButtons(el, txtDest) {
readConfig();
EventManager.Add(txtDest, 'focus', setButtons, false);
EventManager.Add(txtDest, 'click', setButtons, false);
EventManager.Add(txtDest, 'keyup', setButtons, false);
var btnEl=document.createElement('button');
btnEl.className="whirlyCSS";
btnEl.id='wc_config_button';
btnEl.appendChild(document.createTextNode('\u00a9'));
btnEl=el.appendChild(btnEl);
EventManager.Add(btnEl,'click', clickConfig, false);
for(var o in buttons) {
var bn=buttons[o];
bn.opened=false; // flag for when no text selected
btnEl=document.createElement('button');
btnEl.id='wc_'+o;
btnEl.accessKey=bn.key;
btnEl.className="whirlyCSS";
var splits=bn.value.split('-');
var access=document.createElement('SPAN');
access.style.color='#aa3333';
access.appendChild(document.createTextNode(splits[1]));
btnEl.appendChild(document.createTextNode(splits[0]));
btnEl.appendChild(access);
btnEl.appendChild(document.createTextNode(splits[2]));
if(bn.hidden) {
btnEl.className="whirlyHiddenCSS";
}
btnEl=el.appendChild(btnEl);
bn.el=btnEl;
if(o.substr(0,5) == 'whirl') {
btnEl.title=o.substr(5)+' WhirlCode';
EventManager.Add(btnEl,'click', clickWhirl, false);
}
if(o.substr(0,7) == 'makeUrl') {
btnEl.title='Add url '+o.substr(7);
EventManager.Add(btnEl,'click', clickUrl, false);
}
if(o == 'cleanupCode') {
btnEl.title='Cleanup whirlcode';
EventManager.Add(btnEl,'click', clickClean, false);
}
}
}
var textArea=document.getElementById('body');
var buttonLocation;
if(textArea) {
var url=document.location.href;
if(url.indexOf('forum-reply.cfm?r')>-1){
var p2i=document.evaluate('//input[@name="post2"]',
document,null,XPathResult.ANY_UNORDERED_NODE_TYPE,null);
p2i=p2i.singleNodeValue;
if(p2i) {
if(window.post2input) {
window.post2input=p2i;
p2i.id='post2';
}
}
}
if(url.indexOf('whim-send.cfm')<0){
var targetTr=textArea.parentNode.parentNode.previousSibling;
while(targetTr && targetTr.nodeName!='TR') targetTr=targetTr.previousSibling;
if(!targetTr) return;//don't have a previous row ... maybe we could add one ... not now
var tds=targetTr.getElementsByTagName('TD');
if(tds.length < 2) return;//
buttonLocation=tds[1];
buttonLocation.style.fontSize='80%';
buttonLocation.style.textAlign='center';
}
else {
var tNode=document.getElementsByTagName('BLOCKQUOTE')[0];
if(tNode) {
var newDiv=document.createElement('DIV');
buttonLocation=tNode.parentNode.insertBefore(newDiv, tNode);
buttonLocation.style.fontSize='80%';
newDiv.style.textAlign='center';
}
}
}
if(!textArea) {
textArea=document.getElementById('f_body');
if(textArea) {
var tNode=document.getElementById('f_form');
if(!tNode) return;
tNode=tNode.parentNode;
if(!tNode) return;
var newDiv=document.createElement('DIV');
buttonLocation=tNode.appendChild(newDiv);
buttonLocation.style.fontSize='120%';
}
}
if(!textArea) {
textArea=document.getElementById('qqText');
if(textArea) {
var tNode=textArea.parentNode;
if(!tNode) return;
var newDiv=document.createElement('DIV');
buttonLocation=tNode.insertBefore(newDiv,textArea);
buttonLocation.style.fontSize='80%';
}
}
var edit;
if(textArea && buttonLocation) {
edit=new editObject(textArea);
addButtons(buttonLocation, textArea);
}
})();