User:Beeswaxcandle/common.js

/* ProofreadPage extension specific */ self.layout_overrides_have_precedence = true; //	self.proofreadpage_disable_ocr = true; Now handled by User pref gadget

/* CharInsert specific */ //	window.charinsertDontMove = true; //	window.charinsertMoveTop = true; window.editToolsRecall = true; window.charinsertCustom = { User: '— – … † æ Æ œ Œ £ § ♭ ♯ ♮ à á â ä ç è é ê ë Í î ï ñ ò ô ö ù û ü ⅛ ⅙ ⅕ ⅜ ⅝ ¼ ½ ¾ ⅓ ⅔ α β γ δ ° ′ ″ • ⋅ ℞ × ' }; //	if(window.updateEditTools) window.updateEditTools;

/* special formats for proofreading tools */ // var pageNumber = parseInt((mw.config.get('wgTitle').match(/\.djvu\/(\d+)$/) || {})[1], 10); var specialFormats = [ // add as many as you like... {		title: /History of England /, evenHeader: "" + (pageNumber - 20) + "", oddHeader: "1556.]", footer: "", footerWithReferences: "" },	{		title: /Outdoor Girls /, oddHeader: "Rh", evenHeader: "" + (pageNumber - 12) + "", footer: "", footerWithReferences: "" },       {		title: /Ante-Nicene Christian /, evenHeader: "" + (pageNumber - 6) + "", oddHeader: "Rh", footer: "", footerWithReferences: "" },	{		title: /Fairview Boys /, oddHeader: "Rh", evenHeader: "" + (pageNumber - 4) + "", footer: "", footerWithReferences: "" },	{		title: /Shakespeare /, evenHeader: "" + (pageNumber - 14) + "", oddHeader: "Rh", footer: "", footerWithReferences: "" },	{		title: /Adventures of Kimble /, evenHeader: "" + (pageNumber - 28) + "", oddHeader: "Rh", footer: "", footerWithReferences: "" },	{		title: /Tracts for /, evenHeader: "" + pageNumber + "", oddHeader: "Rh", footer: "", footerWithReferences: "" },	{		title: /Arrow of /, evenHeader: "Rh", oddHeader: "" + (pageNumber - 13) +"", footer: "", footerWithReferences: "" },	{		title: /Tom Swift /, evenHeader: "" + (pageNumber - 10) + "", oddHeader: "Rh", footer: "", footerWithReferences: "" },	{		title: /Ruth Fielding /, evenHeader: "" + (pageNumber - 10) + "", oddHeader: "Rh", footer: "", footerWithReferences: "" },	{		title: /Rover Boys /, evenHeader: "" + (pageNumber - 18) + "", oddHeader: "Rh", footer: "", footerWithReferences: "" },	{		title: /The vintage; a /, evenHeader: "", oddHeader: "", footer: "", footerWithReferences: "" },	{		title: /Bobbsey Twins /, evenHeader: "" + (pageNumber - 18) + "", oddHeader: "Rh", footer: "", footerWithReferences: "" },	{		title: /Dave Porter /, evenHeader: "" + (pageNumber - 18) + "", oddHeader: "Rh", footer: "", footerWithReferences: "" },	{		title: /First Footsteps /, evenHeader: "" + (pageNumber - 46) + "", oddHeader: "Rh", footer: "", footerWithReferences: "" },	{		title: /Moving Picture /, evenHeader: "" + (pageNumber - 10) + "", oddHeader: "Rh", footer: "", footerWithReferences: "" },	{		title: /At the Fall /, evenHeader: "" + (pageNumber - 18) + "", oddHeader: "Rh", footer: "", footerWithReferences: "" } ]; //

/** * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor. * @see https://meta.wikimedia.org/wiki/TemplateScript * @update-token */ $.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function {	// customise proofreading tools	pathoschild.TemplateScript.library.override('wikisource.proofreading', 'add-header', { accessKey: 'z' });	pathoschild.TemplateScript.library.override('wikisource.proofreading', 'add-footer', { accessKey: 'f' });	pathoschild.TemplateScript.library.override('wikisource.proofreading', 'cleanup-ocr', { accessKey: 'x' });	pathoschild.TemplateScript.library.override('wikisource.proofreading', 'smallcaps', { accessKey: 'c' });	pathoschild.TemplateScript.library.override('wikisource.proofreading', 'uppercase', { accessKey: 'u' }); });

/** * Add several tools useful when proofreading pages in the Page: namespace. * @see https://en.wikisource.org/wiki/Wikisource:TemplateScript */ mw.loader.load('//en.wikisource.org/w/index.php?title=MediaWiki:TemplateScript/proofreading.js&action=raw&ctype=text/javascript');

// == SIDEBAR TOOLS == /** * WikiEditor specific * * Custom buttons ONLY when Prefs set to - Enable enhanced editing toolbar - is selected, * Enable wizards for... - must not be selected. Show [old]edit toolbar - should be off. * based upon - https://github.com/he7d3r/mw-gadget-ExtraEditButtons */ // var customizeToolbar = function { $( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', { section: 'main', group: 'insert', tool: 'xlink' } ) .wikiEditor( 'removeFromToolbar', { section: 'main', group: 'insert', tool: 'ilink' } ) .wikiEditor( 'removeFromToolbar', { section: 'main', group: 'insert', tool: 'file' } ) .wikiEditor( 'removeFromToolbar', { section: 'main', group: 'insert', tool: 'reference' } ) .wikiEditor( 'removeFromToolbar', { section: 'main', group: 'insert', tool: 'signature' } ) .wikiEditor( 'removeFromToolbar', { section: 'characters' } ) .wikiEditor( 'removeFromToolbar', { section: 'advanced' } ) .wikiEditor( 'removeFromToolbar', { section: 'help' } ) .wikiEditor( 'addToToolbar', {		section: 'main',		group: 'format',		tools: {			underline: {				labelMsg: 'wikieditor-toolbar-tool-underline',				label: 'Underline',				id: 'underline',				filters: [ 'body:not(.ns-2, .ns-8, .ns-828)' ],				type: 'button',				icon: '//upload.wikimedia.org/wikipedia/commons/8/8b/Button_underline_he.png',				action: {					type: 'encapsulate',					options: {						pre: " ",						periMsg: 'wikieditor-toolbar-tool-underline-example',						post: " "					}				}			},			strikeout: {				labelMsg: 'wikieditor-toolbar-tool-strikeout',				label: 'Strike out',				id: 'strikeout',				filters: [ 'body:not(.ns-2, .ns-8, .ns-828)' ],				type: 'button',				icon: '//upload.wikimedia.org/wikipedia/commons/6/6d/Vector_strikeout.png',				action: {					type: 'encapsulate',					options: {						pre: " ",						periMsg: 'wikieditor-toolbar-tool-strikeout-example',						post: " "					} }			},			emdash: { labelMsg: 'wikieditor-toolbar-tool-emdash', label: 'em-dash', id: 'emdash', filters: [ 'body:not(.ns-2, .ns-8, .ns-828)' ], type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/8/8b/Button_m-dash.png', action: { type: 'replace', options: { 'peri': '\u2014', 'selectPeri': false }				}			},			endash: { labelMsg: 'wikieditor-toolbar-tool-endash', label: 'en-dash', id: 'endash', filters: [ 'body:not(.ns-2, .ns-8, .ns-828)' ], type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/8/8b/Button_n-dash.png', action: { type: 'replace', options: { 'peri': '\u2013', 'selectPeri': false }				}			},			bar2: { labelMsg: 'wikieditor-toolbar-tool-bar2', label: 'bar2', id: 'bar2', filters: [ 'body:not(.ns-2, .ns-8, .ns-828)' ], type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/b/bd/Button_number_2.png', action: { type: 'replace', options: { 'peri': '', 'selectPeri': false }				}			},			'break': { labelMsg: 'wikieditor-toolbar-tool-break', label: 'break', id: 'break', filters: [ 'body:not(.ns-2, .ns-8, .ns-828)' ], type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/f/f2/Button-br.png', action: { type: 'replace', options: { 'peri': ' ',						'selectPeri': false }				}			},			'zoom-in': { labelMsg: 'proofreadpage-button-zoom-in-label', label: 'Zoom in', id: 'zoom-in', filters: [ 'body.ns-104' ], type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/0/04/Button_zoom_in.png', action: { type: 'callback', execute: function { $zoomImage.prpZoom( 'zoomIn' ); }				}			},			'zoom-out': { labelMsg: 'proofreadpage-button-zoom-out-label', label: 'Zoom out', id: 'zoom-out', filters: [ 'body.ns-104' ], type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/0/03/Button_zoom_out.png', action: { type: 'callback', execute: function { $zoomImage.prpZoom( 'zoomOut' ); }				}			},			'reset-zoom': { labelMsg: 'proofreadpage-button-reset-zoom-label', label: 'Reset zoom', id: 'reset-zoom', filters: [ 'body.ns-104' ], type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/2/2a/Button_examine.png', action: { type: 'callback', 'execute': function { $zoomImage.prpZoom( 'reset' ); }				}			},			hyphword: { labelMsg: 'wikieditor-toolbar-tool-hyphword', label: 'hyphword', id: 'hyphword', filters: [ 'body.ns-104' ], type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/5/5a/Button_hyphenated_word.svg', action: { type: 'callback', execute: function(context) { hyphenated_word; }				}			},			'toggle-visibility': { labelMsg: 'proofreadpage-button-toggle-visibility-label', label: 'Toggle visible headers and footers', id: 'toggle-visibility', filters: [ 'body.ns-104' ], type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/2/2a/Button_category_plus.png', action: { type: 'callback', 'execute': function { toggleHeaders( 'fast' ); }				}			},			'toggle-layout': { labelMsg: 'proofreadpage-button-toggle-layout-label', label: 'Toggle layout', id: 'toggle-layout', filters: [ 'body.ns-104' ], type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/0/04/Button_multicol.png', action: { type: 'callback', execute: function { toogleLayout; }				}			}		}	} );	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', { section: 'main', group: 'insert', tools: { 'ilink': { labelMsg: 'wikieditor-toolbar-tool-ilink', label: 'Wiki link', id: 'ilink', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/4/48/Toolbar_Insert_link.png', offset: [2, -1582], action: { type: 'encapsulate', options: { pre: "",						periMsg: 'wikieditor-toolbar-tool-ilink-example',						post: "" }				}			},			'xlink': { labelMsg: 'wikieditor-toolbar-tool-xlink', label: 'URL link', id: 'xlink', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/5/55/Toolbar_insert_xlink.png', offset: [-70, 2], action: { type: 'encapsulate', options: { pre: "[", periMsg: 'wikieditor-toolbar-tool-xlink-example', post: "]" }				}			},			'nowiki': { labelMsg: 'wikieditor-toolbar-tool-nowiki', label: 'NoWiki', id: 'nowiki', type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/8/80/Toolbar_insert_nowiki.png', offset: [-70, -70], action: { type: 'encapsulate', options: { pre: '<' + 'nowiki>', periMsg: 'wikieditor-toolbar-tool-nowiki-example', post: '<' + '/nowiki>' }				}			},			redirect: { labelMsg: 'wikieditor-toolbar-tool-redirect', label: 'ReDirect', id: 'redirect', filters: [ 'body:not(.ns-828, .ns-829)' ], type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/7/76/Insert_redirect.png', offset: [-70, -142], action: { type: 'encapsulate', options: { pre: mw.config.get( 'wgWikiEditorMagicWords' ).redirect + ' ',						periMsg: 'wikieditor-toolbar-tool-redirect-example',						post: "", ownline: true }				}			},			signature: { labelMsg: 'wikieditor-toolbar-tool-signature', label: 'Your Signature', id: 'signature', filters: [ 'body.ns-talk, body.ns-4' ], type: 'button', icon: '//upload.wikimedia.org/wikipedia/commons/7/79/Insert-signature.png', offset: [2, -1872], action: { type: 'encapsulate', options: { pre: '— ~' }				}			}		}	} ); }; /* Check for edit mode and required modules are available. Then, customize */ if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {	mw.loader.using( 'user.options', function { if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) { $.when(				mw.loader.using( ['ext.wikiEditor'] ),				$.ready			).then( customizeToolbar ); }	} ); }

var addExtraButtons = function{ mw.toolbar.addButtons(		{			"imageFile": "//upload.wikimedia.org/wikipedia/commons/8/8b/Button_m-dash.png",			"speedTip": "M-dash",			"tagOpen": '—',			"tagClose": ,			"sampleText": ""		},		{			"imageFile": "//upload.wikimedia.org/wikipedia/commons/8/8b/Button_n-dash.png",			"speedTip": "N-dash",			"tagOpen": '–',			"tagClose": ,			"sampleText": ""		},		{			"imageFile": "//upload.wikimedia.org/wikipedia/commons/b/bd/Button_number_2.png",			"speedTip": "2em",			"tagOpen": ,			"tagClose": ,			"sampleText": ""		},		{			"imageFile": "//upload.wikimedia.org/wikipedia/commons/2/22/Button_ellipsis.png",			"speedTip": "Ellipsis",			"tagOpen": '…',			"tagClose": ,			"sampleText": ""		},		{			"imageFile": "//upload.wikimedia.org/wikipedia/commons/b/b1/Button_dagger.png",			"speedTip": "dagger",			"tagOpen": '†',			"tagClose": ,			"sampleText": ""		},		{			"imageFile": "//upload.wikimedia.org/wikipedia/commons/f/f2/Button-br.png", "speedTip": "Break", "tagOpen": ' ',			"tagClose": '', "sampleText": "" },		{			"imageFile": "//upload.wikimedia.org/wikipedia/commons/c/cd/Button_poem.png", "speedTip": "Break & gap", "tagOpen": ' \n', "tagClose": '', "sampleText": "" }	); }; //end of var addExtraButtons //

if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) { mw.loader.using( 'user.options', function {		if ( mw.user.options.get( 'showtoolbar' ) == 1 ) {			$.when( mw.loader.using( 'mediawiki.toolbar' ), $.ready ).then( addExtraButtons );		}	} ); }

