User:Psl85/common.js

ShoutWiki — express yourself and be heard!
Jump to navigation Jump to search

Note: After saving, 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: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
function addExtraButtons () {
	mw.toolbar.addButtons(
	{
		imageId: 'button-redirect',
		imageFile: '//upload.wikimedia.org/wikipedia/en/c/c8/Button_redirect.png',
		speedTip: 'Redirect',
		tagOpen: '#REDIRECT[[',
		tagClose: ']]',
		sampleText: 'Target page name'
	},
	{
		imageId: 'button-strike',
		imageFile: '//upload.wikimedia.org/wikipedia/en/c/c9/Button_strike.png',
		speedTip: 'Strike',
		tagOpen: '<s>',
		tagClose: '</s>',
		sampleText: 'Strike-through text'
	},
	{
		imageId: 'button-enter',
		imageFile: '//upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png',
		speedTip: 'Line break',
		tagOpen: '<br/>',
		tagClose: '',
		sampleText: ''
	},
	{
		imageId: 'button-subscript',
		imageFile: '//upload.wikimedia.org/wikipedia/en/7/70/Button_lower_letter.png',
		speedTip: 'Subscript',
		tagOpen: '<sub>',
		tagClose: '</sub>',
		sampleText: 'Subscript text'
	},
	{
		imageId: 'button-superscript',
		imageFile: '//upload.wikimedia.org/wikipedia/en/8/80/Button_upper_letter.png',
		speedTip: 'Superscript',
		tagOpen: '<sup>',
		tagClose: '</sup>',
		sampleText: 'Superscript text'
	},
	{
		imageId: 'button-small',
		imageFile: '//upload.wikimedia.org/wikipedia/en/5/58/Button_small.png',
		speedTip: 'Small',
		tagOpen: '<small>',
		tagClose: '</small>',
		sampleText: 'Small text'
	},
	{
		imageId: 'button-hide-comment',
		imageFile: '//upload.wikimedia.org/wikipedia/en/3/34/Button_hide_comment.png',
		speedTip: 'Insert hidden Comment',
		tagOpen: '<!-- ',
		tagClose: ' -->',
		sampleText: 'Comment'
	},
	{
		imageId: 'button-gallery',
		imageFile: '//upload.wikimedia.org/wikipedia/en/1/12/Button_gallery.png',
		speedTip: 'Insert a picture gallery',
		tagOpen: '\n<gallery>\n',
		tagClose: '\n</gallery>',
		sampleText: 'File:Example.svg|Caption1\nFile:Example.jpg|Caption2'
	},
	{
		imageId: 'button-blockquote',
		imageFile: '//upload.wikimedia.org/wikipedia/en/f/fd/Button_blockquote.png',
		speedTip: 'Insert block of quoted text',
		tagOpen: '<blockquote>\n',
		tagClose: '\n</blockquote>',
		sampleText: 'Block quote'
	},
	{
		imageId: 'button-insert-table',
		imageFile: '//upload.wikimedia.org/wikipedia/en/6/60/Button_insert_table.png',
		speedTip: 'Insert a table',
		tagOpen: '{| class="wikitable"\n|',
		tagClose: '\n|}',
		sampleText: '-\n! header 1\n! header 2\n! header 3\n|-\n| row 1, cell 1\n| row 1, cell 2\n| row 1, cell 3\n|-\n| row 2, cell 1\n| row 2, cell 2\n| row 2, cell 3'
	},
	{
		imageId: 'button-insert-reflink',
		imageFile: '//upload.wikimedia.org/wikipedia/commons/7/79/Button_reflink.png',
		speedTip: 'Insert a reference',
		tagOpen: '<ref>',
		tagClose: '</ref>',
		sampleText: 'Insert footnote text here'
	},
	{
		imageId: 'button-insert-template',
		imageFile: '//upload.wikimedia.org/wikipedia/commons/4/43/Button-template.png',
		speedTip: 'Insert template braces',
		tagOpen: '{{',
		tagClose: '}}',
		sampleText: 'Insert template name'
	},
	{
		imageId: 'button-insert-gallery',
		imageFile: '//upload.wikimedia.org/wikipedia/commons/4/43/Button-gallery.png',
		speedTip: 'Insert template braces',
		tagOpen: '{{',
		tagClose: '}}',
		sampleText: 'Insert template name'
	},
	{
		imageId: 'button-insert-underline',
		imageFile: '//upload.wikimedia.org/wikipedia/commons/f/fd/Button_underline.png',
		speedTip: 'Insert underlined text',
		tagOpen: '<u>',
		tagClose: '</u>',
		sampleText: 'Underlined text'
	},
	{
		imageId: 'button-insert-gallery',
		imageFile: '//upload.wikimedia.org/wikipedia/commons/9/9e/Btn_toolbar_gallery.png',
		speedTip: 'Insert a gallery',
		tagOpen: '<gallery>',
		tagClose: '</gallery>',
		sampleText: 'Insert gallery images'
	},
	{
		imageId: 'button-insert-wplink',
		imageFile: '//upload.wikimedia.org/wikipedia/commons/7/7f/Button_link_to_Wikipedia.png',
		speedTip: 'Insert a link to a Wikipedia article',
		tagOpen: '[[wikipedia:',
		tagClose: ']]',
		sampleText: 'Wikipedia article name'
	},
	{
		imageId: 'button-insert-wplink',
		imageFile: '//upload.wikimedia.org/wikipedia/commons/0/0d/Button_wikification.png',
		speedTip: 'Insert a link to a Wiktionary word definition',
		tagOpen: '[[wikt:',
		tagClose: ']]',
		sampleText: 'Wiktionary definition'
	},
	{
		imageId: 'button-insert-poem',
		imageFile: '//upload.wikimedia.org/wikipedia/commons/d/d3/Button_definition_list.png',
		speedTip: 'Insert a poem',
		tagOpen: '<poem>',
		tagClose: '</poem>',
		sampleText: 'Text'
	},
	{
		imageId: 'button-insert-subpage',
		imageFile: '//upload.wikimedia.org/wikipedia/commons/0/0c/Button_Link_DifferentName.png',
		speedTip: 'Link to a subpage',
		tagOpen: '[[/',
		tagClose: ']]',
		sampleText: 'Subpage'
	},
	{
		imageId: 'button-insert-textcenter',
		imageFile: '//upload.wikimedia.org/wikipedia/commons/5/5f/Button_center.png',
		speedTip: 'Text centered',
		tagOpen: '<center>',
		tagClose: '</center>',
		sampleText: 'Centered text'
	},
	{
		imageId: 'button-insert-textcenter',
		imageFile: '//upload.wikimedia.org/wikipedia/commons/d/d5/Button_noinclude.png',
		speedTip: 'noinclude',
		tagOpen: '<noinclude>',
		tagClose: '</noinclude>',
		sampleText: 'noinclude text'
	},
	{
		imageId: 'button-insert-plainlink',
		imageFile: '//upload.wikimedia.org/wikipedia/commons/2/26/Button_plainlinks.png',
		speedTip: 'Insert a external link without the external link icon',
		tagOpen: '<span class="plainlinks">',
		tagClose: '</span>',
		sampleText: 'Enter URL here'
	}
	);
}

