Jump to content

User:Rhododendrites/scripts/delsort-monobook-all.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.
// *********************************
// *********************************
// NOTICE: THIS SCRIPT WAS WRITTEN BY [[User:Fox Wilson]] AND COPIED FROM [[User:Fox Wilson/delsort-monobook.js]]. THE ONLY REASON IT IS DUPLICATED HERE IS TO CUSTOMIZE THE DELSORT LIST
// (and by "customize" I mean reproduce the ENTIRE delsort list, along with mickeymoused organizational headers) -- (see [[kludge]])
// This script puts delsort categories in the sidebar. It was intended for Monobook, but works in Vector, too.
// See also [[User:Rhododendrites/scripts/delsort-all.js]], which puts them in a Vector-style dropdown for those who like that sort of thing.
// --Rhododendrites
// *********************************
// *********************************

function defineLink(category){

  mw.util.addPortletLink('pt-delsort', 'javascript:doDelsort("' + category + '")', category, '');

}

if (mw.config.get('wgPageName').indexOf('Wikipedia:Articles_for_deletion/') != -1 && mw.config.get('wgPageName').indexOf('Wikipedia:Articles_for_deletion/Log/201') == -1) {
mw.util.addPortletLink ('p-interaction', 'javascript:delsortIt()', 'Delsort', 'pt-delsort', 'Perform deletion sorting');
// Define custom ones here
defineLink("BASICS");
defineLink("People");
defineLink("Fictional elements");
defineLink("Companies");
defineLink("Organizations");
defineLink("Products");
defineLink("Music");
defineLink("Sports");
defineLink("Science");
defineLink("Religion");
defineLink("Politics");
defineLink("Arts");
defineLink("Visual arts");
defineLink("Lists");
defineLink("Lists of people");
defineLink("Computing");
defineLink("Internet");
defineLink("Software");
defineLink("Technology");
defineLink("Websites");
defineLink("Crime");
defineLink("Events");
defineLink("Schools");
defineLink("History");
defineLink("Language");
defineLink("Law");

defineLink("______________________");
defineLink("______________________");
defineLink("TYPES OF PAGES");
defineLink("Bibliographies");
defineLink("Disambiguations");

defineLink("______________________");
defineLink("______________________");
defineLink("TYPES OF PEOPLE");
defineLink("Academics and educators");
defineLink("Actors and filmmakers");
defineLink("Artists");
defineLink("Authors");
defineLink("Businesspeople");
defineLink("Politicians");
defineLink("Sportspeople");

defineLink("______________________");
defineLink("______________________");
defineLink("BUSINESS/ORGS");
defineLink("Advertising");
defineLink("Business");
defineLink("Management");

defineLink("______________________");
defineLink("______________________");
defineLink("ARTS");
defineLink("Architecture");
defineLink("Fashion");
defineLink("Literature");	
defineLink("Poetry");
defineLink("Theatre");

defineLink("______________________");
defineLink("______________________");
defineLink("AUDIO");
defineLink("Albums and songs");
defineLink("Bands and musicians");	
defineLink("Radio");

defineLink("______________________");
defineLink("______________________");
defineLink("VISUAL");
defineLink("Anime and manga");
defineLink("Comics and animation");
defineLink("Film");
defineLink("Photography");
defineLink("Television");
defineLink("Video games");
defineLink("Webcomics");

defineLink("______________________");
defineLink("______________________");
defineLink("SCIENCE");
defineLink("Astronomy");
defineLink("Behavioural science");
defineLink("COVID-19");
defineLink("Environment");
defineLink("Medicine");
defineLink("Organisms");

defineLink("______________________");
defineLink("______________________");
defineLink("RELIGION/IRRELIGION");
defineLink("Atheism");
defineLink("Bible");
defineLink("Buddhism");
defineLink("Christianity");
defineLink("Hinduism");
defineLink("Islam");
defineLink("Judaism");
defineLink("Paganism");
defineLink("Sikhism");
defineLink("Spirituality");

defineLink("______________________");
defineLink("______________________");
defineLink("POLITICS");
defineLink("Conservatism");
defineLink("Conspiracy theories");

defineLink("______________________");
defineLink("______________________");
defineLink("SPORTS");
defineLink("American football");
defineLink("Baseball");
defineLink("Basketball");
defineLink("Bodybuilding");
defineLink("Cricket");
defineLink("Cycling");
defineLink("Football");
defineLink("Golf");
defineLink("Health and fitness");
defineLink("Ice hockey");
defineLink("Martial arts");	
defineLink("Rugby union");
defineLink("Softball");
defineLink("Wrestling");

defineLink("______________________");
defineLink("______________________");
defineLink("ETC");
defineLink("Aviation");
defineLink("Bilateral relations");
defineLink("Disability");
defineLink("Education");
defineLink("Ethnic groups");
defineLink("Firearms");
defineLink("Food and drink");
defineLink("Games");
defineLink("Islands");
defineLink("Journalism");
defineLink("Libraries");
defineLink("Logic");
defineLink("Magic");
defineLink("Mathematics");
defineLink("Military");
defineLink("Museums");
defineLink("News media");
defineLink("Paranormal");
defineLink("Philosophy");
defineLink("Piracy");
defineLink("Popular culture");
defineLink("Science fiction");
defineLink("Sexuality and gender");
defineLink("Shopping malls");
defineLink("Social science");
defineLink("Terrorism");
defineLink("Transportation");
defineLink("Wine");

defineLink("______________________");
defineLink("______________________");
defineLink("PLACES");
defineLink("North America");
defineLink("South America");
defineLink("Europe");
defineLink("Australia");
defineLink("Africa");
defineLink("Asia");
defineLink("Antarctica");

defineLink("______________________");
defineLink("Caribbean");
defineLink("Central Asia");
defineLink("Latin America");
defineLink("Middle East");
defineLink("Oceania");
defineLink("Palestine");

defineLink("______________________");
defineLink("Afghanistan");
defineLink("Albania");
defineLink("Argentina");
defineLink("Armenia");
defineLink("Austria");
defineLink("Azerbaijan");
defineLink("Bahrain");
defineLink("Bangladesh");
defineLink("Barbados");
defineLink("Belarus");
defineLink("Belgium");
defineLink("Belize");
defineLink("Bolivia");
defineLink("Bosnia");
defineLink("Brazil");
defineLink("Brunei");
defineLink("Bulgaria");
defineLink("Cambodia");
defineLink("Chile");
defineLink("China");
defineLink("Colombia");
defineLink("Colorado");
defineLink("Croatia");
defineLink("Cuba");
defineLink("Cyprus");
defineLink("Czech Republic");
defineLink("Denmark");
defineLink("Ecuador");
defineLink("El Salvador");
defineLink("Egypt");
defineLink("England");
defineLink("Eritrea");
defineLink("Estonia");
defineLink("Ethiopia");
defineLink("Finland");
defineLink("France");
defineLink("Georgia (country)");
defineLink("Germany");
defineLink("Greece");
defineLink("Guatemala");
defineLink("Haiti");
defineLink("Hawaii");
defineLink("Hong Kong");
defineLink("Hungary");
defineLink("Iceland");
defineLink("India");
defineLink("Indonesia");
defineLink("Iran");
defineLink("Iraq");
defineLink("Ireland");
defineLink("Israel");
defineLink("Italy");
defineLink("Japan");
defineLink("Kansas");
defineLink("Kazakhstan");
defineLink("Kenya");
defineLink("Korea");
defineLink("Kosovo");
defineLink("Latvia");
defineLink("Lebanon");
defineLink("Lithuania");
defineLink("Luxembourg");
defineLink("Republic of Macedonia");
defineLink("Malaysia");
defineLink("Maldives");
defineLink("Mauritius");
defineLink("Mexico");
defineLink("Mongolia");
defineLink("Montenegro");
defineLink("Morocco");
defineLink("Nepal");
defineLink("Netherlands");
defineLink("New Zealand");
defineLink("Nigeria");
defineLink("Northern Ireland");
defineLink("Norway");
defineLink("Pakistan");
defineLink("Panama");
defineLink("Paraguay");
defineLink("Peru");
defineLink("Philippines");
defineLink("Poland");
defineLink("Portugal");
defineLink("Romania");
defineLink("Russia");
defineLink("Saudi Arabia");
defineLink("Scotland");
defineLink("Senegal");
defineLink("Serbia");
defineLink("Singapore");
defineLink("Slovakia");
defineLink("Slovenia");
defineLink("Somalia");
defineLink("South Africa");
defineLink("Spain");
defineLink("Sri Lanka");
defineLink("Sweden");
defineLink("Switzerland");
defineLink("Syria");
defineLink("Taiwan");
defineLink("Tajikistan");
defineLink("Tanzania");
defineLink("Thailand");
defineLink("Trinidad and Tobago");
defineLink("Turkey");
defineLink("Turkmenistan");
defineLink("Uganda");
defineLink("Uruguay");
defineLink("Ukraine");
defineLink("United Arab Emirates");
defineLink("United Kingdom");
defineLink("Uzbekistan");
defineLink("Venezuela");
defineLink("Vietnam");
defineLink("Wales");
defineLink("Yugoslavia");
defineLink("Zambia");
defineLink("Zimbabwe");

defineLink("______________________");
defineLink("United States of America");
defineLink("Alabama");
defineLink("Alaska");
defineLink("Arizona");
defineLink("Arkansas");
defineLink("California");
defineLink("Colorado");
defineLink("Connecticut");
defineLink("Delaware");
defineLink("Florida");
defineLink("Georgia (U.S. state)");
defineLink("Hawaii");
defineLink("Idaho");
defineLink("Illinois");
defineLink("Indiana");
defineLink("Iowa");
defineLink("Kansas");
defineLink("Kentucky");
defineLink("Louisiana");
defineLink("Maine");
defineLink("Maryland");
defineLink("Massachusetts");
defineLink("Michigan");
defineLink("Minnesota");
defineLink("Mississippi");
defineLink("Missouri");
defineLink("Montana");
defineLink("Nebraska");
defineLink("Nevada");
defineLink("New Hampshire");
defineLink("New Jersey");
defineLink("New Mexico");
defineLink("New York");
defineLink("North Carolina");
defineLink("North Dakota");
defineLink("Ohio");
defineLink("Oklahoma");
defineLink("Oregon");
defineLink("Pennsylvania");
defineLink("Puerto Rico");
defineLink("Rhode Island");
defineLink("South Carolina");
defineLink("South Dakota");
defineLink("Tennessee");
defineLink("Texas");
defineLink("Utah");
defineLink("Vermont");
defineLink("Virginia");
defineLink("Washington");
defineLink("Washington, D.C.");
defineLink("West Virginia");
defineLink("Wisconsin");
defineLink("Wyoming");

defineLink("______________________");
defineLink("Canada");
defineLink("British Columbia");
defineLink("Manitoba");
defineLink("Nova Scotia");
defineLink("Ontario");
defineLink("Quebec");

// End custom defs
}

