User:Roman Bekker/monobook.js

/* Beta version, tested in FireFox 1.5 only. Usage: */ var IE=(!is_opera&&!is_gecko)?true:false; var bodyContent, blockForm, msgDiv, gml, stopMe;
 * importScript('Участник:Twyster/blockLoop.js')
 * visit Special:BlockIP and put for example 10.1-25.0.0/16

if (wgCanonicalNamespace == "Special" && wgCanonicalSpecialPageName == "Blockip") addOnloadHook(block8_init);

function block8_init{ bodyContent = document.getElementById('bodyContent'); blockForm = document.getElementById('blockip'); if (!bodyContent || !blockForm) return; var but = document.createElement('input'); but.type = 'button'; but.value = 'block8'; but.onclick = block8; blockForm.wpBlock.parentNode.appendChild(but); msgDiv = document.createElement('div'); msgDiv.style.border = '1px solid gray'; msgDiv.style.padding = '5px'; bodyContent.appendChild(msgDiv); //temp!!! //if (!blockForm.wpBlockAddress.value) blockForm.wpBlockAddress.value = '10.1-1.'; }

function block8{ var addr, i, j, left, right, idx1, idx2, ask; addr = blockForm.wpBlockAddress.value.split('-'); if (addr.length !=2 ) return alert('Unrecognized address format: please use something like xx.m-n.0.0/16'); left = addr[0]; right = addr[1]; j = left.lastIndexOf('.'); idx1 = left.substring(j+1); left = left.substring(0,j+1); j = right.indexOf('.'); idx2 = right.substring(0,j); right = right.substring(j); if (!confirm('Will try '+(idx2-idx1+1)+' blocks from \n'+left+idx1+right+' to\n'+(left+idx2+right)+'\n\nProceed?')) return; data = getField(blockForm.wpBlockExpiry) + getField(blockForm.wpBlockOther) + getField(blockForm.wpBlockReason) + getField(blockForm.wpAnonOnly) + getField(blockForm.wpCreateAccount) + getField(blockForm.wpEnableAutoblock) + getField(blockForm.wpEditToken) + getField(blockForm.wpBlock); stopMe = false; for (i=idx1; i<=idx2; i++){ if (stopMe) {msg(' Script stopped'); return } addr = left + i + right; msg(' '+addr+''); gml = HTTPClient; gml.onreadystatechange = onReturn; gml.open("POST", blockForm.action, false); gml.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") //if (gml.overrideMimeType) gml.overrideMimeType('text/html'); gml.send('&wpBlockAddress=' + addr + data); } }

function onReturn{ if (gml.readyState != 4) return; var mm, res; mm = gml.responseText.match(/(.*)<\/div>/); if (!mm) return stopMe = true; res = (mm[1]); msg (res); if (res.match(/Error/)) { stopMe = true; mm = gml.responseText.match(/(.*)<\/p>/); if (mm) msg(' ' + mm[1] + ' '); msg(' Error detected '); return; } }

function getFields(form){ var res = ""; for (var i=0; i < form.elements.length; i++) res += getField(form.elements[i]); return res; }

function getField(node){ var res = ""; switch (node.nodeName) { case "INPUT": var inputType = node.getAttribute("type"); if (node.type == "checkbox"){ if (node.checked) res += "&"+node.name+"=on" }else if (node.type != "submit" && node.type != "button") res += "&"+node.name+"="+encodeURIComponent2(node.value); break; case "SELECT": res += "&"+node.name+"=" + node.options[node.selectedIndex].value; break; case "TEXTAREA": res += "&"+node.name+"="+encodeURIComponent2(node.value); break; } return res; }

function encodeURIComponent2(content){ // from content = content.replace(/\&lt\;/gi, "<"); content = content.replace(/\&gt\;/gi, ">"); content = content.replace(/\&quot\;/gi, "\""); content = content.replace(/\&amp\;/gi, "&");  return encodeURIComponent( content ); }

function HTTPClient{ var http = false; if(window.XMLHttpRequest) http = new XMLHttpRequest; else if (IE){ try{ http = new ActiveXObject("Msxml2.XMLHTTP") } catch(e){ try{ http = new ActiveXObject("Microsoft.XMLHTTP") } catch(e){} } }  return http };

function msg(message){ msgDiv.innerHTML += ' ' + message; return false; } /* */