Jump to content

User:Lar/DYK/monobook.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> 
//automate insertion of the following functions:
// Article talk page: {{dyktalk|10 June|2006}}   
//   (do not subst so that it's compatible with a later change to small)
// Article creator's talk page: {{subst:UpdatedDYK|Article name}}
// Nominator's talk page: {{subst:UpdatedDYKNom|Article name}}

// DEPENDS on  addlilink() and addlimenu() being defined already.

// TO USE JUST THESE FUNCS on new tabs, call add_DYK_tabs() from your main menu hook area

function pipe_date()
{
  var months = new Array('January', 'February', 'March', 'April', 'May', 'June',
                         'July', 'August', 'September', 'October', 'November', 'December');
  var date = new Date();
  var yearStr = date.getUTCFullYear();
  var dayMoStr = months[date.getUTCMonth()] +" "+ date.getUTCDate();
  var t = dayMoStr+"|"+yearStr;
  return t;
}

function dyk_talk()
{
  
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "{{dyktalk|"+pipe_date()+"|small=no}}~~~~";
  f.wpSummary.value = "This article was selected for [[WP:DYK|]]!" 

}

function dyk_talkNo()
{
  
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "{{dyktalk|"+pipe_date()+"|small=no}}";
  f.wpSummary.value = "This article was selected for [[WP:DYK|]]!" 

}

function updated_dyk()
{
  var page = prompt("User created which article?")
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "{{subst:UpdatedDYK|"+pipe_date()+"|" + page + "}} \nThanks for your contributions! ~~~~";
  f.wpSummary.value = "An article which you started, or significantly expanded, ''[[" + page + "]]'', was selected for [[WP:DYK|]]!" 
}

function updated_dyk_nom()
{
  var page = prompt("User nominated which article?")
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "{{subst:UpdatedDYKNom|"+pipe_date()+"|" + page + "}} \nThanks for your contributions! ~~~~";
  f.wpSummary.value = "Your [[WP:DYK|]] nomination for [[" + page + "]] was successful" 
}

/// Special DYK version of add_more_tabs and add Unsigned2 (don't call these if you don't want new tabs, add funcs to some existing one)


// add a {{subst:unsigned2|00:49, 27 May 2006|Joe Random User}} 
// at the end of the current edit contents. 
// will have problems at the change in years since it depends on date.getUTCFullYear()

function addUnsigned2_DYK()
{
  // sample string to paste in is "18:32, 18 June 2006 FredUser" or "00:49, 27 May 2006 Timothy Usher "
  var date = new Date();
  var idString = prompt("ID string?");
  var f = document.editform, t = f.wpTextbox1;

  // a regexp for the date part of the string would be a better way to do this... 
  //... but slicing on year should almost always work

  var pipeLoc= idString.indexOf(date.getUTCFullYear()); // assume 4 digit year, breaks after 9999
  var idStringPiped= idString.substr(0,pipeLoc+4)+'|'+idString.substr(pipeLoc+5,idString.length);

  t.value += "{{subst:unsigned2|" + idStringPiped + "}}";
  f.wpSummary.value = "add {{tl|Unsigned2}} using string:" + idString;
}


// adds various tabs and menu tabs
function add_DYK_tabs()
{
  var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
  var username=document.getElementById("pt-userpage").textContent;

  // Only add for pages with "Editing User talk:" somewhere in the title
  if (document.title.indexOf("Editing User talk:") != -1)
    {
      addlimenu(tabs, 'user talk DYK', 'talkDYK');
      var talkDYK = document.getElementById('talkDYK').getElementsByTagName('ul')[0];
      addlilink(talkDYK,'javascript:updated_dyk()','DYK-Auth');
      addlilink(talkDYK,'javascript:updated_dyk_nom()','DYK-Nom');
      addlilink(talkDYK,'javascript:addUnsigned2_DYK()','Unsigned2');
    }

  // Only add for pages with "Editing Talk:" somewhere in the title
  if (document.title.indexOf("Editing Talk:") != -1) {
      addlimenu(tabs, 'article Talk DYK', 'talkDYK');
      var talkDYK = document.getElementById('talkDYK').getElementsByTagName('ul')[0];
      addlilink(talkDYK,'javascript:dyk_talk()','DYK talk');
      addlilink(talkDYK,'javascript:dyk_talkNo()','DYK talk no sig'); 
      addlilink(talkDYK,'javascript:addUnsigned2_DYK()','Unsigned2');
  }

}



// end of file </nowiki>