User:ABCD/monobook.js

From Wikimedia Foundation Governance Wiki
Revision as of 02:11, 27 January 2006 by ABCD (talk | contribs) (create)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* <nowiki> */
function replace(){
    var s = prompt("Search regexp?");
    if(s){
        var r = prompt("Replace regexp?");
        if(!r && r != '') return;
        var txt = document.editform.wpTextbox1;
        txt.value = txt.value.replace(new RegExp(s, "g"), r);
    }
}

function addlilink(tabs, url, name, id, title, key){
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    na.accesskey = key;
    var pref = 'alt-';
    if(key && title) na.title = title + ' [' + pref + key + ']';
    else if(title) na.title = title;
    else if(key) na.title = '[' + pref + key + ']';
    var li = document.createElement('li');
    if(id) li.id = id;
    li.appendChild(na);
    tabs.appendChild(li);
    return li;
}

function addTab(url, name, id, title, key){
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    addlilink(tabs, url, name, id, title, key);
}

function addPurge(){
    var x = document.getElementById('ca-history');
    if(!x) return;
    if(x.children) x = x.children[0].href;
    else x = x.childNodes[0].href;
    addTab(x.replace(/=history/, "=purge"), 'purge', 'ca-purge', 'Purge the internal cache for this page', 'g');
}

function addEditSection0(){
    if(!document.getElementById) return;
    var x = document.getElementById('ca-edit');
    if(!x) return;
    var y = document.createElement('LI');
    y.id = 'ca-edit-0';
    if(x.className == 'selected'){
      if(/&action=edit&section=0$/.test(window.location.href)){
        x.className = 'istalk';
        y.className = 'selected';
      } else {
        x.className = 'selected istalk';
      }
    } else if(x.className == 'selected istalk'){
      if(/&action=edit&section=0$/.test(window.location.href)){
        x.className = 'istalk';
        y.className = 'selected istalk';
      } else {
        y.className = 'istalk';
      }
    } else {
      y.className = x.className;
      x.className = 'istalk';
    }
    var z = document.createElement('A');
    if(x.children){
        z.href = x.children[0].href + '&section=0';
        z.appendChild(document.createTextNode('0'));
        y.appendChild(z);
        document.getElementById('p-cactions').children[1].insertBefore(y,x.nextSibling);
    }else{
        z.href = x.childNodes[0].href + '&section=0';
        z.appendChild(document.createTextNode('0'));
        y.appendChild(z);
        document.getElementById('p-cactions').childNodes[3].insertBefore(y,x.nextSibling);
    }
    z.title = 'Edit the zeroth section of this page';
    akeytt();
}

function changeLinks(){
    if(!document.getElementById) return;
    document.getElementById('pt-mytalk').firstChild.innerHTML = 'Talk';
    document.getElementById('pt-preferences').firstChild.innerHTML = 'Preferences';
    document.getElementById('pt-watchlist').firstChild.innerHTML = 'Watchlist';
    document.getElementById('pt-mycontris').firstChild.innerHTML = 'Contributions';
    document.getElementById('pt-logout').firstChild.innerHTML = 'Log out';
    if(document.getElementById('ca-talk'))
        document.getElementById('ca-talk').firstChild.innerHTML = 'Talk';
    if(document.getElementById('ca-edit'))
        document.getElementById('ca-edit').firstChild.innerHTML = 'Edit';
    if(document.getElementById('ca-nstab-wp'))
        document.getElementById('ca-nstab-wp').firstChild.innerHTML = 'About';
}
function addForceSummary(){
    if(!/&action=edit/.test(window.location.href)) return;
    if(/&section=new/.test(window.location.href)) return;
    if(!document.forms.editform) return;
    document.forms.editform.wpSave.onclick = forceSummary;
}

function forceSummary(){
    var form = document.forms.editform;
    if(!form.wpSummary.value.replace(/^(\/\*.*\*\/)? *(.*) *$/,'$2')){
      var r = prompt('Are you sure you want to submit without adding a summary?\nTo add a summary, type it in the box below:',form.wpSummary.value);
      if(r == null) return false;
      form.wpSummary.value = r;
    }
    return true;
}

function afddelete(){
    document.forms.deleteconfirm.wpReason.value = '[[Wikipedia:Articles for deletion/' + unescape(window.location.href.replace(/^.*\?title=([^&]+)&action=delete.*$/, '$1').replace(/_/g, ' ')).replace(/^(Talk|Wikipedia( talk)?):/, '') + ']]';
}

function morelinks(){
    if(document.title.indexOf("Editing ") == 0) addTab('javascript:replace()', 'Replace');
}

function myLoadFuncs(){
    addPurge();
    addEditSection0();
    changeLinks();
    addForceSummary();
    morelinks();
    addToolBoxLinks();
}
/* </nowiki> */