User:Yair rand/wsedit.js

// Yay, I finally got around to making a tool for adding nyms to ws pages. Still some problems with green outlines, dunno what I'm going to do about that. // Still needs possibility of adding qualifiers, maybe glosses too. // Also needs cross-browser testing. // Also needs removal of ugliness. var ccc=""

function addwseditbox(q) {

var z var prevheader=q.lastChild.innerHTML var editor=new Editor new AdderWrapper( editor,   {    'createForm':function{      return z=newNode('form', newNode('span','Add ' + q.lastChild.innerHTML.toLowerCase + ': '), newNode('input',{'name':'nym'}), newNode('input',{'type':'submit','value':'Preview'}) )   },    'fields':{'nym':function(txt,error){return txt}},    'onsubmit':function(values, render){      render('',function(res){ z.nym.value="" var nodeToInsert=newNode('div') nodeToInsert.innerHTML=res editor.addEdit({         edit: function(wikitext){            qqqq=z;while(qqqq.nodeName!="H4"){qqqq=qqqq.previousSibling}            wikitext=wikitext.replace(new RegExp("([\\s\\S]*?===="+prevheader+"====[\\s\\S]*?)"),"$1\n")            ccc=wikitext            return wikitext            },          redo: function{z.previousSibling.appendChild(nodeToInsert)},          undo: function{z.previousSibling.removeChild(nodeToInsert)},          summary: prevheader.toLowerCase+"+"+values.nym+""        },nodeToInsert) })   }  },   q.parentNode,   findnextdiv(q).nextSibling )

}

function findnextdiv(qwe) { while(qwe&&qwe.nodeName!="DIV") {qwe=qwe.nextSibling} return qwe }

$(function { if(wgNamespaceNumber==110) { xx=document.getElementsByTagName('h4'); for (x=0;x<xx.length;x++) { xx[x].insertBefore(

newNode('span',{style:'position:absolute;'},	temp=newNode('span', {style:'position:relative; left:-14px; '}, newNode('img',{src:'http://bits.wikimedia.org/w/extensions/UsabilityInitiative/images/wikiEditor/toolbar/arrow-right.png'}), newNode('div',{style:'border:1px solid #C0C0C0;background-color:#FFFFFF;position:absolute;z-index:1;display:none;padding-right:20px;width:175px;margin-top:-5px;'},			xxx=newNode('ul',{style:'list-style-type:none;list-style-image:none;margin-left:15px;font-size:13px;font-weight:normal;'},newNode('li',newNode('a',{style:'cursor:pointer;'},'Edit gloss')))))) , xx[x].firstChild)

xxx.firstChild.firstChild.onclick=function{ editwsgloss(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode); this.parentNode.removeChild(this); }

temp.onmouseover=function{ this.lastChild.style.display=""; this.firstChild.src="http://bits.wikimedia.org/w/extensions/UsabilityInitiative/images/wikiEditor/toolbar/arrow-down.png";} temp.onmouseout=function{ this.lastChild.style.display="none"; this.firstChild.src="http://bits.wikimedia.org/w/extensions/UsabilityInitiative/images/wikiEditor/toolbar/arrow-right.png";}

xxxx={"Synonyms":1,"Antonyms":1,"Hypernyms":1,"Hyponyms":1,"Meronyms":1,"Holonyms":1,"Troponyms":1,"Coordinate terms":1} xxxxx=xx[x] while(xxxxx.nextSibling&&xxxxx.nextSibling.nodeName.toLowerCase!="h4") { if(xxxxx.nodeName.toLowerCase=="h5"&&xxxxx.lastChild.innerHTML.match(/^Synonyms$|^Antonyms$|^Hypernyms$|^Hyponyms$|^Meronyms$|^Holonyms$|^Troponyms$|^Coordinate\sterms$/)) {xxxx[xxxxx.lastChild.innerHTML]=0} xxxxx=xxxxx.nextSibling } for(i in xxxx) {if(xxxx[i]){ xxx.appendChild(	newNode('li',{'id':i}, newNode('a',{style:'cursor:pointer;'},'Add '+i.toLowerCase) )	) xxx.lastChild.onclick=function{ addwssection(this.id,this.parentNode.parentNode.parentNode.parentNode.parentNode); this.parentNode.removeChild(this);}

}} } xx=document.getElementsByTagName('h5') for (x=0;x<xx.length;x++) {

if(xx[x].lastChild&&xx[x].lastChild.innerHTML&&xx[x].lastChild.innerHTML.match(/^Synonyms$|^Antonyms$|^Hypernyms$|^Hyponyms$|^Meronyms$|^Holonyms$|^Troponyms$|^Coordinate\sterms$/)) { addwseditbox(xx[x])

}

}

} } )

function addwssection(typeofsection,sectionl4header) { var editor=Editor

var nodeToInsert=newNode('h5',newNode('span',{'class':"mw-headline",id:typeofsection},typeofsection)) var nodeToInsert2=newNode('div',{style:'column-count:3;-moz-column-count:3;-webkit-column-count:3'},newNode('ul')) function addnewwssectionToWikitext(wikitext) {	qqqq=sectionl4header;while(qqqq.nodeName!="H4"){qqqq=qqqq.previousSibling} wikitext=wikitext.replace(new RegExp("([\\s\\S]*?)(\n=(?!===)|$)"),"$1\n====="+typeofsection+"=====\n\n\n$2") ccc=wikitext return wikitext } qqq=sectionl4header.nextSibling; while((!qqq)||(!qqq.nodeName)||(qqq.nodeName!="H4"&&qqq.nodeName!="H3"&&qqq.className!="printfooter")){qqq=qqq.nextSibling}

editor.addEdit({

edit: addnewwssectionToWikitext, redo: function { sectionl4header.parentNode.insertBefore(nodeToInsert,qqq);sectionl4header.parentNode.insertBefore(nodeToInsert2,qqq);addwseditbox(nodeToInsert); }, undo: function { sectionl4header.parentNode.removeChild(nodeToInsert);sectionl4header.parentNode.removeChild(nodeToInsert2.nextSibling);sectionl4header.parentNode.removeChild(nodeToInsert2); }, summary: "+section: "+typeofsection

},nodeToInsert)

}

function editwsgloss(q) { qq=newNode('span',	newNode('input',{value:q.lastChild.innerHTML.replace(/^Sense:\s/,''),size:50}),	newNode('input',{type:'button',value:'Preview'})) qq.lastChild.onclick=function{ editwsgloss2(this.parentNode.parentNode,this.previousSibling.value,this.parentNode.parentNode.lastChild.innerHTML.replace('Sense: ','')); }

q.insertBefore(qq,q.childNodes[2]) q.lastChild.style.display='none'

} function editwsgloss2(q,newgloss,oldgloss) {

var editor=Editor

editor.addEdit({

edit: function(wikitext){ if(wikitext.indexOf("") > -1) {return wikitext.replace("","")} else {editor.error("ERROR: Gloss not found")} }, redo: function { q.lastChild.innerHTML="Sense: "+newgloss;q.lastChild.style.display="";q.childNodes[2].style. display='none';}, undo: function { q.lastChild.innerHTML="Sense: "+oldgloss;q.lastChild.style.display="none";q.childNodes[2].style. display=''; }, summary: "wsgloss: "+newgloss

},q.lastChild)

}