User:Zzuuzz/protectionreasons.js

From Wikipedia, the free encyclopedia

If a message on your talk page led you here, please be wary of who left it. Code that you insert on this page could contain malicious content capable of compromising your account. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. If this is a .js page, the code will be executed when previewing the page.
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
 // [[User:^demon/csd.js]] adapted for page protection use,
 // this version modified from [[User:Steel359/^demon.js]]
 
 if (document.title.indexOf("Change protection") != -1) {
 
    var protform = {
        FillSelect:function(sel, arr) {
            var FirstOpt = new Option("Protection reasons", "");
            // catches stupid IE error
            if(FirstOpt.innerHTML != "Protection reasons") {
                FirstOpt.innerHTML = "Protection reasons";
            }
            sel.appendChild(FirstOpt);
            sel.options[0].style.color = "#999";
            sel.disabled = false;
            for (var i = 0; i < arr.length; i++) {
                var opt = new Option(arr[i].display, arr[i].value);
                // catches stupid IE error
                if (opt.innerHTML != arr[i].display) {
                    opt.innerHTML = arr[i].display;
                }
                sel.appendChild(opt);
            }
            return true;
        },
        ValueArray:[
            {"value":"IP vandalism", "display":"IP vandalism"},
            {"value":"vandalism, user request", "display":"Userpage"},
            {"value":"[[Wikipedia:Edit war|Edit warring]]", "display":"Edit warring"},
            {"value":"[[Wikipedia:Spam|Spam]]", "display":"Spam"},
            {"value":"[[Wikipedia:Biographies of living persons|BLP]] concerns", "display":"BLP concerns"},
            {"value":"[[Wikipedia:Sock puppetry|Sockpuppets]] of blocked/banned user(s)", "display":"Block/ban evasion"},
            {"value":"Pagemove dispute", "display":"Move war"},
            {"value":"Disruption/Unblock abuse", "display":"Unblock abuse"},
            {"value":"[[Wikipedia:High-risk templates|High risk template]]", "display":"High risk template"},
            {"value":"Unprotecting per [[Wikipedia:Requests for page protection|RFPP]] request", "display":"Unprot per WP:RFPP"},
            {"value":"Block expired", "display":"Block expired"},
            {"value":"Page protected for a while, hopefully protection is no longer necessary", "display":"Time..."}
        ],
        addEvent:function(obj, evType, fn) {
            //alert(obj);
            if (obj.addEventListener) {
                obj.addEventListener(evType, fn, false);
                return true;
            } else if (obj.attachEvent) {
                var r = obj.attachEvent("on" + evType, fn);
                return r;
            } else {
                alert ("Handler could not be attached");
            }
        },
        addSelectAfter:function () {
            var obj = document.getElementById('mwProtect-reason');
            // create select using included array
            var sel = document.createElement("select");
            protform.FillSelect(sel, protform.ValueArray);
            // name it
            sel.name = "proOptions";
            sel.id = "proOptions";
            sel.style.marginLeft = "10px";
            protform.addEvent(sel, "change", protChangeBox);
            // check for next sibling and insert before it or at the end
            if (obj.nextSibling) {
                obj.parentNode.insertBefore(sel, obj.nextSibling);
            } else {
                obj.parentNode.appendChild(sel);
            }
        }
    }
 
    var protform2 = {
        FillSelect:function(sel, arr) {
            var FirstOpt = new Option("Protection expiries", "");
            // catches stupid IE error
            if (FirstOpt.innerHTML != "Protection expiries") {
                FirstOpt.innerHTML = "Protection expiries";
            }
            sel.appendChild(FirstOpt);
            sel.options[0].style.color = "#999";
            sel.disabled = false;
            for (var i = 0; i < arr.length; i++) {
                var opt = new Option(arr[i].display, arr[i].value);
                // catches stupid IE error
                if (opt.innerHTML != arr[i].display) {
                    opt.innerHTML = arr[i].display;
                }
                sel.appendChild(opt);
            }
            return true;
        },
        ValueArray:[
            {"value":"1 day", "display":"1 day"},
            {"value":"2 days", "display":"2 days"},
            {"value":"5 days", "display":"5 days"},
            {"value":"7 days", "display":"7 days"},
            {"value":"10 days", "display":"10 days"},
            {"value":"2 weeks", "display":"2 weeks"},
            {"value":"1 month", "display":"1 month"},
            {"value":"3 months", "display":"3 months"},
            {"value":"6 months", "display":"6 months"}
        ],
        addEvent:function(obj, evType, fn) {
            //alert(obj);
            if (obj.addEventListener) {
                obj.addEventListener(evType, fn, false);
                return true;
            } else if (obj.attachEvent) {
                var r = obj.attachEvent("on" + evType, fn);
                return r;
            } else {
                alert("Handler could not be attached");
            }
        },
        addSelectAfter:function () {
            var obj = document.getElementById('expires');
            // create select using included array
            var sel = document.createElement("select");
            protform2.FillSelect(sel, protform2.ValueArray);
            // name it
            sel.name = "proExpires";
            sel.id = "proExpires";
            sel.style.marginLeft = "10px";
            protform2.addEvent(sel, "change", protChangeBox2);
            // check for next sibling and insert before it or at the end
            if (obj.nextSibling) {
                obj.parentNode.insertBefore(sel, obj.nextSibling);
            } else {
                obj.parentNode.appendChild(sel);
            }
        }
    }
 
    try {
        // add on load
        protform.addEvent(window, "load", protform.addSelectAfter);
        protform2.addEvent(window, "load", protform2.addSelectAfter);
    } catch(err) {}
 
 }
 
 function protChangeBox() {
    var obj = document.getElementById('mwProtect-reason');
    obj.value = document.getElementById('proOptions').value;
 }
 
 function protChangeBox2() {
    var obj = document.getElementById('expires');
    obj.value = document.getElementById('proExpires').value;
 }