User:Steel359/^demon.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
 
// <pre><nowiki>
 
if ( wgAction = 'protect' ) {
     var protform = {
				FillSelect:function(sel, arr){
					if(arr && arr.length>0){
						if(arr.length>1){
							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 = "gray"
						}
						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);
						}
					}else{
						sel.options[0] = new Option("No Options Available", "");
						// catches stupid IE error
						if(sel.options[0].innerHTML != "No Options Available"){
							sel.options[0].innerHTML = "No Options Available";
						}
						sel.disabled = true;
						return false;
					}
					return true;
				},
				ValueArray:[
					{"value":"Edit warring","display":"Edit warring"},
					{"value":"Heavy IP vandalism","display":"IP vandalism"},
					{"value":"Linkspam","display":"Linkspam"},				
					{"value":"[[WP:BLP]] concerns","display":"WP:BLP concerns"},	
					{"value":"Evasion from blocked/banned user\(s\)","display":"Block/ban evasion"},
					{"value":"Pagemove war","display":"Move war"},
					{"value":"{{[[Template:Unblock|unblock]]}} abuse","display":"Unblock abuse"},
					{"value":"High risk template","display":"High risk template"},
 
					{"value":"Unprotecting per [[WP:RFPP]] request","display":"Unprot per WP:RFPP"},
					{"value":"Page protected for a while\; hopefully protection is no longer necessary","display":"Time..."}
				],
 
				addEvent:function(obj, evType, fn, useCapture){
					//alert(obj);
					if (obj.addEventListener){
						obj.addEventListener(evType, fn, useCapture);
						return true;
					} else if (obj.attachEvent){
						var r = obj.attachEvent("on"+evType, fn);
						return r;
					} else {
						alert("Handler could not be attached");
					}
				}
			}
			function addSelectAfter(){
    				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, false);
				// 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 one on load
				protform.addEvent(window, "load", addSelectAfter, false);
			}catch(err){}
}
 
function protChangeBox() {
                                                         var obj = document.getElementById('mwProtect-reason');
                                                         obj.value = document.getElementById('proOptions').value;
                                                         }
 
// ---------------------------------------------------------------------------------------------------------------
 
if ( wgAction = 'protect' ) {
     var protform2 = {
				FillSelect:function(sel, arr){
					if(arr && arr.length>0){
						if(arr.length>1){
							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 = "gray"
						}
						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);
						}
					}else{
						sel.options[0] = new Option("No Options Available", "");
						// catches stupid IE error
						if(sel.options[0].innerHTML != "No Options Available"){
							sel.options[0].innerHTML = "No Options Available";
						}
						sel.disabled = true;
						return false;
					}
					return true;
				},
				ValueArray:[
					{"value":"1 day","display":"1 day"},
					{"value":"2 days","display":"2 days"},
					{"value":"3 days","display":"3 days"},
					{"value":"5 days","display":"5 days"},
					{"value":"1 week","display":"1 week"},
					{"value":"2 weeks","display":"2 weeks"},
					{"value":"3 weeks","display":"3 weeks"},
					{"value":"4 weeks","display":"4 weeks"},
					{"value":"6 weeks","display":"6 weeks"}
				],
 
				addEvent:function(obj, evType, fn, useCapture){
					//alert(obj);
					if (obj.addEventListener){
						obj.addEventListener(evType, fn, useCapture);
						return true;
					} else if (obj.attachEvent){
						var r = obj.attachEvent("on"+evType, fn);
						return r;
					} else {
						alert("Handler could not be attached");
					}
				}
			}
			function addSelectAfter(){
    				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, false);
				// 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 one on load
				protform2.addEvent(window, "load", addSelectAfter, false);
			}catch(err){}
}
 
function protChangeBox2() {
                                                         var obj = document.getElementById('expires');
                                                         obj.value = document.getElementById('proExpires').value;
                                                         }
 
// </nowiki></pre>