Jump to content

User:Davidgothberg/monobook.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Davidgothberg (talk | contribs) at 02:42, 27 November 2009 (Testing TheDJ's new code.). 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.
/************************************************************
    Note! Old JavaScript code is stored on the talk page. 
*************************************************************/

/* A JavaScript file loaded from my local web server for testing. */
importScriptURI( 'http://localhost:8080/wikipediatest.js' );


/* Works! */
/*
importStylesheet( 'User:Bob/externals.css' );
importStylesheetURI( 'http://localhost:8080/wikipediatest.css' );
*/


/*******************************************************
   Note! The DavidClock has been moved to 
   [[User:Davidgothberg/clock.js]]. See code and usage
   explanation there.
********************************************************/
window.davidClock = 300;    //Static + ticking clock, every 5 minutes.
importScript( "User:Davidgothberg/clock.js" );


/* New messages history */
importScript( "User:Davidgothberg/newmessageshistory.js" );



// [[User:Gerbrant/edit/top.js]]

// This will add an [edit] link at the top of all pages except preview pages and the main page.
// Originally by [[User:Pile0nades]], modified by [[User:Gerbrant]].
// [[User:Davidgothberg]] added a [purge] link.

// Add an [edit] link to pages
hookEvent("load", function ()
{
	if(window.location.href.indexOf("/wiki/Special:") != -1) return;
	if(document.getElementById("wikiPreview")) return;
	if(document.getElementById("histlegend‎")) return;
	if(document.getElementById("difference‎")) return;
	if(document.getElementById("watchdetails")) return;
	if(document.getElementById("mainpage")) return;

	if(window.location.href.indexOf("&action=edit") == -1)
	{
		var pageTitle = document.title.split(" - ")[0].replace(" ", "_");
		var divContainer = document.createElement("div");


		divContainer.innerHTML = '<div class="editsection" style="float:right; margin-top:0px;">\
[<a href="/w/index.php?title=' + pageTitle + '&action=purge" \
title="' + pageTitle + '">purge</a>]<br/>[<a href="/w/index.php?title=' + pageTitle + '&action=edit&section=0" \
title="' + pageTitle + '">edit</a>]</div>';


		var coos = document.getElementById("coordinates");
		if(coos) coos.style.right = "4.5em";
		document.getElementById("content").insertBefore(
			divContainer, document.getElementsByTagName("h1")[0]);
	}
	else if(window.location.href.indexOf("&action=edit&section=0") != -1)
	{
		e = document.getElementById("wpSummary");
		if(e) e.value = "/* Intro */ ";
	}
});



// Turn on spellchecking in the edit summary field, for Firefox. 
// Remove this when MediaWiki uses HTML 5 and adds 
// the "spellcheck=true" attribute in the rendered pages.
/*
addOnloadHook( function() {
  var wpSummary = document.getElementById( "wpSummary" );
  if ( wpSummary && typeof wpSummary.spellcheck != undefined )
    wpSummary.spellcheck = true;
} );
*/


/* Adding the "My sandbox" or "Sandbox" link. */
/*
addOnloadHook( function () {

  if( wgUserName ) {
    addPortletLink( 'p-personal', wgArticlePath.replace("$1", "Special:Mypage/sandbox"), 'My sandbox', 'pt-sandbox', 'Your personal sandbox', null, document.getElementById('pt-preferences'));
  }
  else {
    addPortletLink( 'p-personal', wgArticlePath.replace("$1", "Wikipedia:Sandbox"), 'Sandbox', 'pt-sandbox', 'A sandbox where you can experiment' );
  }
} );
*/



/* Add "Extended search" to the "navigation" menu. */
addOnloadHook( function() {

  /* Add an "Extended search" link to the "navigation" menu". */
  addPortletLink( 'p-navigation', wgArticlePath.replace("$1", "Special:Search"), 'Extended search', 'pt-search', 'More search options' );

} );



/* Extra buttons for the Edit Toolbar. */
/*
mwCustomEditButtons.push( {
  "imageFile": "/media/wikipedia/commons/5/5f/Btn_toolbar_tt.png",
  "speedTip": "<tt></tt>",
  "tagOpen": "<tt>",
  "tagClose": "</tt>",
  "sampleText": ""
} );
*/

mwCustomEditButtons.push( {
  "imageFile": "/media/wikipedia/commons/2/23/Button_code.png",
  "speedTip": "<code><nowiki></nowiki></code>",
  "tagOpen": "<code><nowiki>",
  "tagClose": "</nowiki></code>",
  "sampleText": ""
} );



// [[User:Lupin/popups.js]]
//importScript('User:Lupin/popups.js');   // Old method.
//importStylesheet('MediaWiki:Gadget-navpop.css');  //Really old method.
//importScript('User:TheDJ/slimpopups.js');         //Really old method.
/* I now load it using "my preferences - Gadgets 
   - Navigation popups" instead. */

// When true prevents loading of preview data for the popup.
simplePopups=true;

// When false makes it so the "actions" menu instead goes under the page link instead of as a separate menu.
popupActionsMenu=false;

// PopupStructure can be 'original', 'fancy', 'fancy2', 'menus', 'shortmenus', 'lite', 'nostalgia'
// popupStructure='original';



/* Makes the "compare selected versions" button on history pages 
   into a link (allows diffs in new windows, tabs, etc.)
   [[User:Superm401/Compare link.js]]  */
importScript("User:Superm401/Compare link.js");



/* Colour matching brackets in a copy of the edit box.
   [[User:ais523/bracketmatch.js]]   */
importScript("User:ais523/bracketmatch.js");



/* Shows both "preview" and "changes" with Ajax, 
   much faster than standard preview/changes buttons. 
   [[User:Js/ajaxPreview]]   */
importScript("User:Js/ajaxPreview.js");
ajaxPreviewButton = 'P';    // "Preview" button text, when above.
ajaxDiffButton = 'D';       // "Changes" button text, when above.
ajaxPreviewPos = 'bottom';  // Buttons on the bottom, replacing standard.
/* Code to execute after each preview update. */
ajaxPreviewExec = function(previewArea) {
  if (window.setupTooltips)
    setupTooltips(previewArea);   // Restart the Navigation popups.
}



/*******************************************************
   Note! The DavidClock has been moved to 
   [[User:Davidgothberg/clock.js]]. See code and usage
   explanation there.
********************************************************/



// SVG images: adds links to rendered PNG images in different resolutions
function SVGThumbs() {
	var file = document.getElementById("file"); // might fail if MediaWiki can't render the SVG
	if (file && wgIsArticle && wgTitle.substring(wgTitle.lastIndexOf(".")).toLowerCase() == ".svg") {
		var thumbu = file.getElementsByTagName('IMG')[0].src;
		var thumbs = file.getElementsByTagName('IMG')[0].width;
		if(!thumbu || !thumbs) return;
 
		function svgAltSize( w, title) {
			var path = thumbu.replace( "/"+thumbs+"px-", "/"+ w +"px-" );
			var a = document.createElement("A");
			a.setAttribute("href", path);
			a.appendChild(document.createTextNode(title));
			return a;
		}
 
		var p = document.createElement("p");
		p.className = "SVGThumbs";
		p.appendChild(document.createTextNode("This image rendered as PNG in other sizes"+": "));
		var l = new Array( 200, 500, 1000, 2000 )
                for( var i = 0; i < l.length; i++ ) {
			p.appendChild(svgAltSize( l[i], l[i] + "px"));
			if( i < l.length-1 ) p.appendChild(document.createTextNode(", "));
                }
		p.appendChild(document.createTextNode("."));
		var info = getElementsByClassName( file.parentNode, 'div', 'fullMedia' )[0];
		if( info ) info.appendChild(p);
	}
};
addOnloadHook( SVGThumbs )