User:Yair rand/checktbotentries2.js

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Note – after saving, you may have to bypass your browser’s cache to see the changes.

  • 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.

function addchecktbotentrybuttons()
{
var q=(window.bodyContent||document.getElementById('bodyContent')).getElementsByTagName('div')
for(var i=0; i<q.length; i++){
  if(q[i].className == "tbot-entry"){
    var qq = q[i].getElementsByTagName('p')[0].appendChild(newNode('i',' [',newNode('a','check',{'style':'cursor:pointer;','click':function(){
      var qqqqq = this.parentNode, qqqq=this.parentNode.parentNode.parentNode;
      for(var qqq=qqqq; qqq&&!/h\d/i.test(qqq.nodeName); qqq=qqq.previousSibling);
      qqq = qqq.firstChild.getElementsByTagName('a')[0].href.split("&section=")[1]
      JsMwApi().page(wgPageName).edit(function(text, saveFunction, editRes){
        text = text.replace(RegExp("(((^|\n)=[\\s\\S]*?){" + qqq + "}[\\s\\S]*?)\\{\\{tbot entry[^\\}]+\\}\\}"),'$1').replace(/\n\n\n/g,'\n\n')
        saveFunction(text, {summary:'check tbot entry'}, 
          function(saveRes){if(saveRes){location.reload(true)}else{alert('ERROR')}})
        })
      }}),']'))
    }
  }
}

$(addchecktbotentrybuttons)