User:Legoktm/ifd.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <source lang="javascript">
 
document.write('<script type="text/javascript"' +
  'src="http://en.wikipedia.org/w/index.php?title=User:Henrik/js/automod.js' +
  '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
 
ifdh_deletes = Array();
ifdh_keeps = Array();
 
ifdh_keeps["keep"] = 'Keep';
 
ifdh_deletes["unfree"] = 'Unfree%20image';
ifdh_deletes["orphaned"] = 'Orphaned';
ifdh_deletes["unencylo"] = 'Unencyclopedic';
ifdh_deletes["already"] = 'Already%20deleted';
 
function ifd_helper() {
    if (auto_mod())
       return;
 
    var anchors = new Array();
    {
    var oldanchors = document.getElementById('bodyContent').getElementsByTagName('a');
    for (var i=0; i < oldanchors.length; i++)
        anchors[i] = oldanchors[i];
    }
    var url_re = /\?title=Wikipedia:Images and media for deletion\/([^&]+)&action=edit&/;
    var url, matches;
    for (var i=0; i < anchors.length; i++) {
        if (!(matches = anchors[i].href.match(url_re))
         || (anchors[i].parentNode.parentNode.tagName != 'H2'))
            continue;
 
        bla = "<span id=\"ifd-helper-accept\" style=\"background-color: #A0FFA0;\">";
        for (var key in ifdh_keeps) {   
          if( !ifdh_keeps.hasOwnProperty(key) ) { // Twinke workaround?
           continue;
          }      
          link = "javascript:ifd_vote('"+escape(anchors[i].href)+"','"+key+"','"+ifdh_keeps[key]+"','accept')";
          bla += "[<a href=\""+link+"\">"+key+"</a>]";
        }
        bla += "</span><span id=\"ifd-helper-decline\" style=\"background-color: #ffcece;\">";;
        for (var key in ifdh_deletes) {   
          if( !ifdh_deletes.hasOwnProperty(key) ) { // Twinke workaround?
           continue;
          }      
          link = "javascript:ifd_vote('"+escape(anchors[i].href)+"','"+key+"','decline - "+ifdh_deletes[key]+"','')";
          bla += "[<a href=\""+link+"\">"+key+"</a>]";
        }
        bla += "</span>";
        anchors[i].parentNode.innerHTML += bla;
 
    }
}
 
function ifd_vote(edit_link,type,reason,action) {
    var type2 = type;
 
    if (type == "manual")
       type2 = "accept";
 
    var url = edit_link + 
        '&amfind='+escape("==(.*)==")+
        '&amreplace='+escape('$0\n{{subst:ifd top|'+action+'}} ~~'+'~~\n')+
        '&amlocal=1'+
        '&amaddafter='+escape("{{subst:ifd bottom}}") +
        '&amsummary='+escape(reason);
//    if (action == '') {
//       url += "&amautosave=yes;";
    }
    window.location.href = url;
 
//    if (action == "accept" && type != "manual") {
//     title = window.prompt("Create at title?");
//      url = "http://en.wikipedia.org/w/index.php?title="+escape(title)+"&action=edit";
//      window.open(url, "afd_helper_vote");
    }
}
addOnloadHook(ifd_helper);
 
// </source>