Jump to content

User:Prodego/monobook.js

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Prodego (talk | contribs) at 01:52, 11 January 2007 (test). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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.
function addlimenu(tabs, name, id)
{
    var na = document.createElement('a');
    na.href = '#';
    var mn = document.createElement('ul');
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.id = id;
    li.className = 'tabmenu';
    li.appendChild(na);
    li.appendChild(mn);
    tabs.appendChild(li);
    return li;
}

function addlilink(tabs, url, name, id){
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.id = id;
    li.appendChild(na);
    tabs.appendChild(li);
    return li;
}



// appends msg to the currently-editted page, sets the summary to summ,
// and marks or unmarks the Watch this page checkbox according to watch.
function edit_summary_watch(msg, summ, watch, line)
{
  var f = document.editform, t = f.wpTextbox1;
  if ((t.value.length > 0) && (line == 1))
    t.value += '\n\n';
  if (line == -1)
    t.value = msg + t.value;
  else
    t.value += msg;
  if (summ.charAt(0) == '+')
    f.wpSummary.value += summ.substr(1);
  else
    f.wpSummary.value = summ;
  f.wpWatchthis.checked = 0;
}

function add_talk_header()
{
  var from_page = "";
  var from_index = location.search.indexOf("&fakefrom=");
  if(from_index != -1)
    var from_page = unescape(location.search.substring(from_index + 10));
  edit_summary_watch("Regarding your edits to [[\:" + from_page + "]]: ", "\/\* " + from_page + "\*\/ ", true, 1);
}

function testwarning(level, summ, sig)
{
    var user_warnings = new Array (
       "test2a", "test1", "test2", "test3", "test4", "test5-n|31 hours|~\~\~\~", "vblock|31 hours|~\~\~\~", "vpblock", "usertalk-sprotect", "test1a" );
    var msg = "{{" + (level == 8 ? "" : "subst:") + user_warnings [level] + "}}" + (sig==1 ? "\n\n\~\~\~\~\n" : "\n");
    if (level == 3)
        msg = "[[" + "Image:Stop_hand.png|left|30px]]" + msg;
    edit_summary_watch (msg, summ, true, ((level != 8) ? 1 : -1));
}
// adds various tabs to call the above
function add_tabs()
{
  var c1 = document.getElementById('column-one');
  var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];

  // Only add for pages with "Editing User talk:" somewhere in the title
  if (document.title.indexOf("Editing User talk:") != -1)
  {
   addlimenu(tabs, 'Warnings', 'usert');
   var usert = document.getElementById('usert').getElementsByTagName('ul')[0];
   addlilink(usert,'javascript:add_talk_header()',"header");
   addlilink(usert,'javascript:testwarning(1,"+{{" + "test1}}",1)',"test1");
   addlilink(usert,'javascript:testwarning(9,"+{{" + "test1a}}",1)',"test1a");
   addlilink(usert,'javascript:testwarning(2,"+{{" + "test2}}",1)',"test2");
   addlilink(usert,'javascript:testwarning(0,"+{{" + "test2a}}",1)',"test2a");
   addlilink(usert,'javascript:testwarning(3,"+{{" + "test3}}",1)',"test3");
   addlilink(usert,'javascript:testwarning(4,"+{{" + "test4}}",1)',"test4");

   }

}

function strip_namespace(target)
{
  var colon = target.indexOf(':');
  if (colon != -1)
    {
      var spaces = new Array('User', 'Wikipedia', 'Image', 'MediaWiki', 'Template', 'Help', 'Category');
      var ns = target.substring(0, colon);
      if (ns == '' || ns == 'Talk')
        return target.substring(colon + 1);
      else
        for (var i = 0; i < spaces.length; ++i)
          {
            if (ns == spaces[i]
                || ns == spaces[i] + '_talk')
              return target.substring(colon + 1);
          }
    }

  return target;
}

function do_warn_stuff()
{
  var c1 = document.getElementById('column-one');
  var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];
  var rcol = document.getElementById('bodyContent').getElementsByTagName('td').item(1);
  if (rcol != null)
  {
     var vandalname = rcol.getElementsByTagName('a')[3].innerHTML;
    var page = document.title.substring (0, document.title.length - 35);
    addlilink(tabs,'http://en.wikipedia.org/w/index.php?title=User_talk:' + vandalname + '&action=edit&fakefrom=' + escape(page), 'Warn');
  }
}

function do_onload()
{
   if (document.getElementById('contentSub').innerHTML.indexOf("(Difference between revisions)")>-1)
   do_warn_stuff();
}


if (window.addEventListener) 
  window.addEventListener("load", do_onload, false);
else if (window.attachEvent) 
  window.attachEvent("onload", do_onload);

if (window.addEventListener)
  window.addEventListener("load", add_tabs, false);
else if (window.attachEvent)
  window.attachEvent("onload", add_tabs);