User:Yair rand/checktransremove.js
Appearance
Note: You may have to bypass your browser’s cache to see the changes. In addition, after saving a sitewide CSS file such as MediaWiki:Common.css, it will take 5-10 minutes before the changes take effect, even if you clear your cache.
- Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
- Konqueror and Chrome: click Reload or press F5;
- Opera: clear the cache in Tools → Preferences;
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.
- This user script lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • redirects • your own
function addchecktransremovebuttons()
{
var q=document.getElementsByClassName?document.getElementsByClassName('checktrans'):document.getElementsByTagName('div')
for(var i = 0, c = 0; i < q.length; i++){
if(q[i].className == "checktrans"){
c++
var qq = q[i].nextSibling; if(qq.nodeName.toLowerCase()!='div'){qq=qq.nextSibling}
var qqq=qq.getElementsByTagName('li')
for(var ii = 0; ii < qqq.length; ii++){
addchecktransremovebutton(qqq[ii], c, ii)
}
}
}
function addchecktransremovebutton(q, c, i)
{
q.appendChild(newNode('a','(−)',{'style':'padding-left:4px; cursor:pointer;', 'title':'Remove', 'click': function(){
editor=new Editor();
editor.addEdit({
edit:function(wikitext){return ccc=wikitext.replace(RegExp("^(([\\s\\S]*?\\{\\{checktrans-top\\}\\}){"+c+"}[\\s\\S]*?\n([\\s\\S]+?(?=\n\\*(?!:))){"+i+"})[\\s\\S]+?\n(?=\{|\\*(?!:))"),'$1\{\{subst:blank|\n*\}\}\n')},
redo:function(){q.style.border="2px dashed #FF0000";q.style.opacity="0.6";q.style.backgroundColor="#FFEEEE";q.lastChild.style.display='none'},
undo:function(){q.style.border="";q.style.opacity="1";q.style.backgroundColor="";q.lastChild.style.display='inline'},
summary:'rm checktrans',
after_save:function(){q.style.backgroundColor="#F00"; setTimeout(function(){q.parentNode.removeChild(q)}, 400)}
})
}}))
}
}
$(addchecktransremovebuttons)