User:Yair rand/TargetedTranslationsCustomizationAddon.js

// This is a possible addition to User:Atelaes/TargetedTranslations.js, to simplify the customization process.

$(function{

mw.util.addCSS('.translationtargetstar{background-image: url(http://bits.wikimedia.org/skins-1.5/vector/images/watch-icons.png); background-position: 0px 60%;}') mw.util.addCSS('.translationtargetstar:hover{background-image: url(http://bits.wikimedia.org/skins-1.5/vector/images/watch-icons.png); background-position: -24px 60%;}'); mw.util.addCSS('.translationtargetstarchecked{background-image: url(http://bits.wikimedia.org/skins-1.5/vector/images/watch-icons.png); background-position: -48px 60%;}') mw.util.addCSS('.translationtargetstarchecked:hover{background-image: url(http://bits.wikimedia.org/skins-1.5/vector/images/watch-icons.png); background-position: -72px 60%;}');

function grugpubbawup(zinkwattoom) {

var foobmog=newNode('a', 'Select targeted languages',    {'href':'javascript:','click':function{      addtargetlangfavoriteicons(foobmog.parentNode.parentNode.nextSibling.getElementsByTagName('li'));      foobmog.parentNode.replaceChild(newNode('a','Save',{'href':"javascript:location.reload(true)"}),foobmog)    }  } )

zinkwattoom.getElementsByTagName('tbody')[0].insertBefore( newNode('tr', newNode('td',     {colspan:3,style:'font-size:85%; padding:0px;'},      foobmog    ) ), zinkwattoom.getElementsByTagName('tr')[0] )

}

var q=document.getElementsByTagName('table') for(var i=0;i<q.length;i++) { if(q[i].className=="translations") { grugpubbawup(q[i]) }

}})

function addtargetlangfavoriteicons(q) { function w(x){ x.insertBefore(newNode('a',{'class':"translationtargetstar"+(getCookie('TargetedTransPrefs').match("(^|;)"+(x.innerText||x.textContent).split(":")[0]+"($|;)")?"checked":""),'style':'position:absolute;margin-top:3px;margin-left:-17px;cursor:pointer;width:16px;height:16px;',click:function{selecttargetlangfavorite(x.firstChild)}}),x.firstChild) } for(var i=0;i<q.length;i++) { w(q[i]) var xx=q[i].getElementsByTagName('dd') for(var ii=0;ii<xx.length;ii++){w(xx[ii])} } }

function selecttargetlangfavorite(qq) { if(getCookie('TargetedTransPrefs').match("(^|;)"+(qq.parentNode.innerText||qq.parentNode.textContent).split(":")[0]+"($|;)")){ qq.className="translationtargetstar"; setCookie("TargetedTransPrefs", getCookie('TargetedTransPrefs').replace((qq.parentNode.innerText||qq.parentNode.textContent).split(":")[0],'').replace(/;(?=;)|;$|^;/,"")) }else{ qq.className="translationtargetstarchecked" setCookie("TargetedTransPrefs", getCookie('TargetedTransPrefs')+(getCookie('TargetedTransPrefs')?";":"")+(qq.parentNode.innerText||qq.parentNode.textContent).split(":")[0]) } }