// From Inductiveload page

/* * Does a lookup on the previous page to see if there is a hyphenated * word and tries to complete it * * To use this script, add the following to your .js: *    importScript('User:Inductiveload/Hyphenated word.js'); * */

function check_hws(data) { try { var editbox = document.getElementsByName('wpTextbox1')[0]; if (editbox && !data.query.pages["-1"]) { for (var ids in data.query.pages) { var content = data.query.pages[ids].revisions[0]['*']; var match = content.match( /{{ *([Hh]ws|[Hh]yphenated word start)\|([^\|}]*)\|?([^\|}]*)?}}/ ); if (match !== undefined && match.length > 3) { var hws = match[2]; var word = match[3]; var hwe = word.slice(hws.length); var hwestring = ' '; editbox.value = hwestring + editbox.value; }				break; }		}	}	catch (err) { } }

function hyphenated_word { var r = new RegExp("(\\d+)$"); var page = Number(r.exec(mw.config.get('wgPageName'))[1]) - 1; //previous page var pagename = mw.config.get('wgPageName').replace(/\d+$/g, page);

var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/api.php?action=query&prop=revisions&callback=check_hws&rvprop=content" + "&format=json&titles=" + encodeURIComponent(pagename);

$('body').append(''); }

$(function {	var tb = document.getElementById("toolbar");	if(tb) {		var image = document.createElement("img");		image.width = 23;		image.height = 23;		image.border = 0;		image.className = "mw-toolbar-editbutton";		image.style.cursor = "pointer";		image.alt = "Hyph. word";		image.title = "Add hyphenated word started on the previous page";		image.src = "//upload.wikimedia.org/wikipedia/commons/thumb/5/5a/Button_hyphenated_word.svg/23px-Button_hyphenated_word.svg.png";		image.onclick = hyphenated_word;		tb.appendChild(image);	} });