Difference between revisions of "User:Nathan/monobook.js"

MyWikiBiz, Author Your Legacy — Monday November 18, 2024
Jump to navigationJump to search
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
// '''Note''': There is now a mostly equivalent function, <code>addPortletLink()</code>, included as a part of [[MediaWiki]] in [http://en.wikipedia.org/skins-1.5/common/wikibits.js wikibits.js].  Please consider using it instead.  The only major difference is that the first argument to <code>addPortletLink()</code> should be the <code>id</code> attribute of an element containing the list, not the DOM node of the list itself. <pre>
+
// <pre><nowiki>
 +
if (window.showModalDialog && document.compatMode && document.compatMode == "CSS1Compat")
 +
{
 +
  var oldWidth;
 +
  var docEl = document.documentElement;
  
function addlilink(node, href, text, id, tooltip, accesskey) {
+
  function fixIEScroll()
        // the code below is mostly copied from addPortletLink()
+
  {
 +
    if (!oldWidth || docEl.clientWidth > oldWidth)
 +
      doFixIEScroll();
 +
    else
 +
      setTimeout(doFixIEScroll, 1);
 +
 
 +
    oldWidth = docEl.clientWidth;
 +
  }
  
var link = document.createElement( "a" );
+
  function doFixIEScroll() {
link.appendChild( document.createTextNode( text ) );
+
    docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
link.href = href;
+
  }
 
 
var item = document.createElement( "li" );
 
item.appendChild( link );
 
if ( id ) item.id = id;
 
 
 
if ( accesskey ) {
 
link.setAttribute( "accesskey", accesskey );
 
tooltip += " ["+accesskey+"]";
 
}
 
if ( tooltip ) {
 
link.setAttribute( "title", tooltip );
 
}
 
updateTooltipAccessKeys( new Array( link ) );
 
 
 
node.appendChild( item );
 
  
return item;
+
  document.attachEvent("onreadystatechange", fixIEScroll);
 +
  attachEvent("onresize", fixIEScroll);
 
}
 
}
 
// </pre>
 
 
// '''Note''': This is now just a thin wrapper around <code>addPortletLink()</code> from [http://en.wikipedia.org/skins-1.5/common/wikibits.js wikibits.js].  Please consider using <code>addPortletLink()</code> directly instead.
 
 
function addTab(url, name, id, title, key) {
 
    return addPortletLink('p-cactions', url, name, id, title, key);
 
}
 
 
// [[Category:Wikipedia scripts]]
 
 
// <pre><nowiki>
 
 
// Please leave the following line
 
// [[user:Where/usertabs]]
 
 
addOnloadHook(function() {
 
  if (wgTitle.indexOf("/") != -1 || document.title.indexOf("- History -") != -1)  //no subpages or history
 
    return;
 
  if (wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk") {
 
    var username = encodeURIComponent( wgTitle );
 
    addPortletLink("p-cactions", wgServer + "/Special:Contributions/" + username, "Contribs", "ca-contrib", "User contributions");
 
    addPortletLink("p-cactions", wgServer + "/Special:Log&type=move&user=" + username, "Page moves", "ca-pagemoves", "Page moves by this user");
 
    addPortletLink("p-cactions", wgServer + "/Special:Log&type=block&page=User:" + username, "Blocks received", "ca-blog", "Blocks received by this user");
 
    addPortletLink("p-cactions", wgServer + "/Special:Prefixindex&from=" + username + "&namespace=2", "Userspace", "", "List of pages in this user's userspace");
 
    addPortletLink("p-cactions", wgServer + "/Special:Log&type=block&user=" + username, "Blocks given", "", "Blocks by this user");
 
    addPortletLink("p-cactions", wgServer + "/Special:Log&type=protect&user=" + username, "Protections", "", "Protections by this user");
 
    addPortletLink("p-cactions", wgServer + "/Special:Log&type=delete&user=" + username, "Deletions", "", "Deletions by this user");
 
  }
 
});
 
 
 
// </nowiki></pre>
 
// </nowiki></pre>
  

Latest revision as of 08:50, 20 April 2007

// <pre><nowiki>
if (window.showModalDialog && document.compatMode && document.compatMode == "CSS1Compat")
{
  var oldWidth;
  var docEl = document.documentElement;

  function fixIEScroll()
  {
    if (!oldWidth || docEl.clientWidth > oldWidth)
      doFixIEScroll();
    else
      setTimeout(doFixIEScroll, 1);
  
    oldWidth = docEl.clientWidth;
  }

  function doFixIEScroll() {
    docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
  }

  document.attachEvent("onreadystatechange", fixIEScroll);
  attachEvent("onresize", fixIEScroll);
}
// </nowiki></pre>

// This script changes the "Your signature with timestamp" edit button to use a real em dash instead of two hyphens.  <pre><nowiki>

(function () {
    var oldAddButton = addButton;
    if (typeof(oldAddButton) != 'function') return;
    addButton = function () {
        if (arguments.length > 2)
            arguments[2] = arguments[2].replace(/^--(~+)$/, '—$1');
        oldAddButton.apply(this, arguments);
    };
})();

// </nowiki></pre>

//<pre><nowiki>
// Add date and time to your monobook "personal menu" list at the very top of the page.
// Created by [[User:Mathwiz2020]]

// Indicate where you would like the time to appear:
// 1 is first (before username), 2 is second (before talk link), ... 7 is last (after log out link)
insertBeforeNum = 7;

// Do NOT edit below this line unless you're experiened in javascript
insertBeforeArr = new Array("","pt-userpage","pt-mytalk","pt-preferences","pt-watchlist","pt-mycontris","pt-logout","");
insertBefore = insertBeforeArr[insertBeforeNum];

function makeTime()
{
  var li = document.createElement( 'li' );
  li.id = 'pt-time';

  var mySpan = document.createElement( 'span' );
  mySpan.appendChild( document.createTextNode( 'date and time' ) );

  li.appendChild( mySpan );

  if ( insertBefore )
  {
    var before = document.getElementById( insertBefore );
    before.appendChild( li, before );
  }
  else // append to end (right) of list
  {
    document.getElementById( 'pt-logout' ).parentNode.appendChild( li );
  }

  getTime();
}

if      ( window.addEventListener ) window.addEventListener ( 'load', makeTime, false );
else if ( window.attachEvent      ) window.attachEvent      ( 'onload', makeTime      );

function getTime()
{
    var time    = new Date();
    var date    = time.getUTCDate();
    var months  = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ');
        month   = months[time.getUTCMonth()];
    var year    = time.getUTCFullYear();
    var hours   = '0' + time.getUTCHours();
        hours   = hours.substr(hours.length-2, hours.length);
    var minutes = '0' + time.getUTCMinutes();
        minutes = minutes.substr(minutes.length-2, minutes.length);
    var seconds = '0' + time.getUTCSeconds();
        seconds = seconds.substr(seconds.length-2, seconds.length);
    var curTime = hours + ":" + minutes + ":" + seconds + ", " + date + " " + month + " " + year + " (UTC)";
    datePlace   = document.getElementById('pt-time').childNodes[0].childNodes[0];
                  datePlace.replaceData(0, datePlace.length, curTime);
    doTime      = window.setTimeout("getTime()", 1000);
}
//</nowiki></pre>