function delsortIt(){

  x = prompt("Category: ");

  if (x != null){doDelsort(x);}

  else{alert('Delsort cancelled!');}

}
function doDelsort(cat){

  var url = "//en.wikipedia.org/w/api.php?action=query&format=json&meta=tokens&type=csrf"; 
  var xhr = new XMLHttpRequest();
  xhr.open("GET", url); //Code now working, was set to async
  xhr.send();
  xhr.onreadystatechange = function() {
    if (xhr.readyState == 4 && xhr.status == 200) {
      var resp = JSON.parse(xhr.responseText);
      console.log("Token first: ", resp.query.tokens.csrftoken);
      $.each(resp, function(i,v){console.log(i,"=",v);});
      var etoken = resp.query.tokens.csrftoken;
console.log("The token is: ", etoken);
if (cat != null){
  var editData = {               
                  action: "edit",
                  format: "json",
                  summary: "Listing at [[WP:DELSORT]] under " + cat + " ([[WP:FWDS|FWDS]])",
                  token: etoken,
                  title: mw.config.get('wgPageName'),
                  appendtext: "\{\{subst:Delsort|" + cat + "|\~\~\~\~\}\}"
  };
  $.each(editData, function(i,v){console.log(i,"=",v);});
  $.post('//en.wikipedia.org/w/api.php', editData, function(data){jQuery.each(data, function( index, value ) {

  console.log( "index", index, "value", value );

});});
// Add to the Delsort page 

  //First, get the content

  $.post('//en.wikipedia.org/w/api.php', 
{action:'query', format:'json', prop:'revisions', rvprop:'content', rvlimit:'1', titles:'Wikipedia:WikiProject Deletion sorting/'+cat}, 

function(data){

  $.each(data.query.pages, 

    function(i,v){

      window.editContent = v.revisions[0]['*'].replace('directly below this line -->', 'directly below this line -->\n\{\{' + mw.config.get('wgPageName') + '\}\}');

    } );

  var editData = {               
                  action: "edit",
                  format: "json",
                  token: etoken,

                  summary: "Listing [[" + mw.config.get('wgPageName') + "]] ([[WP:FWDS|FWDS]])",
                  title: 'Wikipedia:WikiProject Deletion sorting/' + cat,
                  text: window.editContent
  };
  $.each(editData, function(i,v){console.log(i,"=",v);});
  $.post('//en.wikipedia.org/w/api.php', editData, function(data){jQuery.each(data, function( index, value ) {
  console.log( "index", index, "value", value );});});
  alert('Delsort complete.');
  }
);

}
    }
  }
}