mw.loader.using( 'user.options', function () {
	// This can be the string "0" if the user disabled the preference ([[bugzilla:52542#c3]])
	if ( mw.user.options.get( 'usebetatoolbar' ) != 1 && mw.user.options.get( 'showtoolbar' ) == 1 ) {
		$.when(
			mw.loader.using( 'mediawiki.toolbar' ),
			$.ready
		).then( addExtraButtons );
	}
} );

/* Auto-refresh button on Special:RecentChanges */
function setCookie(c_name, value, expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}
function getCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}
var ajaxPages = new Array("Special:RecentChanges");
var ajaxRCOverride = false;
var rcRefresh = 30000;
function ajaxRC() {
	appTo = $(".firstHeading");
	appTo.append('&nbsp;<span style="position:absolute; right:75px;"><span style="position:relative; top:2px;"><span style="position:relative; top:-12px; right:-15px;" id="autoRefreshProgress"><img src="/images/loader.gif" border="0" alt="Refreshing..." /></span><span style="font-size: xx-small; cursor:help;" title="Automatically refresh the current page every ' + Math.floor(rcRefresh / 1000) + ' seconds">Auto refresh</span><input type="checkbox" id="autoRefreshToggle"></span></span>');
	$("#autoRefreshToggle").click(function () {
		setCookie("ajaxRC", $("#autoRefreshToggle").is(":checked") ? "on" : "off")
		loadRCData()
	});
	$("#autoRefreshProgress").hide();
	if (getCookie("ajaxRC") == "on" || ajaxRCOverride) {
		$("#autoRefreshToggle").attr("checked", "checked");
		setTimeout("loadRCData();", rcRefresh);
	}
}
function loadRCData() {
	if (!$("#autoRefreshToggle").is(":checked")) return;
	$('#autoRefreshProgress').show()
	$(article).load(location.href + " " + article + " > *", function (data) {
		$(article + " .mw-collapsible").makeCollapsible();
		$('#autoRefreshProgress').hide()
		if ($("#autoRefreshToggle").is(":checked")) setTimeout("loadRCData();", rcRefresh);
	});
}
$(function () {
	article = "#bodyContent";
	for (x in ajaxPages) {
		if (mw.config.get('wgPageName') == ajaxPages[x] && $("#autoRefreshToggle").length == 0) ajaxRC();
	}
});

function setUpSynchTable () {
  var tables = document.getElementsByClassName("awardsSynchronisedTable");
  for (var k = 0; k < tables.length; k++) {
    var rows = tables[k].rows;
    for (var i = 0; i < rows.length; i++) {
      var cells = rows[i].cells;
      for (var j = 0; j < cells.length; j++) {
        cells[j].style.verticalAlign = "top";
        var synchDiv = document.createElement("DIV");
        synchDiv.style.position = "relative";
        synchDiv.className = "synchDiv";
        var childs = cells[j].childNodes;
        while (childs.length > 0) {
          synchDiv.appendChild(childs[0]);
        }
        cells[j].appendChild(synchDiv);
      }
    }
  }
  if (tables.length > 0) {
    document.onscroll = synchTableOnScroll;
  }
}

function synchTableOnScroll() {
  
  var divs = document.getElementsByClassName("synchDiv");
  for (var i = 0; i < divs.length; i++) {
    var parent = divs[i].parentNode;
    var parentRect = parent.getBoundingClientRect();
    var offset;
    if (window.innerHeight > divs[i].offsetHeight) {
      offset = Math.min(Math.max(-1 * parentRect.top, 0), parent.clientHeight - divs[i].offsetHeight);
    } else {
      offset = Math.min(Math.max(-1 * parentRect.top / (parent.clientHeight - window.innerHeight) * (parent.clientHeight - divs[i].offsetHeight), 0), parent.clientHeight - divs[i].offsetHeight);
    }
    divs[i].style.top = offset + "px";
  }
}
importScriptURI('//en.wikipedia.org/w/index.php?title=User:MarkS/extraeditbuttons.js&action=raw&ctype=text/javascript');