Jump to content

User:Dtrebbien/Scripts/newPagesTool.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.
//<nowiki>
function addlimenu(tabs,name,id,href,position){var na,mn;var li;if(!id)id=name;if(!href)href='#';na=document.createElement("a");na.appendChild(document.createTextNode(name));na.href=href;mn=document.createElement("ul");li=document.createElement("li");li.appendChild(na);li.appendChild(mn);if(id)li.id=id;li.className='tabmenu';if(position){tabs.insertBefore(li,position)}else{tabs.appendChild(li)}return mn}var wgPreferences=wgPreferences||new Object;var wgMessages=wgMessages||new Object;var dateFormat=function(){var token=/d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,timezone=/\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,timezoneClip=/[^-+\dA-Z]/g,pad=function(val,len){val=String(val);len=len||2;while(val.length<len)val="0"+val;return val};return function(date,mask,utc){var dF=dateFormat;if(arguments.length==1&&(typeof date=="string"||date instanceof String)&&!/\d/.test(date)){mask=date;date=undefined}date=date?new Date(date):new Date();if(isNaN(date))throw new SyntaxError("invalid date");mask=String(dF.masks[mask]||mask||dF.masks["default"]);if(mask.slice(0,4)=="UTC:"){mask=mask.slice(4);utc=true}var _=utc?"getUTC":"get",d=date[_+"Date"](),D=date[_+"Day"](),m=date[_+"Month"](),y=date[_+"FullYear"](),H=date[_+"Hours"](),M=date[_+"Minutes"](),s=date[_+"Seconds"](),L=date[_+"Milliseconds"](),o=utc?0:date.getTimezoneOffset(),flags={d:d,dd:pad(d),m:m+1,mm:pad(m+1),mmmm:wgMessages.monthNames[m],yy:String(y).slice(2),yyyy:y,h:H%12||12,hh:pad(H%12||12),H:H,HH:pad(H),M:M,MM:pad(M),s:s,ss:pad(s),l:pad(L,3),L:pad(L>99?Math.round(L/10):L),t:H<12?"a":"p",tt:H<12?"am":"pm",T:H<12?"A":"P",TT:H<12?"AM":"PM",Z:utc?"UTC":(String(date).match(timezone)||[""]).pop().replace(timezoneClip,""),o:(o>0?"-":"+")+pad(Math.floor(Math.abs(o)/60)*100+Math.abs(o)%60,4),S:["th","st","nd","rd"][d%10>3?0:(d%100-d%10!=10)*d%10]};return mask.replace(token,function($0){return $0 in flags?flags[$0]:$0.slice(1,$0.length-1)})}}();dateFormat.masks={"default":"ddd mmm dd yyyy HH:MM:ss",shortDate:"m/d/yy",mediumDate:"mmm d, yyyy",longDate:"mmmm d, yyyy",fullDate:"dddd, mmmm d, yyyy",shortTime:"h:MM TT",mediumTime:"h:MM:ss TT",longTime:"h:MM:ss TT Z",isoDate:"yyyy-mm-dd",isoTime:"HH:MM:ss",isoDateTime:"yyyy-mm-dd'T'HH:MM:ss",isoUtcDateTime:"UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"};Date.prototype.format=function(mask,utc){return dateFormat(this,mask,utc)};var formatTimestamp=function(timestamp){timestamp=timestamp.split(/-0?|:0?|T|Z/);var date=new Date(Date.UTC(parseInt(timestamp[0]),parseInt(timestamp[1]),parseInt(timestamp[2]),parseInt(timestamp[3]),parseInt(timestamp[4]),parseInt(timestamp[5])));var timeCorrection=wgPreferences.timecorrection.split(/:0?/);date.setUTCHours(date.getUTCHours()+parseInt(timeCorrection[0]));date.setUTCMinutes(date.getUTCMinutes()+parseInt(timeCorrection[1]));var format="HH:MM, d mmmm yyyy";switch(wgPreferences.date){case"ISO 8601":format="isoDateTime";break;case"ymd":format="HH:MM, yyyy mmmm d";break;case"mdy":format="HH:MM, mmmm d, yyyy";break;default:case"default":case"dmy":break}return date.format("UTC:"+format)};if(!Object.prototype.join){Object.prototype.join=function(separator){var result="";for(var k in this){if(result!="")result+=separator;result+=k}return result}}if(!window.hasAttribute){if(window.HTMLElement&&HTMLElement.prototype.hasAttribute&&window.Element&&Element.prototype.hasAttribute){window.hasAttribute=function(e,attr){return e.hasAttribute(attr)}}else{window.hasAttribute=function(e,attr){return e.getAttribute(attr)!=null}}}var wRclimit=wRclimit||50;if(500<wRclimit)wRclimit=500;var wRcshow=wRcshow||"!bot|!redirect";var wUpdateDelay=wUpdateDelay||10000;if(wUpdateDelay<3000)wUpdateDelay=3000;if(!window.wUpdatesEnabledByDefault)window.wUpdatesEnabledByDefault=true;function processComment(comment){comment=comment.replace("<","&lt;");comment=comment.replace(/\[\[\s*(?![Ii]mage\s*:)([^|]*?)(?:\|(.*?))?\s*\]\]/g,"<a href='"+wgServer+"/wiki/$1' title='$1'>$+</a>");comment=comment.replace(/'''([^']*?)'''/g,"<b>$1</b>");comment=comment.replace(/''([^']*?)''/g,"<i>$1</i>");comment=comment.replace(/\{\{\s*([^|]*?)(\s*(\||&lt;!|\}))/g,"{{<a href='"+wgServer+"/wiki/Template:$1' title='Template:$1' class='external text'>$1</a>$2");return comment}function finishDisablingUpdates(){var endiUpdates=document.getElementById("a-endiupdates");endiUpdates.onclick=function(){enableUpdates()};endiUpdates.innerHTML="Enable updates"}function enableUpdates(initialRun){if(!updateNewPages.updatesEnabled||initialRun){updateNewPages.updatesEnabled=true;var endiUpdates=document.getElementById("a-endiupdates");endiUpdates.onclick=function(){endiUpdates.innerHTML="Disabling...";updateNewPages.updatesEnabled=false};endiUpdates.innerHTML="Disable updates";setTimeout("updateNewPages()",(initialRun)?wUpdateDelay:1)}}function updateNewPages(){if(updateNewPages.updatesEnabled){var bodyContent=document.getElementById("bodyContent");var ul=bodyContent.getElementsByTagName("ul")[0];var list=updateNewPages.list;var request=updateNewPages.request;request.open("GET",wgServer+wgScriptPath+"/api.php?format=xml&action=query&list=recentchanges"+"&rctype=new&rcnamespace=0&rcprop=user|comment|timestamp|title|ids|sizes|redirect|patrolled&rcshow="+wRcshow+"&rclimit="+wRclimit,false);request.send(null);var titles=new Array;var users=new Object;var rcs=request.responseXML.getElementsByTagName("rc");for(var i=rcs.length-1;0<=i;i--){var rc=rcs[i];var title=rc.getAttribute("title");titles.push(title);var li=null;for(var j=0;j<list.length;j++){if(list[j].title==title){li=list[j]}}if(!li){if(wRclimit<=list.length)ul.removeChild(list.shift());li=document.createElement("li");li.title=title;li.appendChild(document.createTextNode(formatTimestamp(rc.getAttribute("timestamp"))+" "));var a=document.createElement("a");a.title=title;if(hasAttribute(rc,"patrolled"))a.href=wgServer+"/wiki/"+encodeURIComponent(title)+"?easydb=1";else a.href=wgServer+"/w/index.php?title="+encodeURIComponent(title)+"&rcid="+rc.getAttribute("rcid")+"&easydb=1";a.innerHTML=title;li.appendChild(a);li.appendChild(document.createTextNode(" ("));a=document.createElement("a");a.title=title;a.href=wgServer+"/w/index.php?title="+encodeURIComponent(title)+"&action=history";a.innerHTML="hist";li.appendChild(a);li.appendChild(document.createTextNode(") ["+rc.getAttribute("newlen")+" bytes] "));a=document.createElement("a");var user=rc.getAttribute("user");if(hasAttribute(rc,"anon")){a.title=user;a.href=wgServer+"/wiki/Special:Contributions/"+user}else{a.title="User:"+user;if(!users[a.title])users[a.title]=new Array;users[a.title].push(a);a.href=wgServer+"/wiki/User:"+user}a.innerHTML=user;li.appendChild(a);li.appendChild(document.createTextNode(" ("));a=document.createElement("a");a.title="User talk:"+user;if(!users[a.title])users[a.title]=new Array;users[a.title].push(a);a.href=wgServer+"/wiki/User talk:"+user;a.innerHTML="Talk";li.appendChild(a);if(!hasAttribute(rc,"anon")){li.appendChild(document.createTextNode(" | "));a=document.createElement("a");a.title="Special:Contributions/"+user;a.href=wgServer+"/wiki/Special:Contributions/"+user;a.innerHTML="contribs";li.appendChild(a)}li.appendChild(document.createTextNode(") "));var span=document.createElement("span");span.className="comment";span.innerHTML=processComment(rc.getAttribute("comment"));li.appendChild(span);list.push(li);ul.insertBefore(li,ul.firstChild)}if(hasAttribute(rc,"patrolled")){li.className="plainlinks";li.getElementsByTagName("a")[0].href=wgServer+"/wiki/"+encodeURIComponent(li.title)+"?easydb=1"}else{li.className="plainlinks not-patrolled";li.getElementsByTagName("a")[0].href=wgServer+"/w/index.php?title="+encodeURIComponent(li.title)+"&rcid="+rc.getAttribute("rcid")+"&easydb=1"}}request.abort();request.open("GET",wgServer+wgScriptPath+"/api.php?format=xml&action=query&prop=info|categories"+"&cllimit=500&titles="+encodeURIComponent(titles.join("|")),false);request.send(null);var pages=request.responseXML.getElementsByTagName("page");outer:for(var i=0;i<pages.length;i++){var page=pages[i];var title=page.getAttribute("title");for(var j=0;j<list.length;j++){if(list[j].title==title){var li=list[j];if(hasAttribute(page,"missing")){if(li.style.display!="none"){li.style.display="none";window.status=title+" was deleted.";window.alert(title+" was deleted.")}}else{var categories=page.getElementsByTagName("cl");for(var k=0;k<categories.length;k++){var title=categories[k].getAttribute("title");if(title=="Category:Candidates for speedy deletion"){li.className="plainlinks sdcandidate";break}else if(title=="Category:Possible copyright violations"){li.className="plainlinks possiblecopyvio";break}}}continue outer}}}request.abort();request.open("GET",wgServer+wgScriptPath+"/api.php?format=xml&action=query&prop=info"+"&titles="+encodeURIComponent(users.join("|")),false);request.send(null);var pages=request.responseXML.getElementsByTagName("page");for(var i=0;i<pages.length;i++){var page=pages[i];if(hasAttribute(page,"missing")){var arr=users[page.getAttribute("title")];for(var j=0;j<arr.length;j++){arr[j].className="new"}}}request.abort();setTimeout("updateNewPages()",wUpdateDelay)}else finishDisablingUpdates()}updateNewPages.list=new Array;updateNewPages.request=sajax_init_object();updateNewPages.updatesEnabled=wUpdatesEnabledByDefault;addOnloadHook(function(){var i=window.location.href.indexOf("?");var queryString=(0<i)?window.location.href.substring(i+1):"";if(wgCanonicalNamespace=="Special"&&wgCanonicalSpecialPageName=="Newpages"){if(!wgPreferences.timecorrect||!wgPreferences.date||!wgPreferences.language){var request=sajax_init_object();request.open("GET",wgServer+wgScriptPath+"/api.php?format=xml&action=query"+"&meta=userinfo&uiprop=options",false);request.send(null);var options=request.responseXML.getElementsByTagName("options")[0];wgPreferences.timecorrection=options.getAttribute("timecorrection");wgPreferences.date=options.getAttribute("date");wgPreferences.language=wgUserLanguage;if(window.wAlertSource&&wgPreferences.toSource)window.alert("var wgPreferences = "+wgPreferences.toSource()+";")}if(!wgMessages.monthNames){wgMessages.monthNames=new Array;var request=sajax_init_object();request.open("GET",wgServer+wgScriptPath+"/api.php?format=xml&action=query"+"&meta=allmessages&ammessages=january|february|march|april|may|june"+"|july|august|september|october|november|december&amlang="+wgPreferences.language,false);request.send(null);var messages=request.responseXML.getElementsByTagName("message");for(var i=0;i<messages.length;i++){var message=messages[i];var name=message.getAttribute("name");wgMessages[name]=message.innerText||message.textContent;wgMessages.monthNames.push(message.innerText||message.textContent)}if(window.wgMessages&&wgMessages.toSource)window.alert("var wgMessages = "+wgMessages.toSource()+";")}var bodyContent=document.getElementById("bodyContent");var ul=bodyContent.getElementsByTagName("ul")[0];var lis=ul.getElementsByTagName("li");for(var i=0;i<lis.length;i++){var li=lis[i];var title=li.getElementsByTagName("a")[0].title.replace("_"," ");li.title=title;updateNewPages.list.unshift(li)}var endiUpdates=document.createElement("a");endiUpdates.id="a-endiupdates";endiUpdates.href="#";endiUpdates.style.paddingLeft="12px";ul.parentNode.insertBefore(endiUpdates,ul);if(updateNewPages.updatesEnabled)enableUpdates(true);else finishDisablingUpdates()}else if(0<=queryString.search(/(?:^|&)easydb=/i)){importStylesheet("Wikipedia:WikiProject User scripts/Scripts/Add LI menu/css");var tabs=document.getElementById("p-cactions").getElementsByTagName("ul")[0];addlimenu(tabs,"db","ca-db","#",document.getElementById("ca-edit"));addPortletLink("ca-db","javascript:db('attack')","attack","ca-db-attack","Serves no purpose but to disparage or threaten its subject or some other entity");addPortletLink("ca-db","javascript:db('band')","band","ca-db-band","About a band, singer, musician, or musical ensemble that does not indicate the importance or significance of the subject");addPortletLink("ca-db","javascript:db('bio')","bio","ca-db-bio","About a real person that does not indicate the importance or significance of the subject");addPortletLink("ca-db","javascript:db('blank')","blank","ca-db-blank","Empty article, or one that consists only of external links, category tags and \"see also\" sections, a rephrasing of the title, attempts to correspond with the person or group named by its title, chat-like comments, template tags and/or images");addPortletLink("ca-db","javascript:db('nocontext')","nocontext","ca-db-nocontext","Very short and lacking sufficient context to identify the subject");addPortletLink("ca-db","javascript:db('nonsense')","nonsense","ca-db-nonsense","Unsalvageably incoherent with no meaningful content or history; patent nonsense");addPortletLink("ca-db","javascript:db('spam')","spam","ca-db-spam","Does nothing but promote some entity and would require a fundamental rewrite in order to become encyclopedic");addPortletLink("ca-db","javascript:db('test')","test","ca-db-test","Test page");addPortletLink("ca-db","javascript:db('vandalism')","vandalism","ca-db-vandalism","Pure vandalism")}else if(wgAction=="edit"&&/&db=([^&]*)/.test(queryString)){var code=RegExp.$1;var wpTextbox1=document.getElementById("wpTextbox1");if(/\{\{\s*db-(\w*)\s*\}\}/.test(wpTextbox1.innerHTML)){window.alert("The article already has a speedy deletion template, `{{db-"+RegExp.$1+"}}`, so `{{db-"+code+"}}` will not be added.")}else{wpTextbox1.style.display="none";wpTextbox1.innerHTML="{{db-"+code+"}}\n"+wpTextbox1.innerHTML;document.getElementById("wpSummary").value="db-"+code;document.getElementById("wpMinoredit").setAttribute("checked","1");document.getElementById("wpSave").click()}}});function db(code){if(!db.inUse){db.inUse=true;var request=sajax_init_object();request.open("GET",wgServer+wgScriptPath+"/api.php?format=xml&action=parse&text={{db-"+code+"}}",false);request.send(null);var div=document.createElement("div");div.id="db-confirmation-dialog";var text=request.responseXML.getElementsByTagName("text")[0];div.innerHTML=text.innerText||text.textContent;div.style.position="absolute";div.style.zIndex="10";div.style.top="13%";div.style.right="0";document.getElementById("bodyContent").appendChild(div);var tbody=div.getElementsByTagName("tbody")[0];var tr=document.createElement("tr");var td=document.createElement("td");td.style.border="medium none";td.style.padding="0px";td.style.width="1px";tr.appendChild(td);td=document.createElement("td");td.align="right";var button=document.createElement("button");button.innerHTML="<b>Confirm</b>";button.onclick=function(){window.location=wgServer+"/w/index.php?action=edit&title="+encodeURIComponent(wgTitle)+"&db="+code};button.style.marginRight="3px";td.appendChild(button);button=document.createElement("button");button.innerHTML="Cancel";button.onclick=function(){var div=document.getElementById("db-confirmation-dialog");div.parentNode.removeChild(div);db.inUse=false};td.appendChild(button);tr.appendChild(td);tbody.appendChild(tr)}}
//</nowiki>